Image-to-Text
Transformers
ONNX
Transformers.js
PyTorch
English
vision-encoder-decoder
image-text-to-text
image-captioning
vision-language
onnxruntime
vit
gpt2
Instructions to use anmol-unitmole/image-caption-generation-vision-encoder-decoder-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use anmol-unitmole/image-caption-generation-vision-encoder-decoder-model with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "image-to-text" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # 'pip install "transformers<5.0.0' from transformers import pipeline pipe = pipeline("image-to-text", model="anmol-unitmole/image-caption-generation-vision-encoder-decoder-model")# Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("anmol-unitmole/image-caption-generation-vision-encoder-decoder-model") model = AutoModelForMultimodalLM.from_pretrained("anmol-unitmole/image-caption-generation-vision-encoder-decoder-model", device_map="auto") - Transformers.js
How to use anmol-unitmole/image-caption-generation-vision-encoder-decoder-model with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('image-to-text', 'anmol-unitmole/image-caption-generation-vision-encoder-decoder-model'); - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,88 +1,245 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
## System
|
| 4 |
|
| 5 |
-
`
|
| 6 |
|
| 7 |
## Status
|
| 8 |
|
| 9 |
-
**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
## Architecture
|
| 12 |
|
| 13 |
-
-
|
| 14 |
-
- Vision encoder: ViT
|
| 15 |
- Text decoder: GPT-2 with encoder cross-attention
|
| 16 |
-
-
|
| 17 |
-
-
|
|
|
|
|
|
|
| 18 |
- Browser runtime: Transformers.js and ONNX Runtime Web
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
## Training method
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
##
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
## Inputs
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
## Outputs
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
-
|
| 42 |
-
-
|
|
|
|
|
|
|
|
|
|
| 43 |
- sequence score where available;
|
| 44 |
-
-
|
| 45 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
- METEOR;
|
| 53 |
-
- ROUGE-L;
|
| 54 |
-
- CIDEr;
|
| 55 |
-
- CLIPScore;
|
| 56 |
-
- distinct-1 and distinct-2;
|
| 57 |
-
- unique-caption ratio and repetition rate;
|
| 58 |
-
- greedy-versus-beam analysis;
|
| 59 |
-
- model size and latency;
|
| 60 |
-
- quality challenge performance;
|
| 61 |
-
- manual failure analysis;
|
| 62 |
-
- PyTorch-versus-ONNX parity.
|
| 63 |
|
| 64 |
-
|
| 65 |
|
| 66 |
-
##
|
| 67 |
|
| 68 |
-
|
| 69 |
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
|
| 73 |
|
| 74 |
-
##
|
| 75 |
|
| 76 |
-
The model
|
| 77 |
|
| 78 |
-
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
|
| 84 |
-
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
library_name: transformers
|
| 5 |
+
pipeline_tag: image-to-text
|
| 6 |
+
base_model: nlpconnect/vit-gpt2-image-captioning
|
| 7 |
+
tags:
|
| 8 |
+
- vision-encoder-decoder
|
| 9 |
+
- image-captioning
|
| 10 |
+
- vision-language
|
| 11 |
+
- onnx
|
| 12 |
+
- transformers.js
|
| 13 |
+
- onnxruntime
|
| 14 |
+
- pytorch
|
| 15 |
+
- vit
|
| 16 |
+
- gpt2
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
# Fine-Tuned ViT-GPT-2 Vision Encoder-Decoder Image Captioning
|
| 20 |
+
|
| 21 |
+
## Model repository
|
| 22 |
+
|
| 23 |
+
`anmol-unitmole/image-caption-generation-vision-encoder-decoder-model`
|
| 24 |
|
| 25 |
## System
|
| 26 |
|
| 27 |
+
`image-caption-generation-vision-encoder-decoder-model`
|
| 28 |
|
| 29 |
## Status
|
| 30 |
|
| 31 |
+
**Training, held-out evaluation, browser-compatible ONNX export, dynamic quantization, and PyTorch-versus-ONNX parity validation are complete.**
|
| 32 |
+
|
| 33 |
+
This repository contains the browser-compatible model configuration, processor, tokenizer, generation configuration, and quantized ONNX artifacts for a fine-tuned ViT-GPT-2 Vision Encoder-Decoder image-captioning model.
|
| 34 |
+
|
| 35 |
+
The model was fine-tuned locally using an NVIDIA GeForce RTX 5090. The browser artifacts are intended for Transformers.js and ONNX Runtime Web inference inside a static Hugging Face Space.
|
| 36 |
+
|
| 37 |
+
The final public Static Space remains subject to successful browser loading and end-to-end caption-generation validation.
|
| 38 |
|
| 39 |
## Architecture
|
| 40 |
|
| 41 |
+
- Base checkpoint: `nlpconnect/vit-gpt2-image-captioning`
|
| 42 |
+
- Vision encoder: Vision Transformer β ViT
|
| 43 |
- Text decoder: GPT-2 with encoder cross-attention
|
| 44 |
+
- Python framework: PyTorch
|
| 45 |
+
- Hugging Face architecture: `VisionEncoderDecoderModel`
|
| 46 |
+
- Pretrained browser baseline: `Xenova/vit-gpt2-image-captioning`
|
| 47 |
+
- Fine-tuned browser repository: `anmol-unitmole/image-caption-generation-vision-encoder-decoder-model`
|
| 48 |
- Browser runtime: Transformers.js and ONNX Runtime Web
|
| 49 |
+
- Preferred browser provider: WebGPU
|
| 50 |
+
- Fallback browser provider: WebAssembly
|
| 51 |
+
|
| 52 |
+
## Task
|
| 53 |
+
|
| 54 |
+
The model generates English-language captions from input images.
|
| 55 |
+
|
| 56 |
+
Supported project features include:
|
| 57 |
+
|
| 58 |
+
- greedy caption generation;
|
| 59 |
+
- beam-search caption generation;
|
| 60 |
+
- caption-length controls;
|
| 61 |
+
- alternate-text draft generation;
|
| 62 |
+
- pretrained-versus-fine-tuned comparison;
|
| 63 |
+
- caption-structure diagnostics;
|
| 64 |
+
- genuine precomputed token-generation traces for bundled sample images;
|
| 65 |
+
- model latency and evaluation reporting.
|
| 66 |
|
| 67 |
## Training method
|
| 68 |
|
| 69 |
+
The model was trained using a staged adaptation strategy.
|
| 70 |
+
|
| 71 |
+
### Stage 1 β Decoder warm-up
|
| 72 |
+
|
| 73 |
+
- Freeze the complete vision encoder.
|
| 74 |
+
- Train the decoder and cross-modal generation pathway.
|
| 75 |
+
- Preserve pretrained visual representations during initial adaptation.
|
| 76 |
+
|
| 77 |
+
### Stage 2 β Upper encoder adaptation
|
| 78 |
+
|
| 79 |
+
- Unfreeze the upper eight ViT encoder blocks.
|
| 80 |
+
- Use a lower learning rate for the vision encoder.
|
| 81 |
+
- Continue adapting the decoder using a higher learning rate.
|
| 82 |
+
- Evaluate generated captions during training.
|
| 83 |
+
|
| 84 |
+
### Stage 3 β Conservative full fine-tuning
|
| 85 |
+
|
| 86 |
+
- Unfreeze the full encoder-decoder architecture.
|
| 87 |
+
- Apply reduced learning rates.
|
| 88 |
+
- Select the best checkpoint using validation CIDEr with configured fallback behavior.
|
| 89 |
+
|
| 90 |
+
Training controls included:
|
| 91 |
+
|
| 92 |
+
- BF16 mixed precision;
|
| 93 |
+
- TF32 support;
|
| 94 |
+
- fused AdamW fallback;
|
| 95 |
+
- gradient accumulation;
|
| 96 |
+
- label smoothing;
|
| 97 |
+
- warm-up scheduling;
|
| 98 |
+
- cosine learning-rate decay;
|
| 99 |
+
- minimum learning-rate floor;
|
| 100 |
+
- gradient clipping;
|
| 101 |
+
- early-stopping support;
|
| 102 |
+
- resumable checkpoints;
|
| 103 |
+
- best-checkpoint selection;
|
| 104 |
+
- environment and GPU-memory reporting.
|
| 105 |
+
|
| 106 |
+
## Hardware
|
| 107 |
+
|
| 108 |
+
The final experiment was executed locally using:
|
| 109 |
|
| 110 |
+
- GPU: NVIDIA GeForce RTX 5090
|
| 111 |
+
- GPU memory: approximately 31.84 GB
|
| 112 |
+
- CUDA build: CUDA 13.0
|
| 113 |
+
- PyTorch: 2.12.0 with CUDA 13.0
|
| 114 |
+
- Precision: BF16 where supported
|
| 115 |
+
- Operating system: Windows 11
|
| 116 |
|
| 117 |
+
## Dataset
|
| 118 |
|
| 119 |
+
The primary experiment used Flickr30k.
|
| 120 |
+
|
| 121 |
+
The processed experiment contained:
|
| 122 |
+
|
| 123 |
+
| Split | Unique images | Caption records |
|
| 124 |
+
|---|---:|---:|
|
| 125 |
+
| Training | 29,000 | 144,767 |
|
| 126 |
+
| Validation | 1,014 | 5,062 |
|
| 127 |
+
| Test | 1,000 | 4,985 |
|
| 128 |
+
|
| 129 |
+
Multiple reference captions remained grouped for evaluation.
|
| 130 |
+
|
| 131 |
+
The complete Flickr30k dataset is not redistributed through this model repository. Users must obtain the dataset according to its original access and licensing requirements.
|
| 132 |
|
| 133 |
## Inputs
|
| 134 |
|
| 135 |
+
Supported browser image formats:
|
| 136 |
+
|
| 137 |
+
- JPG/JPEG
|
| 138 |
+
- PNG
|
| 139 |
+
- WEBP
|
| 140 |
+
- BMP
|
| 141 |
+
|
| 142 |
+
Input processing includes:
|
| 143 |
+
|
| 144 |
+
- safe image decoding;
|
| 145 |
+
- EXIF orientation correction;
|
| 146 |
+
- RGB conversion;
|
| 147 |
+
- model-native image resizing and normalization;
|
| 148 |
+
- processor-compatible pixel-value generation;
|
| 149 |
+
- validation for unsupported or corrupt images.
|
| 150 |
|
| 151 |
## Outputs
|
| 152 |
|
| 153 |
+
The model may provide:
|
| 154 |
+
|
| 155 |
+
- one greedy caption;
|
| 156 |
+
- multiple ranked beam-search candidates;
|
| 157 |
+
- a concise alternate-text draft;
|
| 158 |
+
- generation latency;
|
| 159 |
+
- generation configuration;
|
| 160 |
- sequence score where available;
|
| 161 |
+
- genuine token-transition traces for bundled sample images;
|
| 162 |
+
- caption-structure diagnostics.
|
| 163 |
+
|
| 164 |
+
Generated captions are model predictions and are not guaranteed to be factually correct.
|
| 165 |
+
|
| 166 |
+
## Evaluation protocol
|
| 167 |
+
|
| 168 |
+
The pretrained baseline and fine-tuned model were evaluated on the same held-out 1,000-image Flickr30k test subset.
|
| 169 |
+
|
| 170 |
+
### Main results
|
| 171 |
+
|
| 172 |
+
| Metric | Pretrained baseline | Fine-tuned model |
|
| 173 |
+
|---|---:|---:|
|
| 174 |
+
| BLEU-1 | 0.5779 | 0.4350 |
|
| 175 |
+
| BLEU-4 | 0.1366 | 0.1078 |
|
| 176 |
+
| METEOR | 0.3337 | 0.4050 |
|
| 177 |
+
| ROUGE-L | 0.3759 | 0.3041 |
|
| 178 |
+
| CIDEr | 0.2336 | 0.0595 |
|
| 179 |
+
| CLIPScore | 0.6601 | 0.7211 |
|
| 180 |
+
| Distinct-1 | 0.0652 | 0.0708 |
|
| 181 |
+
| Distinct-2 | 0.2331 | 0.2478 |
|
| 182 |
+
| Unique-caption ratio | 0.9500 | 1.0000 |
|
| 183 |
+
| Average repetition rate | 0.1126 | 0.1463 |
|
| 184 |
+
| Mean GPU latency | 0.1163 seconds | 0.2762 seconds |
|
| 185 |
+
|
| 186 |
+
### Result interpretation
|
| 187 |
+
|
| 188 |
+
The fine-tuned model did not outperform the pretrained baseline on every metric.
|
| 189 |
+
|
| 190 |
+
Observed improvements included:
|
| 191 |
+
|
| 192 |
+
- higher METEOR;
|
| 193 |
+
- higher CLIPScore;
|
| 194 |
+
- higher Distinct-1;
|
| 195 |
+
- higher Distinct-2;
|
| 196 |
+
- a 1.0 unique-caption ratio.
|
| 197 |
|
| 198 |
+
Observed regressions included:
|
| 199 |
|
| 200 |
+
- lower BLEU-1;
|
| 201 |
+
- lower BLEU-4;
|
| 202 |
+
- lower ROUGE-L;
|
| 203 |
+
- lower CIDEr;
|
| 204 |
+
- increased caption length;
|
| 205 |
+
- increased repetition;
|
| 206 |
+
- slower generation latency.
|
| 207 |
|
| 208 |
+
These mixed results are reported intentionally. The experiment demonstrates that fine-tuning can improve semantic similarity and lexical diversity while reducing reference-overlap metrics or generation efficiency.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
+
The fine-tuned model should therefore not be described as universally superior to the pretrained baseline.
|
| 211 |
|
| 212 |
+
## Model size
|
| 213 |
|
| 214 |
+
The fine-tuned Python checkpoint contains approximately:
|
| 215 |
|
| 216 |
+
- Parameters: 239,195,904
|
| 217 |
+
- Estimated FP32 parameter size: 912.46 MB
|
| 218 |
+
- Estimated FP16 parameter size: 456.23 MB
|
| 219 |
+
- Serialized checkpoint directory size: 917.11 MB
|
| 220 |
|
| 221 |
+
Browser deployment uses quantized ONNX artifacts rather than the original PyTorch checkpoint.
|
| 222 |
|
| 223 |
+
## ONNX export
|
| 224 |
|
| 225 |
+
The model was exported using the `image-to-text-with-past` task and ONNX opset 18.
|
| 226 |
|
| 227 |
+
The browser export produced:
|
| 228 |
|
| 229 |
+
- `encoder_model.onnx`
|
| 230 |
+
- `decoder_model.onnx`
|
| 231 |
+
- `decoder_with_past_model.onnx`
|
| 232 |
+
- `decoder_model_merged.onnx`
|
| 233 |
|
| 234 |
+
The files were then processed through dynamic ONNX Runtime quantization.
|
| 235 |
|
| 236 |
+
## Browser model files
|
| 237 |
|
| 238 |
+
This repository contains the following quantized ONNX files:
|
| 239 |
|
| 240 |
+
```text
|
| 241 |
+
onnx/
|
| 242 |
+
βββ encoder_model_quantized.onnx
|
| 243 |
+
βββ decoder_model_quantized.onnx
|
| 244 |
+
βββ decoder_with_past_model_quantized.onnx
|
| 245 |
+
βββ decoder_model_merged_quantized.onnx
|