Ollama multimodal - Gemma not seeing image #145

Closed
opened 2026-02-15 16:28:18 -05:00 by yindo · 1 comment
Owner

Originally created by @LindaLawton on GitHub (Sep 23, 2024).

I'm trying to get gemma to identify images. I have tried serval ways to load in the image and its not seeing it.

Model is: gemma2:27b

I have also tried with jyan1/paligemma-mix-224


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!


Cross posted on SO

Originally created by @LindaLawton on GitHub (Sep 23, 2024). I'm trying to get gemma to identify images. I have tried serval ways to load in the image and its not seeing it. Model is: gemma2:27b I have also tried with jyan1/paligemma-mix-224 ``` 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! ``` Cross posted on [SO](https://stackoverflow.com/q/79015047/1841839)
yindo closed this issue 2026-02-15 16:28:18 -05:00
Author
Owner

@ParthSareen commented on GitHub (Nov 21, 2024):

Hey @LindaLawton - couple things:

  1. Gemma2 is not multimodal - maybe give llama3.2-vision a shot?
  2. IIRC we currently don't accept PIL files - passing in a path works!
@ParthSareen commented on GitHub (Nov 21, 2024): Hey @LindaLawton - couple things: 1. Gemma2 is not multimodal - maybe give llama3.2-vision a shot? 2. IIRC we currently don't accept PIL files - passing in a path works!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#145