Skip to content

ビジョンモデルはテキストに加えて画像を受け付けるため、モデルは画像の内容を説明、分類、質問に回答することができます。

クイックスタート

shell
ollama run gemma4 ./image.png whats in this image?

OllamaのAPIを使用する

images配列を指定してください。SDKはファイルパス、URL、または生のバイト列を受け付けますが、REST APIはbase64でエンコードされた画像データを期待します。

cURL

```shell
# 1. サンプル画像をダウンロード
curl -L -o test.jpg "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg"

# 2. 画像をエンコード
IMG=$(base64 < test.jpg | tr -d '\n')

# 3. 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

```python
from ollama import chat
# from pathlib import Path

# 画像のパスを渡す
path = input('Please enter the path to the image: ')

# base64でエンコードした画像データを渡すこともできます
# img = base64.b64encode(Path(path).read_bytes()).decode()
# または生のバイト列
# 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

```javascript
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)
```