Image-Text-to-Image
Transformers
PEFT
English
knowledge-graph
information-extraction
scene-graph
image-to-graph
structured-extraction
opengraph
gemma4
lora
mcp
Instructions to use OpenGraph-AI/opengraph-image-gemma4-e4b-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGraph-AI/opengraph-image-gemma4-e4b-v1 with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("OpenGraph-AI/opengraph-image-gemma4-e4b-v1", device_map="auto") - PEFT
How to use OpenGraph-AI/opengraph-image-gemma4-e4b-v1 with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,253 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ags:
|
| 9 |
+
- knowledge-graph
|
| 10 |
+
- information-extraction
|
| 11 |
+
- scene-graph
|
| 12 |
+
- image-to-graph
|
| 13 |
+
- structured-extraction
|
| 14 |
+
- opengraph
|
| 15 |
+
- gemma4
|
| 16 |
+
- lora
|
| 17 |
+
- peft
|
| 18 |
+
- mcp
|
| 19 |
+
datasets:
|
| 20 |
+
- OpenGraphAI/opengraph-image-gold-v1
|
| 21 |
+
metrics:
|
| 22 |
+
- accuracy
|
| 23 |
+
- f1
|
| 24 |
+
# new_version: # leave unset β only used later to point to a v2 successor
|
| 25 |
+
# --- Eval Results (uncomment and fill once the eval harness produces numbers) ---
|
| 26 |
+
# model-index:
|
| 27 |
+
# - name: opengraph-image-gemma4-e4b-v1
|
| 28 |
+
# results:
|
| 29 |
+
# - task:
|
| 30 |
+
# type: image-text-to-text
|
| 31 |
+
# name: Image-to-Knowledge-Graph Extraction
|
| 32 |
+
# dataset:
|
| 33 |
+
# name: OpenGraph Image Gold v1 (test split)
|
| 34 |
+
# type: OpenGraphAI/opengraph-image-gold-v1
|
| 35 |
+
# split: test
|
| 36 |
+
# metrics:
|
| 37 |
+
# - type: accuracy
|
| 38 |
+
# name: Schema-valid extraction rate
|
| 39 |
+
# value: [XX.X]
|
| 40 |
+
# - type: f1
|
| 41 |
+
# name: Node/Edge F1
|
| 42 |
+
# value: [XX.X]
|
| 43 |
---
|
| 44 |
+
|
| 45 |
+
# Model Card for opengraph-image-gemma4-e4b-v1
|
| 46 |
+
|
| 47 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
| 48 |
+
|
| 49 |
+
A fine-tuned **Gemma 4 E4B** that turns a single image into a valid, schema-faithful **knowledge graph** (`graph.json`) β objects, attributes, scene context, text spans, and the relationships between them β ready for AI agents to query and reason over. Built by [OpenGraph AI](https://github.com/OpenGraphAI/opengraph-ai) as the small, cheap, on-device alternative to calling a frontier vision API for every extraction.
|
| 50 |
+
|
| 51 |
+
## Model Details
|
| 52 |
+
|
| 53 |
+
### Model Description
|
| 54 |
+
|
| 55 |
+
The model does one thing extremely well: **image β knowledge graph, on-schema, every time.** It was trained on verified imageβgraph gold pairs so that its output always conforms to OpenGraph's `graph.json` contract β stable snake_case node IDs with type prefixes (`entity_`, `concept_`, `event_`, `attr_`), typed edges, and cross-image-mergeable entities. Compared to prompting a general frontier model, it is dramatically cheaper per extraction, runs on a single consumer GPU (or laptop, quantized), and produces structurally consistent output that downstream graph tooling can rely on.
|
| 56 |
+
|
| 57 |
+
- **Developed by:** OpenGraph AI
|
| 58 |
+
- **Model type:** Multimodal (image-text-to-text), decoder-only transformer; QLoRA fine-tune of Gemma 4 E4B
|
| 59 |
+
- **Language(s):** English
|
| 60 |
+
- **License:** Apache 2.0 (inherited from Gemma 4; use is additionally subject to Google's [Gemma terms of use](https://ai.google.dev/gemma/terms))
|
| 61 |
+
- **Finetuned from model:** [`google/gemma-4-E4B`](https://huggingface.co/google/gemma-4-E4B)
|
| 62 |
+
|
| 63 |
+
### Model Sources
|
| 64 |
+
|
| 65 |
+
- **Repository:** https://github.com/OpenGraphAI/opengraph-ai
|
| 66 |
+
- **Demo:** [More Information Needed] <!-- link the graph.html shareable demo when live -->
|
| 67 |
+
|
| 68 |
+
## Uses
|
| 69 |
+
|
| 70 |
+
### Direct Use
|
| 71 |
+
|
| 72 |
+
Feed the model one image plus the OpenGraph extraction system prompt; it returns a complete `graph.json` β nodes for detected objects (fine-grained labels, normalized bounding boxes), one scene node, attribute nodes, transcribed text spans, and the edges wiring them together. Useful anywhere images need to become structured, queryable knowledge: visual search indexes, dataset annotation, scene understanding, and document/diagram parsing.
|
| 73 |
+
|
| 74 |
+
### Downstream Use
|
| 75 |
+
|
| 76 |
+
The model's intended home is inside the **[opengraph-image MCP server](https://github.com/OpenGraphAI/opengraph-ai)**: register it with Claude Desktop, Cursor, or any MCP-compatible agent, and the agent gains persistent, queryable visual memory β including multi-hop questions across many images ("which components appear in both photos, and what changed between them?"). It also serves as a local extraction backend for robotics scene memory, where per-frame frontier API calls are too slow and expensive.
|
| 77 |
+
|
| 78 |
+
### Out-of-Scope Use
|
| 79 |
+
|
| 80 |
+
- **Safety-critical decisions without human review** (e.g., equipment maintenance, medical, or navigation decisions made solely from the extracted graph).
|
| 81 |
+
- **General chat, reasoning, or text generation** β the fine-tune specializes the model for extraction; general capabilities may be degraded relative to the base model.
|
| 82 |
+
- **Images far outside the training distribution** (see Limitations).
|
| 83 |
+
- Any use prohibited by Google's [Gemma prohibited use policy](https://ai.google.dev/gemma/prohibited_use_policy).
|
| 84 |
+
|
| 85 |
+
## Bias, Risks, and Limitations
|
| 86 |
+
|
| 87 |
+
- **Extraction errors are silent.** The model can hallucinate objects, miss objects, or assign wrong relationships while still producing perfectly *valid* JSON β structural validity is not factual accuracy.
|
| 88 |
+
- **Distribution sensitivity.** Accuracy degrades on image types unlike the training data (domains, camera angles, lighting, languages in text spans). [More Information Needed β characterize after evaluation]
|
| 89 |
+
- **Inherited bias.** The model inherits biases from Gemma 4's pretraining data, from the public image datasets used for fine-tuning, and from the frontier models used to generate a portion of the training labels.
|
| 90 |
+
- **Schema lock-in.** Output follows OpenGraph's `graph.json` schema; it is not a general-purpose captioner and will not follow arbitrary output formats reliably.
|
| 91 |
+
|
| 92 |
+
### Recommendations
|
| 93 |
+
|
| 94 |
+
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. Validate every output with the schema validators shipped in the [OpenGraph repo](https://github.com/OpenGraphAI/opengraph-ai), keep a human in the loop for consequential decisions, and spot-check extractions when applying the model to a new image domain.
|
| 95 |
+
|
| 96 |
+
## How to Get Started with the Model
|
| 97 |
+
|
| 98 |
+
Use the code below to get started with the model.
|
| 99 |
+
|
| 100 |
+
```python
|
| 101 |
+
# pip install -U "transformers>=5.10.1" torch torchvision accelerate
|
| 102 |
+
|
| 103 |
+
from transformers import AutoProcessor, AutoModelForImageTextToText
|
| 104 |
+
from PIL import Image
|
| 105 |
+
|
| 106 |
+
MODEL_ID = "OpenGraphAI/opengraph-image-gemma4-e4b-v1"
|
| 107 |
+
|
| 108 |
+
processor = AutoProcessor.from_pretrained(MODEL_ID)
|
| 109 |
+
model = AutoModelForImageTextToText.from_pretrained(
|
| 110 |
+
MODEL_ID, dtype="auto", device_map="auto"
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
SYSTEM_PROMPT = """[More Information Needed β paste the OpenGraph extraction system prompt]"""
|
| 114 |
+
|
| 115 |
+
image = Image.open("your_image.jpg").convert("RGB")
|
| 116 |
+
messages = [
|
| 117 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 118 |
+
{"role": "user", "content": [
|
| 119 |
+
{"type": "image", "image": image},
|
| 120 |
+
{"type": "text", "text": "Extract the knowledge graph from this image."},
|
| 121 |
+
]},
|
| 122 |
+
]
|
| 123 |
+
|
| 124 |
+
inputs = processor.apply_chat_template(
|
| 125 |
+
messages, add_generation_prompt=True, tokenize=True,
|
| 126 |
+
return_dict=True, return_tensors="pt",
|
| 127 |
+
).to(model.device)
|
| 128 |
+
|
| 129 |
+
outputs = model.generate(**inputs, max_new_tokens=2048)
|
| 130 |
+
graph_json = processor.decode(
|
| 131 |
+
outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True
|
| 132 |
+
)
|
| 133 |
+
print(graph_json) # -> valid graph.json
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
Or skip the code entirely and use it through the MCP server:
|
| 137 |
+
|
| 138 |
+
```bash
|
| 139 |
+
[More Information Needed β one-line MCP install command]
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
## Training Details
|
| 143 |
+
|
| 144 |
+
### Training Data
|
| 145 |
+
|
| 146 |
+
Trained on **[More Information Needed β N] verified imageβ`graph.json` gold pairs** ([`OpenGraphAI/opengraph-image-gold-v1`](https://huggingface.co/datasets/OpenGraphAI/opengraph-image-gold-v1)), assembled from two sources: (1) public scene-graph datasets (e.g., Visual Genome) converted programmatically into the `graph.json` schema, and (2) unannotated images labeled by two independent frontier vision models, auto-accepted where both models agreed and human-reviewed otherwise. Every pair passed the OpenGraph Pydantic schema validators before inclusion.
|
| 147 |
+
|
| 148 |
+
### Training Procedure
|
| 149 |
+
|
| 150 |
+
Supervised fine-tuning (SFT) with **QLoRA**: the base model frozen in 4-bit NF4 quantization, with LoRA adapters (rank 16, all linear layers, plus `lm_head`/`embed_tokens`) trained via Hugging Face TRL's `SFTTrainer`, following [Google's official Gemma 4 vision QLoRA guide](https://ai.google.dev/gemma/docs/core/huggingface_vision_finetune_qlora).
|
| 151 |
+
|
| 152 |
+
#### Preprocessing
|
| 153 |
+
|
| 154 |
+
Each example is formatted as a three-turn conversation (system = schema instruction, user = image + extraction request, assistant = gold `graph.json`) and templated with the official Gemma 4 chat template. Images are processed at their native aspect ratio; image tokens are masked out of the training loss.
|
| 155 |
+
|
| 156 |
+
#### Training Hyperparameters
|
| 157 |
+
|
| 158 |
+
- **Training regime:** bf16 mixed precision (4-bit NF4 quantized base, bf16 compute)
|
| 159 |
+
- **LoRA:** r=16, alpha=16, dropout=0.05, target_modules=all-linear
|
| 160 |
+
- **Epochs:** 3
|
| 161 |
+
- **Learning rate:** 2e-4 (constant schedule)
|
| 162 |
+
- **Per-device batch size:** 1
|
| 163 |
+
- **Max grad norm:** 0.3
|
| 164 |
+
|
| 165 |
+
#### Speeds, Sizes, Times
|
| 166 |
+
|
| 167 |
+
[More Information Needed β fill after training: total training time, adapter size, merged checkpoint size]
|
| 168 |
+
|
| 169 |
+
## Evaluation
|
| 170 |
+
|
| 171 |
+
### Testing Data, Factors & Metrics
|
| 172 |
+
|
| 173 |
+
#### Testing Data
|
| 174 |
+
|
| 175 |
+
A held-out **test split (5%)** of [`OpenGraphAI/opengraph-image-gold-v1`](https://huggingface.co/datasets/OpenGraphAI/opengraph-image-gold-v1), never seen during training.
|
| 176 |
+
|
| 177 |
+
#### Factors
|
| 178 |
+
|
| 179 |
+
Results are disaggregated by image source/domain (converted scene-graph data vs. frontier-labeled robot/inspection frames). [More Information Needed β add further factors after evaluation]
|
| 180 |
+
|
| 181 |
+
#### Metrics
|
| 182 |
+
|
| 183 |
+
- **Schema-valid extraction rate** β % of outputs that parse as JSON *and* pass the OpenGraph Pydantic validators on the first attempt. Chosen because downstream graph tooling hard-fails on invalid output; this is the reliability number that matters in production.
|
| 184 |
+
- **Node F1 / Edge F1** β precision and recall of predicted nodes and edges against the gold graph, matched on normalized label + type. Measures whether the *content* of the graph is right, not just its shape.
|
| 185 |
+
- **Cost per 1,000 images & p50 latency** β the practical case for a small fine-tune over a frontier API.
|
| 186 |
+
|
| 187 |
+
### Results
|
| 188 |
+
|
| 189 |
+
All numbers produced by the open [eval harness](https://github.com/OpenGraphAI/opengraph-ai) and reproducible from the linked script.
|
| 190 |
+
|
| 191 |
+
| Metric | This model | Base Gemma 4 E4B-it | Frontier API baseline |
|
| 192 |
+
|---|---|---|---|
|
| 193 |
+
| Schema-valid rate | [More Information Needed] | [More Information Needed] | [More Information Needed] |
|
| 194 |
+
| Node/Edge F1 | [More Information Needed] | [More Information Needed] | [More Information Needed] |
|
| 195 |
+
| $ / 1k images | [More Information Needed] | [More Information Needed] | [More Information Needed] |
|
| 196 |
+
| p50 latency | [More Information Needed] | [More Information Needed] | [More Information Needed] |
|
| 197 |
+
|
| 198 |
+
#### Summary
|
| 199 |
+
|
| 200 |
+
[More Information Needed β 2β3 honest sentences: where the fine-tune wins, where it still trails the frontier baseline]
|
| 201 |
+
|
| 202 |
+
## Environmental Impact
|
| 203 |
+
|
| 204 |
+
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 205 |
+
|
| 206 |
+
- **Hardware Type:** [More Information Needed β e.g., 1Γ NVIDIA L4 / A100]
|
| 207 |
+
- **Hours used:** [More Information Needed]
|
| 208 |
+
- **Cloud Provider:** Google Colab
|
| 209 |
+
- **Compute Region:** [More Information Needed]
|
| 210 |
+
- **Carbon Emitted:** [More Information Needed]
|
| 211 |
+
|
| 212 |
+
## Technical Specifications
|
| 213 |
+
|
| 214 |
+
### Model Architecture and Objective
|
| 215 |
+
|
| 216 |
+
Gemma 4 E4B: a decoder-only transformer (~4.5B effective parameters, ~8B with embeddings) with a dedicated vision encoder, hybrid local/global attention, and a 128K-token context window. Fine-tuning objective: supervised next-token prediction on gold `graph.json` completions, with prompt and image tokens masked from the loss.
|
| 217 |
+
|
| 218 |
+
### Compute Infrastructure
|
| 219 |
+
|
| 220 |
+
#### Hardware
|
| 221 |
+
|
| 222 |
+
[More Information Needed β e.g., 1Γ NVIDIA L4 24GB (Google Colab Pro)]
|
| 223 |
+
|
| 224 |
+
#### Software
|
| 225 |
+
|
| 226 |
+
Python, PyTorch, Hugging Face `transformers>=5.10.1`, `trl`, `peft`, `bitsandbytes`, `datasets`.
|
| 227 |
+
|
| 228 |
+
## Citation
|
| 229 |
+
|
| 230 |
+
**BibTeX:**
|
| 231 |
+
|
| 232 |
+
```bibtex
|
| 233 |
+
@misc{opengraph2026imagegemma,
|
| 234 |
+
title = {opengraph-image-gemma4-e4b-v1: A schema-faithful image-to-knowledge-graph model},
|
| 235 |
+
author = {OpenGraph AI},
|
| 236 |
+
year = {2026},
|
| 237 |
+
url = {https://huggingface.co/OpenGraphAI/opengraph-image-gemma4-e4b-v1}
|
| 238 |
+
}
|
| 239 |
+
```
|
| 240 |
+
|
| 241 |
+
This model builds on Gemma 4 β please also cite the [Gemma 4 Technical Report](https://arxiv.org/abs/2607.02770) (Gemma Team, 2026).
|
| 242 |
+
|
| 243 |
+
## More Information
|
| 244 |
+
|
| 245 |
+
OpenGraph AI is open-source, MCP-first infrastructure for turning heterogeneous data (images, tables, text) into semantic knowledge graphs that AI agents can query and reason over. β [Star the repo](https://github.com/OpenGraphAI/opengraph-ai) β and contribute schemas, test images, or extraction edge cases.
|
| 246 |
+
|
| 247 |
+
## Model Card Authors
|
| 248 |
+
|
| 249 |
+
OpenGraph AI team
|
| 250 |
+
|
| 251 |
+
## Model Card Contact
|
| 252 |
+
|
| 253 |
+
team@opengraphai.io Β· [GitHub issues](https://github.com/OpenGraphAI/opengraph-ai/issues)
|