1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Ollama multimodal - Gemma not seeing image

Discussão em 'Python' iniciado por Stack, Setembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    This sample multimodal/main.py appears to show Ollama

    I am trying to do the same with an image loaded from my machine. I am using the gemma2:27b model. The model is working with chat so that is not the issue.

    my Code


    import os.path
    import PIL.Image
    from dotenv import load_dotenv
    from ollama import generate

    load_dotenv()
    CHAT_MODEL_NAME = os.getenv("MODEL_NAME_LATEST")

    image_path = os.path.join("data", "image_one.jpg")
    test_image = PIL.Image.open(image_path)

    # test 1:

    for response in generate(CHAT_MODEL_NAME, 'What do you see', images=[test_image], stream=True):
    print(response['response'], end='', flush=True)

    # response: ollama._types.RequestError: image must be bytes, path-like object, or file-like object

    # test 2: bytes

    for response in generate(CHAT_MODEL_NAME, 'What do you see', images=[test_image.tobytes()], stream=True):
    print(response['response'], end='', flush=True)

    # response: Please provide me with the image!

    # test 3: Path
    for response in generate(CHAT_MODEL_NAME, 'What do you see', images=[image_path], stream=True):
    print(response['response'], end='', flush=True)

    # response: Please provide me with the image!


    How do i properly load an image to Gemma

    Cross posted on issue forum 289

    Continue reading...

Compartilhe esta Página