anmol-unitmole commited on
Commit
beb5793
Β·
verified Β·
1 Parent(s): 130d4de

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +205 -48
README.md CHANGED
@@ -1,88 +1,245 @@
1
- # Model Card Β· RTX 5090 Vision Encoder-Decoder Image Captioning
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  ## System
4
 
5
- `02-image-caption-generation-vision-encoder-decoder`
6
 
7
  ## Status
8
 
9
- **Execution-ready, not yet result-complete.** This repository contains the complete training, evaluation, optimization, and deployment workflow. Fine-tuned weights, new metrics, ONNX parity results, and the final public URL must be generated on the target RTX 5090 system.
 
 
 
 
 
 
10
 
11
  ## Architecture
12
 
13
- - Python checkpoint: `nlpconnect/vit-gpt2-image-captioning`
14
- - Vision encoder: ViT
15
  - Text decoder: GPT-2 with encoder cross-attention
16
- - Framework: PyTorch and Hugging Face `VisionEncoderDecoderModel`
17
- - Browser baseline: `Xenova/vit-gpt2-image-captioning`
 
 
18
  - Browser runtime: Transformers.js and ONNX Runtime Web
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  ## Training method
21
 
22
- 1. Freeze the vision encoder and adapt the decoder/cross-modal path.
23
- 2. Unfreeze the top six vision blocks with differential learning rates.
24
- 3. Conservatively fine-tune the full architecture.
25
- 4. Select checkpoints using generated-caption validation metrics, with validation-loss fallback.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
- Implemented controls include BF16/FP16 handling, TF32, fused AdamW fallback, gradient accumulation, label smoothing, warm-up, cosine decay, minimum LR floor, gradient clipping, early stopping, resumable checkpoints, environment capture, and peak GPU-memory reporting.
 
 
 
 
 
28
 
29
- ## Data
30
 
31
- Primary experiment: Flickr30k. Multiple references remain grouped for evaluation. The repository does not redistribute the complete dataset.
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  ## Inputs
34
 
35
- RGB JPG, PNG, WEBP, or BMP images after safe decoding, EXIF orientation correction, and checkpoint-native image processing.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  ## Outputs
38
 
39
- - greedy caption;
40
- - ranked beam candidates;
41
- - concise model-generated alt-text draft;
42
- - token transition scores where available;
 
 
 
43
  - sequence score where available;
44
- - latency and generation settings;
45
- - optional genuine cross-attention output.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- ## Evaluation
48
 
49
- Required final evidence:
 
 
 
 
 
 
50
 
51
- - BLEU-1 and BLEU-4;
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
- No new score is claimed until the corresponding artifact exists under `outputs/`.
65
 
66
- ## Intended use
67
 
68
- Education, portfolio demonstration, image-captioning experimentation, draft metadata, human-reviewed visual documentation, and quality-reporting research prototypes.
69
 
70
- ## Prohibited or unsuitable use
 
 
 
71
 
72
- Identity recognition, surveillance, sensitive-attribute inference, accessibility-critical publishing without review, product release, official quality decisions, medical, legal, financial, hiring, insurance, security, or safety-critical decisions.
73
 
74
- ## Limitations
75
 
76
- The model can hallucinate, omit important objects, confuse colors and counts, produce generic descriptions, repeat phrases, and fail on poor-quality or out-of-distribution images. Flickr30k is not an industrial inspection dataset. Quality challenge results measure descriptive behavior only and do not establish defect-detection competence.
77
 
78
- ## Confidence and interpretability
79
 
80
- Generated-token probability is not calibrated correctness. The browser's structural heuristic is not presented as model confidence. Token and attention views are interpretability aids and do not prove reasoning.
 
 
 
81
 
82
- ## Privacy
83
 
84
- Do not upload personal, confidential, medical, proprietary, security-sensitive, or unlicensed images to a public Space. Public samples must be synthetic, public-domain, or properly licensed.
85
 
86
- ## Deployment
87
 
88
- The fine-tuned Python checkpoint must be converted to a Transformers.js-compatible ONNX repository and pass parity/browser checks before `fine_tuned_model_id` is enabled in `web/metadata.json`.
 
 
 
 
 
 
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