ViT-tiny Image Captioner (20.8M parameters)

A compact image-captioning model: a ViT-tiny/16 image encoder (vit_tiny_patch16_224, timm) feeding a 6-layer Transformer decoder (hidden 192, 8 heads) that writes captions with the distilbert-base-uncased tokenizer. Built and trained from scratch (decoder) by FYP team.

Try it with your own pictures: FarhanAK128/OptiPros-VLM-DEMO

Architecture

Part Details
Encoder ViT-tiny, patch 16, 224Γ—224 input β†’ 197 tokens Γ— 192 dims; last 4 blocks fine-tuned
Decoder 6 Γ— nn.TransformerDecoderLayer (d_model 192, 8 heads, FFN 768), sinusoidal positions
Vocabulary 30,522 WordPiece tokens (distilbert-base-uncased), [CLS]=start, [SEP]=end
Parameters 20,836,218 total

Training

  1. Stage 1 – COCO Captions (train2014), 35 epochs, Adam (decoder 1e-4, encoder 1e-5), TokenDrop(0.5), mixed precision.
  2. Stage 2 – fine-tuning: 3,000 images from jxie/flickr8k (train split), 20 epochs (best: epoch 20), AdamW, decoder LR 5e-05, encoder LR 5e-06, batch 64, TokenDrop 0.5, mixed precision.

Evaluation

Fine-tuning run (held-out 500 images, jxie/flickr8k validation split, greedy decoding)

BLEU-1 BLEU-2 BLEU-3 BLEU-4 ROUGE-L METEOR loss
Original checkpoint 0.5304 0.3284 0.1892 0.1079 0.3678 0.3095 3.1879
Fine-tuned (epoch 20) 0.5721 0.3882 0.2542 0.1681 0.4153 0.3712 2.8043

COCO val2014 (from the original training notebook, 5k images, temperature-0.5 sampling)

BLEU-1 BLEU-2 BLEU-3 BLEU-4
FP32 PyTorch 0.6081 0.4193 0.2804 0.1834
INT8 ONNX 0.5739 0.3835 0.2524 0.1624

INT8 ONNX = statically quantised encoder + decoder (onnxruntime, QDQ, per-channel).

Usage

# pip install torch torchvision timm transformers safetensors huggingface_hub pillow
from huggingface_hub import hf_hub_download
import importlib.util, sys
from PIL import Image

path = hf_hub_download("FarhanAK128/OptiPros-VLM-Finetuned", "modeling_captioner.py")
spec = importlib.util.spec_from_file_location("modeling_captioner", path)
mc = importlib.util.module_from_spec(spec); sys.modules["modeling_captioner"] = mc; spec.loader.exec_module(mc)

model, tokenizer = mc.load_captioner("FarhanAK128/OptiPros-VLM-Finetuned")
print(mc.caption_images(model, tokenizer, [Image.open("my_photo.jpg")]))          # greedy
print(mc.caption_images(model, tokenizer, [Image.open("my_photo.jpg")], temperature=0.5))  # sampled

Files

  • model.safetensors – weights (model_state_dict of the PyTorch checkpoint)
  • config.json – architecture hyper-parameters
  • modeling_captioner.py – model definition, preprocessing, generation, loader
  • metrics.json, examples.png, training_curves.png – results of the fine-tuning run

Limitations

  • Small model (20.8M params, 224Γ—224 input): captions are short and generic, and it can miscount objects or confuse similar ones.
  • English only; learned from COCO/Flickr-style everyday photos, so it is weaker on diagrams, screenshots, medical or other specialised images.
  • Inherits the biases of COCO / Flickr captions.
Downloads last month
70
Safetensors
Model size
20.8M params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Dataset used to train FarhanAK128/OptiPros-VLM-Finetuned