OpenBMB / MiniCPM

MiniCPM-2B: An end-side LLM outperforming Llama2-13B.
Apache License 2.0
4.67k stars 334 forks source link

The same output #56

Closed pribadihcr closed 6 months ago

pribadihcr commented 6 months ago

Hi, I tried to infer MiniCPM-V different images in loops. But got the same result.

images = ["a.jpg", "b.jpg", "c.jpg"]

for img in images:
     image = Image.open(image_path).convert('RGB')
     res, context, _ = model.chat(
            image=image,
            msgs=msgs,
            context=None,
            tokenizer=tokenizer,
            sampling=False,
            temperature=0.0
        )
     print(res)

the "res" has the same output.

THUCSTHanxu13 commented 6 months ago

please change "image = Image.open(image_path).convert('RGB')" to "image = Image.open(img).convert('RGB')"

THUCSTHanxu13 commented 6 months ago

everytime you open the file "image_path" rather than "img"

pribadihcr commented 6 months ago

@THUCSTHanxu13 ,

Sorry, the issue still exists.

images = ["a.jpg", "b.jpg", "c.jpg"]

for img in images:
     image = Image.open(img).convert('RGB')
     res, context, _ = model.chat(
            image=image,
            msgs=msgs,
            context=None,
            tokenizer=tokenizer,
            sampling=False,
            temperature=0.0
        )
     print(res)
ShengdingHu commented 6 months ago

Do you still have questions? @pribadihcr

pribadihcr commented 6 months ago
model = AutoModel.from_pretrained('openbmb/MiniCPM-V', trust_remote_code=True, cache_dir="./cache")
tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V', trust_remote_code=True, cache_dir="./cache")

prompt = 'What is this photo about? Please answer with details.'
msgs = [{'role': 'user', 'content': prompt}]

images = ["a.jpg", "b.jpg", "c.jpg"]

for img in images:
    image = Image.open(img).convert('RGB')
    res, context, _ = model.chat(
        image=image,
        msgs=msgs,
        context=None,
        tokenizer=tokenizer,
        sampling=False,
        temperature=0.0
    )
    print(res)

@ShengdingHu, with the script above give the same output. Please double check with reproduce it. Thank you.

YuzaChongyi commented 6 months ago

@pribadihcr You should put msgs inside the for loop,because msgs are updated when called model.chat