RinNguyen103 commited on
Commit
6b653b0
·
verified ·
1 Parent(s): 2ff691e

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +102 -3
README.md CHANGED
@@ -1,3 +1,102 @@
1
- ---
2
- license: unknown
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🇻🇳 Vietnamese Image Captioning Model
2
+
3
+ > **EfficientNet-B0 × BARTPho** | *Trained on UIT-ViIC dataset*
4
+
5
+ ## 📌 Giới thiệu
6
+
7
+ Mô hình Sinh chú thích ảnh tiếng Việt (Vietnamese Image Captioning) huấn luyện trên bộ dữ liệu UIT-ViIC, cho phép tạo mô tả ảnh tự nhiên và chính xác bằng tiếng Việt.
8
+
9
+ ### Ứng dụng:
10
+
11
+ * 🔍 **Tìm kiếm ảnh** theo ngôn ngữ tự nhiên
12
+ * 🦯 **Hỗ trợ người khiếm thị** tiếp cận nội dung hình ảnh
13
+ * 🤖 **Tích hợp** vào hệ thống AI đa phương thức (Multimodal AI)
14
+
15
+ ## 🧠 Kiến trúc mô hình
16
+
17
+ | Thành phần | Mô tả |
18
+ |------------|-------|
19
+ | **Encoder** | EfficientNet-B0 (pretrained từ NVIDIA TorchHub) → Trích xuất đặc trưng ảnh thành vector embedding |
20
+ | **Decoder** | BARTPho-Syllable → Sinh câu mô tả dựa trên đặc trưng ảnh |
21
+
22
+ ### Pipeline:
23
+
24
+ ```
25
+ Ảnh → EncoderCNN (EfficientNet-B0) → vector đặc trưng (embed size = 768)
26
+ → Linear projection → encoder BARTPho
27
+ → BARTPho decoder → sinh chú thích tiếng Việt
28
+ ```
29
+
30
+ ## ⚙️ Thông số huấn luyện
31
+
32
+ | Tham số | Giá trị |
33
+ |---------|---------|
34
+ | **Dataset** | UIT-ViIC (train/val/test) |
35
+ | **Loss** | CrossEntropyLoss (ignore pad tokens) |
36
+ | **Optimizer** | Adam (lr = 5e-5) |
37
+ | **Batch size** | 32 |
38
+ | **Epochs** | 30 |
39
+ | **Gradient clipping** | 1.0 |
40
+ | **Mixed Precision** | torch.cuda.amp |
41
+ | **Image augmentation** | Resize(256) → RandomCrop(224) → Normalize(Imagenet) |
42
+
43
+ ## 📊 Metrics hỗ trợ
44
+
45
+ - **BLEU**
46
+ - **ROUGE-L**
47
+ - **METEOR**
48
+ - **CIDEr**
49
+ - **F1 trung bình token-level**
50
+ - **Recall trung bình token-level**
51
+
52
+ > *Điểm số cụ thể phụ thuộc vào checkpoint được tải.*
53
+
54
+ ## 🚀 Cách sử dụng
55
+
56
+ ```python
57
+ import torch
58
+ from PIL import Image
59
+ from torchvision import transforms
60
+ from image_caption import ImageCaptioningModel, Vocabulary
61
+ from huggingface_hub import hf_hub_download
62
+
63
+ DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
64
+ model_name = "vinai/bartpho-syllable"
65
+
66
+ # Load vocab & model
67
+ vocab = Vocabulary(model_name=model_name)
68
+ model = ImageCaptioningModel(embed_size=768, bartpho_model_name=model_name,
69
+ train_CNN=False, freeze_bartpho=False).to(DEVICE)
70
+
71
+ # Download checkpoint từ Hugging Face
72
+ ckpt_path = hf_hub_download(repo_id="username/vietnamese-image-captioning",
73
+ filename="best_image_captioning_model_vietnamese.pth.tar")
74
+ model.load_state_dict(torch.load(ckpt_path, map_location=DEVICE)["state_dict"])
75
+ model.eval()
76
+
77
+ # Transform ảnh
78
+ tfm = transforms.Compose([
79
+ transforms.Resize((256, 256)),
80
+ transforms.CenterCrop((224, 224)),
81
+ transforms.ToTensor(),
82
+ transforms.Normalize(mean=[0.485, 0.456, 0.406],
83
+ std=[0.229, 0.224, 0.225]),
84
+ ])
85
+
86
+ img = Image.open("your_image.jpg").convert("RGB")
87
+ img = tfm(img).to(DEVICE)
88
+
89
+ with torch.no_grad():
90
+ caption = model.predict(img, vocab, max_length=50)
91
+
92
+ print("Caption:", caption)
93
+ ```
94
+
95
+ ## 📜 Giấy phép
96
+
97
+ - **Model**: Tuân theo giấy phép của BARTPho và EfficientNet
98
+ - **Dataset**: UIT-ViIC (chỉ sử dụng cho nghiên cứu & học tập)
99
+
100
+ ## 👤 Tác giả
101
+
102
+ **Nguyễn Thành Đạt**