비전(Vision)
비전(Vision)
비전 모델은 텍스트와 함께 이미지를 입력으로 받아서, 이미지에 담긴 내용을 설명·분류하고 그와 관련된 질문에 답할 수 있어요. 사진 속에 뭐가 있는지 궁금한 상황이 바로 이 기능이 필요한 순간이에요.
출처: 공식문서
빠른 시작
명령줄에서 이미지 경로와 질문을 함께 넘기면 됩니다.
ollama run gemma4 ./image.png what is in this image?
Ollama API로 사용하기
API를 쓸 때는 images 배열을 넘겨요. SDK는 파일 경로·URL·raw 바이트를 그대로 받아들이지만, REST API는 base64로 인코딩된 이미지 데이터를 기대합니다.
cURL 예시는 이미지 다운로드 → base64 인코딩 → 전송 순서로 진행됩니다.
# 1. Download a sample image
curl -L -o test.jpg "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg"
# 2. Encode the image
IMG=$(base64 < test.jpg | tr -d '\n')
# 3. Send it to Ollama
curl -X POST http://localhost:11434/api/chat \
-H "Content-Type: application/json" \
-d '{
"model": "gemma4",
"messages": [{
"role": "user",
"content": "What is in this image?",
"images": ["'"$IMG"'"]
}],
"stream": false
}'
Python에서는 images에 이미지의 경로를 넘기면 됩니다. base64 인코딩 데이터나 raw 바이트를 넘길 수도 있어요.
from ollama import chat
# from pathlib import Path
# Pass in the path to the image
path = input('Please enter the path to the image: ')
# You can also pass in base64 encoded image data
# img = base64.b64encode(Path(path).read_bytes()).decode()
# or the raw bytes
# img = Path(path).read_bytes()
response = chat(
model='gemma4',
messages=[
{
'role': 'user',
'content': 'What is in this image? Be concise.',
'images': [path],
}
],
)
print(response.message.content)
JavaScript도 비슷하게 images 배열에 이미지 경로를 넣어 호출합니다.
import ollama from 'ollama'
const imagePath = '/absolute/path/to/image.jpg'
const response = await ollama.chat({
model: 'gemma4',
messages: [
{ role: 'user', content: 'What is in this image?', images: [imagePath] }
],
stream: false,
})
console.log(response.message.content)
더 알아보기 (Learn more)
- Structured outputs와 함께 쓰는 비전 — 이미지 설명을 고정된 JSON 스키마로 받기