Pokzy commited on
Commit
596d165
·
verified ·
1 Parent(s): 6d93d57

Commit changes to main

Browse files
Files changed (1) hide show
  1. README.md +53 -0
README.md ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: Salesforce/blip-image-captioning-base
4
+ datasets:
5
+ - flickr8k
6
+ language:
7
+ - en
8
+ - th
9
+ pipeline_tag: image-to-text
10
+ tags:
11
+ - image-captioning
12
+ - blip
13
+ - vision-encoder-decoder
14
+ - pytorch
15
+ - fine-tuned
16
+ ---
17
+ # 🖼️ BLIP Fine-Tuned on Flickr8k (Image Captioning)
18
+ This repository contains a **Fine-Tuned BLIP (Bootstrapping Language-Image Pre-training)** model for **Image Captioning**, trained on the **Flickr8k** dataset.
19
+ - **Base Model:** [`Salesforce/blip-image-captioning-base`](https://huggingface.co/Salesforce/blip-image-captioning-base)
20
+ - **Developer:** Pokzy
21
+ - **Interactive Web Demo:** [Hugging Face Space Demo](https://huggingface.co/spaces/Pokzy/image-captioning-blip)
22
+ ---
23
+ ## 📌 Model Description
24
+ This model takes an image as input and generates descriptive English captions. It has been fine-tuned on the 8,000 daily images and human-annotated captions of the **Flickr8k** dataset to improve caption accuracy for everyday outdoor scenes, people, animals, and sports activities.
25
+ In the associated web application, generated captions are also translated into **Thai (ภาษาไทย)** using the NLLB-200 translation model (`facebook/nllb-200-distilled-600M`).
26
+ ---
27
+ ## 🚀 How to Use
28
+ You can easily load and use this fine-tuned model using Hugging Face's `transformers` library:
29
+ ```python
30
+ import torch
31
+ from PIL import Image
32
+ from transformers import BlipProcessor, BlipForConditionalGeneration
33
+ # 1. Load Preprocessor & Fine-Tuned Model
34
+ processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
35
+ model = BlipForConditionalGeneration.from_pretrained("Pokzy/flickr8k-finetuned")
36
+ device = "cuda" if torch.cuda.is_available() else "cpu"
37
+ model.to(device)
38
+ model.eval()
39
+ # 2. Load & Preprocess Image
40
+ image_path = "example.jpg"
41
+ image = Image.open(image_path).convert("RGB")
42
+ inputs = processor(images=image, return_tensors="pt").to(device)
43
+ # 3. Generate Caption
44
+ with torch.no_grad():
45
+ output_ids = model.generate(
46
+ **inputs,
47
+ do_sample=True,
48
+ temperature=0.7,
49
+ top_p=0.9,
50
+ max_length=50
51
+ )
52
+ caption = processor.decode(output_ids[0], skip_special_tokens=True)
53
+ print("Generated Caption:", caption)