7 2 months ago

Gemma 4 E2B fine-tune for biological microscopy · 95 genera · 89% genus accuracy · runs offline · Apache-2.0 + CC-BY 4.0

vision tools thinking
ollama run brinzaengineeringai/microlens-final

Applications

Claude Code
Claude Code ollama launch claude --model brinzaengineeringai/microlens-final
OpenCode
OpenCode ollama launch opencode --model brinzaengineeringai/microlens-final
Hermes Agent
Hermes Agent ollama launch hermes --model brinzaengineeringai/microlens-final
OpenClaw
OpenClaw ollama launch openclaw --model brinzaengineeringai/microlens-final

Models

View all →

Readme

MicroLens — Gemma 4 Vision for Field Microscopy

A pocket microscope that fits in your pocket. Open-weight, offline, license-clean. Built for the Gemma 4 Good Hackathon (Kaggle 2026).

ollama run brinzaengineeringai/microlens-final

Then drop in a microscopy image and ask “Identify the organism and describe its morphology.”


Why this matters

Diatoms are the gold-standard bioindicator for freshwater quality under the European Water Framework Directive. A community lake monitor or a high-school biology class can measure pollution by counting and identifying diatoms — but a trained diatomologist takes years to learn the 200+ relevant genera, and the world is short on taxonomists.

Closed-source SaaS tools require internet and a credit card. Image-classification CNNs emit only a label — no morphology, no habitat reasoning, no “why”.

MicroLens turns a 2 B-effective vision model into a field assistant that:

  • Runs offline on a $100 Android phone (4 GB RAM) or a Raspberry Pi 5
  • Identifies 95 genera of diatoms and fungal spores
  • Produces explainable answers — morphology, habitat, identification cues — not just labels
  • Is license-clean for commercial use (Apache 2.0 weights + CC-BY 4.0 training data)

Pair with a $20 USB-microscope clip-on lens → floor hardware cost: $120. That is what digital equity for science looks like.


What’s in the box

  • Base model: unsloth/gemma-4-E2B-it4.44 B total parameters · ~2 B effective via Per-Layer Embeddings (PLE), runnable on consumer GPU, Android phones, and Raspberry Pi 5.
  • Fine-tuning: LoRA on both vision and language towers (r=16, α=32), 29.9 M trainable parameters (0.58 % of base).
  • Quantisation: Q4_K_M (~6.5 GB on Hub, audio encoder stripped).
  • Chat template: Gemma 4 instruction format with thinking-mode support.

Held-out evaluation

Measured on a 200-pair stratified sample of the held-out validation split (150 diatoms + 50 fungal spores, covering all 95 genera):

Metric Value
Genus accuracy (substring match) 89.0 %
Category accuracy (diatom vs fungal spore) 100 %
Format adherence (morphology / habitat / cues) 89.5 %
Genus accuracy — fungal spores only 100 %

The 11 % of genus misses are between visually adjacent diatom genera (Bacillaria ↔ Nitzschia, Cyclostephanos ↔ Discostella, Staurosirella ↔ Staurosira) — pairs that even expert diatomists routinely confuse without SEM imaging.

Training data

75,491 image-question-answer pairs · 95 unique genera · 2 categories:

Source Pairs License
UDE Diatoms in the Wild 2024 (Zenodo 10410655) 39,389 CC0
DIATLAS open European diatom imaging (Zenodo 16260887) 23,544 CC-BY 4.0
TgFC — Tectona grandis Fungal Community (figshare 28855910) 4,188 CC-BY 4.0

Top-30 genera have hand-curated knowledge-base answers from AlgaeBase, WoRMS, and ITIS.

Datasets released on Kaggle:

  • VQA: kaggle.com/datasets/sergheibrinza/microlens-vqa-hackathon
  • Images: kaggle.com/datasets/sergheibrinza/microlens-images-hackathon

Training configuration

  • 1× NVIDIA RTX 3090 Ti (24 GB), single-GPU
  • 2 full epochs · ~8,400 optimizer steps · 14.7 hours wall-clock
  • Unsloth FastVisionModel + TRL SFTTrainer + 4-bit QLoRA
  • LR 2e-4 · cosine schedule · warmup 0.03 · AdamW-8bit · bf16 · seed 42
  • Eval loss decreased monotonically from 0.0377 (step 500) to 0.0189 (step 8392) — clean convergence, no overfitting

Example output

Image: Gomphonella olivacea (UDE Diatoms)

MicroLens: *“This is a diatom of the genus Gomphonella, specifically Gomphonella olivacea. Morphology: pennate diatom with characteristic silica frustule composed of two valves (epitheca and hypotheca). Cell size, valve outline, and striae pattern are species-specific. Frustule preserves well in sediments. Habitat: ubiquitous in fresh, brackish, and marine waters worldwide. Identification cues: valve outline, raphe arrangement, striae density and pattern, presence/absence of rimoportulae, fultoportulae, fibulae.”*

Limitations & honest tradeoffs

  • Trained on stained light-microscopy at 384 × 384. Performance on SEM, fluorescence, or live-field photographs is not characterised.
  • Coverage is narrow: diatoms and fungal spores only.
  • Long-tail genera (outside the top-30 KB-curated set) produce shorter, templated answers.
  • Confidence calibration is informal — natural-language hedging, not probabilities.
  • The tools capability tag shown on this Hub page is inherited from base Gemma 4, not trained for MicroLens. Tool-calling and function-calling are not characterised for this fine-tune — use vision and chat features only.
  • Research and educational use only. This is not a regulated medical device.

License

  • Model weights & Modelfile: Apache-2.0
  • Training-data aggregate: CC-BY 4.0 (attribution required for the aggregate and the upstream sources Zenodo 10410655 / 16260887 / figshare 28855910)

Citation

@misc{brinza2026microlens,
  title  = {MicroLens: Gemma 4 Vision for Biological Microscopy},
  author = {Brinza, Serghei},
  year   = {2026},
  month  = {may},
  url    = {https://ollama.com/brinzaengineeringai/microlens-final},
  note   = {Submission for the Gemma 4 Good Hackathon, Kaggle 2026}
}

Author

Serghei Brinza — AI engineer, Vienna, Austria. Open vision-language models for biological and microscopy applications.


Built with Unsloth and Google Gemma 4. Diatom imagery used under CC0 and CC-BY 4.0.