Skip to content
HUIAHUB

TutorialImage & video

Run vision language model locally: Ollama and llama.cpp guide

Run vision language model locally with Ollama or llama.cpp, send screenshots through local APIs, and check image answers before using them.

Edited by Published 11 min read18 sources
An image flows through two local processing paths with a server and chip, then reaches a magnifying glass and verification checkmark.

Illustration generated with ChatGPT

Run vision language model locally using Ollama for a quick start or llama.cpp for direct control over model files and inference. Both can accept an image with a text question and generate an answer on your computer. Transformers provides a third route when image analysis belongs inside a Python application.

A vision language model (VLM) accepts images and text together. You can ask it to explain a screenshot, identify parts of a diagram, describe a photograph or read text from a scanned page.

The model must support image input, and your local runner must support that model's vision components. A text-only LLM cannot read an image merely because its chat interface has an attachment button.

If you already use Ollama for text models, HuiaHub's local LLM setup guide covers the underlying installation and API workflow.

What can a local vision language model read?

A VLM can answer questions about visible content rather than receiving only text extracted from an image.

For example, you can give it a screenshot and ask which warning appears above a disabled button. You can provide a circuit diagram and ask how its labeled components connect.

Other tasks include:

  • Describing objects and their positions in photographs.
  • Reading labels, messages and table headings from screenshots.
  • Extracting information from receipts and scanned pages.
  • Explaining the visible structure of diagrams.
  • Answering questions about charts and plotted relationships.

The output is generated text. It should not be treated as an exact transcription or a verified measurement.

Where vision models struggle

Small text is a concern, particularly when screenshots contain dense tables or several lines of tiny labels. A plausible transcription can contain incorrect characters, missing values or invented text.

Counting objects and comparing visual quantities also present difficulties. Research on visual arithmetic has identified errors in counting, length comparisons and related tasks.

Charts add another problem. Reading an axis label is different from correctly interpreting a plotted relationship.

The ChartMuseum research paper (opens in a new tab) examined vision language models on questions requiring chart interpretation. Its findings show that successful text reasoning does not guarantee accurate visual reasoning.

These limitations matter when using local models for invoices, monitoring dashboards or technical drawings. Check extracted numbers and spatial relationships against the source image.

How should you choose a vision model?

Start with three checks: model size, license and runtime support.

A model repository may provide several weight formats or quantized variants. The download size tells you how much storage the file needs, but it does not establish the complete runtime memory requirement.

Model or familyDocumented optionWhat to check
Gemma 4Used in Ollama's vision examplesAvailable variant, memory needs and applicable license
Gemma 3 4BGGUF available for llama.cppMatching multimodal projector and Gemma license
Qwen3-VL 4B InstructTransformers image-text-to-text modelApache 2.0 license and image processing settings
SmolVLM2GGUF options listed by llama.cppSelected model size and supported input types

These are documented examples, not a quality ranking.

The Qwen3-VL-4B-Instruct model card (opens in a new tab) identifies its Apache 2.0 license and provides Transformers usage examples. Gemma models use Google's Gemma license, which has different terms.

Review the license of the exact model you download. A model's availability for local inference does not establish unrestricted commercial permission.

For runner selection, Ollama manages model downloads and exposes its own local API. llama.cpp supports GGUF files, a multimodal command-line tool and an OpenAI-compatible server. Transformers offers direct model loading and image processing in Python.

HuiaHub also has a comparison of llama.cpp, Ollama and LM Studio for the broader runner differences.

Run vision language model locally with Ollama

Ollama is the shorter path when you want to ask questions about an image without managing separate projector files.

Its official vision documentation (opens in a new tab) uses Gemma 4 and supports image input through the command line and API.

The following commands assume Ollama is installed and running.

Step 1: Pull a vision-capable model

Open a terminal and download the model:

ollama pull gemma4

Ollama's current CLI reference documents this command.

The unqualified model name selects the model's default tag. Check the actual model variant and hardware requirements before downloading it.

Step 2: Ask about a local image

Place a file named screenshot.png in your working directory.

Run:

ollama run gemma4 ./screenshot.png "Describe the visible error message."

Ollama's vision command accepts an image path alongside the question.

You can change the question without changing the image:

ollama run gemma4 ./screenshot.png "List the labels visible in the navigation menu."

The model generates an answer using the image and your prompt. The returned text still needs checking when exact wording matters.

For an initial test, use a screenshot with a clearly readable message. Compare the answer with the original before moving to documents containing smaller text.

Step 3: Send an image through Ollama's REST API

Ollama documents image input through POST /api/chat.

The native REST API expects base64-encoded image data in an images array. The Ollama SDKs also accept image paths, URLs or raw bytes.

The following example uses Bash on macOS or Linux. It reads screenshot.png from the current directory.

IMG=$(base64 < screenshot.png | tr -d '\n')

curl http://localhost:11434/api/chat \
-H "Content-Type: application/json" \
-d '{
"model": "gemma4",
"messages": [{
"role": "user",
"content": "Read the visible error message.",
"images": ["'"$IMG"'"]
}],
"stream": false
}'

The response contains the generated message under message.content.

Setting stream to false requests a complete response rather than streamed response chunks.

The images value contains base64 data, not a local filename. This distinction matters when moving from Ollama's CLI to a program that calls the REST endpoint.

The example contacts a locally running Ollama service. It does not require sending the image to a hosted inference API.

A local deployment still needs ordinary network precautions. Keep the inference endpoint restricted to clients that should have access to it.

How does llama.cpp handle image input?

llama.cpp provides more direct control over model loading and multimodal processing.

Its current multimodal documentation (opens in a new tab) describes support through libmtmd.

A typical multimodal GGUF setup has two files:

  • A language model GGUF containing the model weights.
  • A corresponding multimodal projector, commonly called mmproj, which handles image encoding and projection.

The projector must match the model architecture. Downloading a language model file alone may leave you with text inference but no working image input.

The libmtmd project handles the multimodal processing. Its developers describe this part of llama.cpp as under active development, with breaking changes possible.

Step 1: Build the multimodal tools

For a source build using CMake on macOS or Linux:

git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp

cmake -B build
cmake --build build --config Release

The build produces the command-line and server tools when the relevant build options are enabled.

The examples below use binaries under ./build/bin/. Other installations may place executables elsewhere.

Step 2: Send an image with llama-mtmd-cli

For a supported Hugging Face GGUF repository, llama.cpp provides the -hf option.

This avoids manually supplying the separate model and projector paths.

./build/bin/llama-mtmd-cli \
-hf ggml-org/gemma-3-4b-it-GGUF \
--image ./diagram.png \
-p "Describe how the components in this diagram connect."

The repository identifier is listed in llama.cpp's official multimodal examples.

The --image argument supplies the image, while -p supplies the prompt.

llama-mtmd-cli is an experimental tool intended for multimodal testing and development. Its source code explicitly identifies it as unsuitable for production use.

For a longer-lived application, consider the server interface instead.

Step 3: Load the GGUF and projector files directly

The Gemma 3 4B GGUF repository (opens in a new tab) lists these files:

  • gemma-3-4b-it-Q4_K_M.gguf, approximately 2.49 GB.
  • mmproj-model-f16.gguf, approximately 851 MB.

Download both from that repository.

If you save them in a local directory named models, you can start the server with explicit paths:

./build/bin/llama-server \
-m ./models/gemma-3-4b-it-Q4_K_M.gguf \
--mmproj ./models/mmproj-model-f16.gguf

The filenames above come from the repository. The models directory is an illustrative local location.

llama.cpp uses -m for the language model and --mmproj for the multimodal projector.

By default, llama.cpp attempts to offload the multimodal projector to the GPU. Its documented --no-mmproj-offload option disables that behavior.

Step 4: Use llama-server for an application

llama-server exposes an OpenAI-compatible /v1/chat/completions endpoint.

Its multimodal request format accepts typed message content, including image_url objects. The server documentation supports base64 image data and data URLs.

An application can send text and an image within the same user message.

This is useful when your existing code already sends chat completion requests. You can adapt the image-bearing message format while directing the client to your local server.

The server also supports loading compatible models by Hugging Face repository identifier:

./build/bin/llama-server \
-hf ggml-org/gemma-3-4b-it-GGUF

This gives llama.cpp a way to obtain supported model files without manually selecting each local path.

For applications that already depend on an OpenAI-style interface, the server avoids adding the experimental llama-mtmd-cli binary to the application workflow.

Use Transformers for a Python vision pipeline

Hugging Face Transformers provides an image-text-to-text task for working with image-and-text models in Python.

Its image-text-to-text guide (opens in a new tab) documents both the higher-level pipeline and direct model loading.

The pipeline is useful for a Python program that needs to process local screenshots, extract answers and pass results to other code.

Step 1: Install the Python dependencies

Use a Python environment with a compatible PyTorch installation.

The current Transformers installation documentation supports installing the PyTorch dependencies through its torch extra.

For a pip-based environment:

pip install "transformers[torch]" accelerate pillow

GPU support depends on the installed PyTorch build and the available hardware.

Step 2: Run image-text-to-text inference

The following Python example uses Qwen3-VL-4B-Instruct and a local image.

from PIL import Image
from transformers import pipeline

pipe = pipeline(
"image-text-to-text",
model="Qwen/Qwen3-VL-4B-Instruct",
device_map="auto",
dtype="auto",
)

image = Image.open("screenshot.png").convert("RGB")

messages = [
{
"role": "user",
"content": [
{"type": "image"},
{
"type": "text",
"text": "Read the visible warning message."
},
],
}
]

result = pipe(
text=messages,
images=[image],
max_new_tokens=128,
return_full_text=False,
)

print(result[0]["generated_text"])

The model and processor are loaded locally through Transformers. The first model load downloads the required files unless they are already cached.

return_full_text=False excludes the input conversation from the generated result.

A pipeline also lets your Python program control which files it reads and how it handles generated text.

For stricter offline operation, Transformers documents HF_HUB_OFFLINE=1 and local model directories. The required model files must already be available.

Step 3: Control image resolution when memory is limited

Transformers warns that dynamic-resolution models such as Qwen3-VL may process very large images into many visual tokens.

Its documentation identifies a default longest-edge limit around 16 megapixels for the supported dynamic-resolution models. Such inputs can create more than 10,000 visual tokens.

This can cause slow inference or out-of-memory errors on consumer GPUs.

When using the lower-level processor API, Transformers documents controlling the image pixel budget:

from transformers import AutoProcessor

processor = AutoProcessor.from_pretrained(
"Qwen/Qwen3-VL-4B-Instruct",
min_pixels=224 * 224,
max_pixels=1024 * 1024,
)

This processor configuration is for a lower-level inference path. It does not modify the pipeline created in the previous example.

Reducing the image pixel budget can reduce processing costs. It also risks losing fine detail, especially small text.

Test the same image at different processing resolutions before selecting a setting for a document-reading application.

How do memory, resolution and speed affect local vision?

Vision inference needs memory for more than the language model weights.

The selected architecture and runtime determine how images are processed, how much memory their visual representations need and where processing happens.

Several factors matter:

Model weights and quantization. A smaller quantized GGUF generally uses less storage than a higher-precision version of the same weights. Runtime memory also includes other allocations.

Multimodal projector. llama.cpp's projector is a separate component. It adds its own storage and runtime requirements.

Image resolution. Larger images can produce more visual tokens or image patches. This increases processing work for supported architectures.

Context and output length. Image input and conversation history consume context capacity. Generated output also takes processing time.

CPU and GPU placement. Processing on the CPU rather than a supported GPU can change latency. The result depends on the model, hardware and runtime configuration.

There is no single trustworthy memory or speed figure for all three routes.

The Gemma 3 GGUF files above provide a concrete storage example, but their combined download size does not equal required VRAM.

For troubleshooting, record the exact model identifier, quantization, image dimensions, prompt and runtime settings. Compare latency and memory usage using the same image when changing one setting.

How should you check answers against your own images?

A successful response proves that the model accepted the request and generated text. It does not establish that every detail is correct.

Use a small collection of images whose answers you can verify manually.

Include the kinds of files your application will actually receive. Screenshots, receipts and diagrams expose different errors.

Copyable local vision evaluation checklist

The following table is an illustrative test plan. It contains suggested questions and acceptance checks, not measured model results.

Test imageQuestion to askWhat to verify
Application screenshotWhat warning is displayed?Exact wording, punctuation and visible status
Screenshot with small labelsList the visible menu items.Missing, altered or invented labels
ReceiptList the purchased items and amounts.Every amount against the original receipt
Technical diagramWhich components connect to the output?Connections and arrow directions
ChartWhich series has the highest final value?Legend, axis and final plotted values
Repeated objectsHow many marked objects are visible?Count against manual inspection

Run the same questions after changing models or image processing settings.

Record the response beside the correct answer. Mark each incorrect value rather than relying on whether the explanation sounds reasonable.

Check screenshots

Start with a screenshot containing a known error message.

Ask the model to transcribe the visible message before asking it to explain the error. This separates text recognition from interpretation.

If the transcription is wrong, the explanation may be based on incorrect input.

For dense interfaces, crop the relevant area and run the question again. Keep the original screenshot for comparison.

Check receipts and scanned pages

Use a receipt whose item descriptions, quantities and amounts you can read independently.

Ask for transcription first. Compare each value with the source.

For totals, use ordinary arithmetic or programmatic validation against verified values. Do not accept a generated total solely because the model provides a plausible calculation.

Scanned pages with small print or poor contrast need particular attention. If the source text is unreadable, label that field as unverified rather than filling it from the model's guess.

Check diagrams and charts

For diagrams, verify arrow directions, component labels and connections.

Ask for a description of what is visibly connected before requesting an explanation of how the system works.

For charts, compare cited values with the actual axes and legend. Check whether the model confuses plotted lines or incorrectly interprets scale.

The same checks can become a repeatable prompt evaluation set. HuiaHub's guide to testing LLM outputs with promptfoo covers how to structure prompt tests and run them in CI.

Frequently asked questions

Can a local vision language model read a PDF directly?

The image workflows documented here accept image inputs. For a scanned PDF, render the relevant pages as images before using these examples. A direct PDF-reading workflow requires separate support from the chosen runner or application.

Does running a vision model locally guarantee image privacy?

Local inference avoids sending an image to a hosted model API when the application uses only the local runtime. Model downloads may still require network access, and other application components can make external requests. Review the complete processing path before handling sensitive files.

Can the same vision model work in Ollama and llama.cpp?

Only when compatible model formats and multimodal support are available for both runners. llama.cpp commonly uses a GGUF language model with a corresponding projector, while Ollama manages supported model packages. Check the exact model and runner documentation rather than assuming compatibility from the model family name.

Can a vision model replace OCR for receipts and scanned documents?

A vision model can generate text from document images, but fluent output does not guarantee faithful transcription. Check amounts, identifiers and other important fields against the source. Dedicated OCR tools may be another option when exact text extraction is the primary task.

Will a larger image always improve the answer?

No. Higher resolution can preserve small details, but it may increase visual token counts, memory requirements and processing time. Some processing pipelines also resize or divide images internally, so the useful resolution depends on the model and task.

Sources

  1. 1.Vision - OllamaOfficial docsPrimarydocs.ollama.com
  2. 2.llama.cpp/docs/multimodal.md at master · ggml-org/llama.cpp · GitHubRepositoryPrimarygithub.com
  3. 3.llama.cpp/tools/mtmd at master · ggml-org/llama.cpp · GitHubRepositoryPrimarygithub.com
  4. 4.Image-text-to-text · Hugging FaceOfficial docsPrimaryhuggingface.co
  5. 5.docs.ollama.com/cliOfficial docsPrimary
  6. 6.docs.ollama.com/api/chatOfficial docsPrimary
  7. 7.github.com/ggml-org/llama.cpp/blob/master/tools/mtmd/README.mdRepositoryPrimary
  8. 8.github.com/ggml-org/llama.cpp/blob/master/tools/mtmd/mtmd-cli.cppRepositoryPrimary
  9. 9.github.com/ggml-org/llama.cpp/blob/master/docs/build.mdRepositoryPrimary
  10. 10.huggingface.co/ggml-org/gemma-3-4b-it-GGUF/tree/mainRepositoryPrimary
  11. 11.huggingface.co/ggml-org/gemma-3-4b-it-GGUFRepositoryPrimary
  12. 12.llama.cpp/tools/server/README.md at master · ggml-org/llama.cpp · GitHubRepositoryPrimarygithub.com
  13. 13.huggingface.co/Qwen/Qwen3-VL-4B-InstructRepositoryPrimary
  14. 14.huggingface.co/docs/transformers/installationRepositoryPrimary
  15. 15.huggingface.co/docs/transformers/chat_templating_multimodalRepositoryPrimary
  16. 16.arxiv.org/abs/2502.11492PaperPrimary
  17. 17.arxiv.org/abs/2505.13444PaperPrimary
  18. 18.arxiv.org/abs/2605.27750PaperPrimary

Spotted an error? See our corrections policy.

Enjoyed this? Get the weekly brief.

New guides, Project & Tool of the Week and the AI developments that matter. One email, no spam.

Read next

More on these topics