Math behind the solution: https://zenodo.org/records/21245474
Full code of model creation (TOPO): https://github.com/frank-morales2020/AST/blob/main/13TASK_TOPO.ipynb
Application code (FERRARI AI - MEDICAL IMAGE ANALYSIS SYSTEM): https://github.com/frank-morales2020/AST/blob/main/FERRARI_MEDICAL_REASONING.ipynb
TOPO-2026: Gemma-4-E4B-Vision with 13 Tasks
Model Description
Gemma-4-E4B-Vision fine-tuned on 13 vision tasks using TOPO-2026.
Results
- β 100% Accuracy on all 13 tasks
- β 0% Forgetting
- β NF4 Quantization
- β Boundary Layer 24 anchor
- β Prime Anchors: [2, 3, 5, 7, 11, 13]
INFERENCE
import sys
import os
import contextlib
from PIL import Image
# 1. Download image using wget and load it
image_url = "https://picsum.photos/300/300"
image_filename = "test_image.jpg"
os.system(f"wget -q -O {image_filename} {image_url}")
image = Image.open(image_filename).convert("RGB")
import sys
import os
import contextlib
# Suppress all C/C++/Python low-level file descriptor prints during imports
@contextlib.contextmanager
def suppress_all_output():
with open(os.devnull, "w") as devnull:
old_stdout = sys.stdout
old_stderr = sys.stderr
sys.stdout = devnull
sys.stderr = devnull
try:
yield
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
# Completely silence unsloth/transformers startup output and progress bars
os.environ["UNSLOTH_DISABLE_LOGGING"] = "1"
os.environ["TRANSVERSE_NO_PROGRESS_BARS"] = "1"
os.environ["TQDM_DISABLE"] = "1"
with suppress_all_output():
import torch
import numpy as np
# Globally enforce weights_only=False for PyTorch 2.6+ checkpoint loading
original_torch_load = torch.load
def patched_torch_load(*args, **kwargs):
kwargs["weights_only"] = False
return original_torch_load(*args, **kwargs)
torch.load = patched_torch_load
from huggingface_hub import hf_hub_download
from PIL import Image
from unsloth import FastVisionModel
MODEL_ID = "frankmorales2020/topo-gemma-4-e4b-vision-13tasks"
with suppress_all_output():
ckpt_path = hf_hub_download(repo_id=MODEL_ID, filename="pytorch_model.bin")
checkpoint = torch.load(ckpt_path, map_location="cpu")
BASE_MODEL = checkpoint.get("base_model", "frankmorales2020/gemma-4-e4b-unesco-optimized")
model, tokenizer = FastVisionModel.from_pretrained(
model_name=BASE_MODEL,
load_in_4bit=True,
dtype=torch.bfloat16,
)
FastVisionModel.for_inference(model)
# 1. Load test image
image = Image.open("test_image.jpg").convert("RGB")
# 2. Define all 13 tasks
tasks = [
("Task A", "Animal vs Vehicle", "Does this image depict an animal or a vehicle?"),
("Task B", "Natural vs Man-Made", "Is this subject natural or man-made?"),
("Task C", "Living vs Non-Living", "Is the primary subject living or non-living?"),
("Task D", "Large vs Small", "Is the subject large or small in scale?"),
("Task E", "Ground vs Air/Water", "Does this subject belong to ground or air/water?"),
("Task F", "Domestic vs Wild", "Is this subject domestic or wild?"),
("Task G", "Mammal vs Non-Mammal", "Is this subject a mammal or non-mammal?"),
("Task H", "Flying vs Non-Flying", "Is this subject flying or non-flying?"),
("Task I", "Fast vs Slow", "Is this subject characterized as fast or slow?"),
("Task J", "Urban vs Rural", "Does this setting represent an urban or rural environment?"),
("Task K", "Predator vs Prey", "Is this subject a predator or prey?"),
("Task L", "Nocturnal vs Diurnal", "Is this subject nocturnal or diurnal?"),
("Task M", "Domesticated vs Wild Animals", "Is this animal domesticated or wild?")
]
print("\n" + "="*80)
print("π EVALUATING ALL 13 TOPO-2026 TASKS")
print("="*80)
for task_id, task_name, prompt in tasks:
messages = [
{
"role": "user",
"content": [
{"type": "image"},
{"type": "text", "text": f"{task_id} ({task_name}): {prompt}"}
]
}
]
input_text = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
inputs = tokenizer(
image,
input_text,
add_special_tokens=False,
return_tensors="pt",
).to("cuda")
with torch.inference_mode():
output_tokens = model.generate(
**inputs,
max_new_tokens=24,
do_sample=False,
use_cache=True,
)
response = tokenizer.decode(output_tokens[0], skip_special_tokens=True)
answer = response.split("model")[-1].strip() if "model" in response else response
print(f"[{task_id}] {task_name:<30} β {answer}")
print("="*80)
print("π EVALUATION COMPLETE!")
print("="*80)
EXPECTED - INFERENCE - OUTPUT
Loadingβweights:β100%β2130/2130β[00:03<00:00,β1004.30it/s]
================================================================================
π EVALUATING ALL 13 TOPO-2026 TASKS
================================================================================
[Task A] Animal vs Vehicle β This image depicts **neither** an animal nor a vehicle. It is a landscape photograph of the **ocean/sea**
[Task B] Natural vs Man-Made β This subject is **natural**.
It depicts a seascape with waves, ocean, and a distant landmass under a dramatic
[Task C] Living vs Non-Living β The primary subject in the image is the **ocean/sea** and the **sky/weather**.
Both the ocean
[Task D] Large vs Small β Based on the image, the **subject** (the ocean, waves, and coastline) is **large in scale**.
[Task E] Ground vs Air/Water β This subject belongs to **both ground and air/water**.
Here's why:
* **Water:** The
[Task F] Domestic vs Wild β This subject is **wild**.
The image depicts a natural scene: the ocean, waves, and the sky. These
[Task G] Mammal vs Non-Mammal β Based on the image provided, there is **no subject** visible that is an animal. The image is a landscape photograph
[Task H] Flying vs Non-Flying β Based on the image provided, there is **no subject** that is clearly flying or non-flying.
The image
[Task I] Fast vs Slow β Based on the image, the subject matter is a **seascape** (ocean waves, sky, and coastline).
[Task J] Urban vs Rural β This setting represents a **rural** environment.
Here's why:
* **Natural Landscape:** The image is
[Task K] Predator vs Prey β Based on the image provided, which is a **landscape photograph of the ocean at sunset/sunrise**, there are **no
[Task L] Nocturnal vs Diurnal β Based on the image, the subject is a **seascape** (ocean, waves, sky).
The concept of
[Task M] Domesticated vs Wild Animals β I'm sorry, but you have provided an image of a **seascape (ocean waves and sky)**, not
================================================================================
π EVALUATION COMPLETE!
================================================================================
- Downloads last month
- 100
Inference Providers NEW
This model isn't deployed by any Inference Provider. π Ask for provider support