---
license: mit
base_model: florence-community/Florence-2-base-ft
library_name: transformers
pipeline_tag: image-to-text
language:
- en
datasets:
- tomytjandra/h-and-m-fashion-caption
tags:
- image-captioning
- alt-text
- accessibility
- fashion
- florence-2
---
# Apparel Image Caption
Give it a retail clothing photo and it writes a short, objective description suitable for a
screen reader, for example:
> Dark purple checked shirt with a turn-down collar, chest pockets, long sleeves with buttoned
> cuffs and a rounded hem.
It is [Florence-2-base](https://huggingface.co/florence-community/Florence-2-base-ft) (231M
parameters) fine-tuned on H&M product photos. This was a course project on image captioning.
Try it in the [demo Space](https://huggingface.co/spaces/MeghanaNanuvala/apparel-image-caption).
## How to use
Needs `transformers` 4.56 or newer (trained with 5.24.0).
```python
from PIL import Image
from transformers import AutoProcessor, Florence2ForConditionalGeneration
repo = "MeghanaNanuvala/apparel-image-caption"
processor = AutoProcessor.from_pretrained(repo)
model = Florence2ForConditionalGeneration.from_pretrained(repo).eval()
image = Image.open("shirt.jpg").convert("RGB")
inputs = processor(text=["
"], images=[image], return_tensors="pt")
ids = model.generate(**inputs, max_new_tokens=96, num_beams=3, do_sample=False)
print(processor.batch_decode(ids, skip_special_tokens=True)[0].strip())
```
## Training
- **Data:** 20,491 image-caption pairs from `tomytjandra/h-and-m-fashion-caption`. The original
captions are lowercase, unpunctuated, mostly longer than 125 characters, and 88% of them state
things a camera cannot see (fibre content, linings, "soft"). Each one was rewritten by a
text-only LLM (Qwen2.5-7B-Instruct) into one punctuated sentence that keeps the visible facts.
Every rewrite was checked automatically; 19,363 passed and were used.
- **Split:** 17,418 train, 975 validation, 970 test, grouped so that images sharing a
description never end up on both sides.
- **Settings:** full fine-tune, input = image + the `` task prompt, target = the
alt-text. AdamW, learning rate 1e-5 with 5% warm-up then linear decay, batch size 16, 5 epochs,
bf16 autocast, 32 minutes on one H100. This is the checkpoint with the best validation CIDEr
(epoch 4).
## Results
970 held-out test images. Scores are multiplied by 100 (CIDEr's maximum is 1000).
| System | BLEU-4 | ROUGE-L | METEOR | CIDEr | CLIPScore |
|---|---:|---:|---:|---:|---:|
| BLIP-base, zero-shot | 2.3 | 22.1 | 18.0 | 18.5 | 77.9 |
| Florence-2-base, zero-shot | 1.8 | 22.6 | 17.4 | 16.5 | 77.9 |
| **This model** | **37.3** | **63.9** | **64.0** | **281.6** | **80.5** |
BLEU to CIDEr mostly measure how close the wording is to the reference style, which the
zero-shot models were never shown. CLIPScore compares the caption with the image and is the
fairer comparison: the gain there is real but modest (2.6 points). 94% of the captions are 125
characters or shorter, and all are a sentence with a capital letter and a full stop.
## Limitations
- The training targets were written by an LLM that did not see the images, so some of them
contain errors, and the model learned from those.
- It states small details it cannot always confirm, such as pockets, fly type or fastenings.
How often this happens has not been measured.
- It was trained only on H&M studio photos of single garments. On close-ups it still describes
a whole garment, and on other kinds of photos it is unreliable.
- Colour and pattern can be wrong for multi-colour and printed garments.
- The images are H&M catalogue data, used here for coursework. The dataset card states no
licence. The `mit` tag is the licence of the Florence-2 base model.