jxie/flickr8k
Viewer β’ Updated β’ 8k β’ 5.14k β’ 10
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
| 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 |
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.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 |
| 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).
# 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
model.safetensors β weights (model_state_dict of the PyTorch checkpoint)config.json β architecture hyper-parametersmodeling_captioner.py β model definition, preprocessing, generation, loadermetrics.json, examples.png, training_curves.png β results of the fine-tuning run