File size: 8,407 Bytes
119ce7b 5576e88 119ce7b 5576e88 119ce7b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
---
language:
- tr
license: apache-2.0
datasets:
- ituperceptron/image-captioning-turkish
base_model:
- Salesforce/blip-image-captioning-base
model-index:
- name: ogulcanakca/blip-base-turkish-image-captioning
results:
- task:
type: image-to-text
name: Türkçe Görüntü Altyazılama
metrics:
- name: SacreBLEU
type: sacrebleu
value: 0.1129
- name: ROUGE-L
type: rougeL_fmeasure
value: 0.2852
- name: ROUGE-1
type: rouge1_fmeasure
value: 0.3486
- name: METEOR
type: meteor
value: 0.2978
- name: Validation Loss
type: loss
value: 1.417300
pipeline_tag: image-to-text
tags:
- transformers
- pytorch
- blip
- image-captioning
- turkish
- ituperceptron/image-captioning-turkish
- fine-tuned
- multimodal
- computer-vision
- natural-language-processing
metrics:
- sacrebleu
- rouge
- meteor
---
# Türkçe Görüntü Altyazılama: BLIP ile Bir Başlangıç Noktası
## Projeye Genel Bakış ve Katkısı
Bu proje, `Salesforce/blip-image-captioning-base` modelinin, `ituperceptron/image-captioning-turkish` veri kümesinin "long_captions" bölümünden alınan bir alt küme üzerinde **Türkçe görüntü altyazıları üretmek** amacıyla ince ayar (fine-tuning) yapılmasına odaklanmaktadır. Amaç, görseller için otomatik, akıcı ve anlamlı Türkçe açıklamalar üretebilen bir model geliştirmek ve bu alanda bir "orta karar ama değerli bir başlangıç noktası" oluşturmaktır.
Bu çalışma, özellikle Türkçe gibi, İngilizceye kıyasla daha az kaynak ve önceden eğitilmiş modele sahip dillerde VLM (Görsel Dil Modeli) yeteneklerini keşfetmeyi ve geliştirmeyi hedefler.
## Veri Kümesi
* **Adı:** Türkçe Görüntü Altyazılama Veri Kümesi
* **Kaynak:** `ituperceptron/image-captioning-turkish`
* **Yapılandırma/Split:** `long_captions`
* **İçerik:** Çeşitli görseller ve bu görsellere ait insanlar tarafından yazılmış uzun, açıklayıcı Türkçe altyazılar.
* **Kullanılan Alt Küme:** Bu projede, eğitim ve değerlendirme için 60.000 örnekten oluşan bir alt küme kullanılmıştır.
## Model
* **Temel Model:** `Salesforce/blip-image-captioning-base`
* **Görev:** Görüntüden Metne Çeviri (Image-to-Text) / Görüntü Altyazılama (Image Captioning)
BLIP (Bootstrapping Language-Image Pre-training), görüntü ve metin arasındaki ilişkiyi anlamak ve bu ilişkiden yola çıkarak metin üretmek üzere tasarlanmış güçlü bir VLM mimarisidir.
## Temel Özellikler ve Yaklaşım
* `Salesforce/blip-image-captioning-base` modeli, Türkçe altyazılama görevine adapte etmek için `ituperceptron/image-captioning-turkish` veri kümesi üzerinde fine tunining yapılmıştır.
* Eğitimde, P100 GPU gibi kısıtlı kaynaklarda çalışabilmek için bellek optimizasyon teknikleri (örn: `per_device_eval_batch_size=1`, FP16 eğitimi, `PYTORCH_CUDA_ALLOC_CONF` ortam değişkeni, üretilen maksimum token sayısının sınırlandırılması) kullanılmıştır.
* Hugging Face `Transformers`, `Datasets` ve `Evaluate` kütüphaneleri, veri işleme, model eğitimi ve metriklerin hesaplanması için temel araçlar olarak kullanılmıştır.
* Modelin performansı SacreBLEU, ROUGE ve METEOR gibi standart görüntü altyazılama metrikleri ile değerlendirilmiştir.
## Performans (İnce Ayar Sonrası)
Model, `ituperceptron/image-captioning-turkish` veri kümesinin **test seti** üzerinde aşağıdaki performansı göstermiştir:
* **SacreBLEU:** `0.1129`
* **ROUGE-L:** `0.2852`
* **ROUGE-1:** `0.3486`
* **METEOR:** `0.2978`
Bu metrikler, modelin Türkçe altyazı üretme yeteneğini önemli ölçüde kazandığını ve zero-shot performansına kıyasla büyük bir gelişme kaydettiğini göstermektedir. Özellikle kısıtlı veri ve donanım kaynakları göz önüne alındığında, bu sonuçlar Türkçe VLM alanında umut verici bir başlangıç noktası sunmaktadır.
## Kullanım (Örnek)
Bu fine tuning yapılmış model, Hugging Face Hub'dan doğrudan yüklenebilir ve Türkçe görüntü altyazıları üretmek için kullanılabilir:
```python
from transformers import BlipProcessor, BlipForConditionalGeneration
from PIL import Image
import torch
# 1. Modelinizi ve İşlemcinizi Hugging Face Hub'dan Yükleyin
MODEL_ID = "ogulcanakca/blip-base-turkish-image-captioning" # modelimizin Hub ID'si
try:
processor = BlipProcessor.from_pretrained(MODEL_ID)
model = BlipForConditionalGeneration.from_pretrained(MODEL_ID)
print(f"'{MODEL_ID}' başarıyla yüklendi.")
except Exception as e:
print(f"Hata: Model veya Processor yüklenemedi: {e}")
raise
model.eval()
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
print(f"Model '{device}' cihazına taşındı ve değerlendirme modunda.")
# 2. Altyazı Üretmek İstediğiniz Görüntüyü Yükleyin
image_path = "path/to/your/image.jpg" # <<< KENDİ GÖRÜNTÜNÜZÜN YOLUNU GİRİN
try:
image_pil = Image.open(image_path).convert("RGB")
print(f"'{image_path}' başarıyla yüklendi.")
except FileNotFoundError:
print(f"HATA: Görüntü '{image_path}' bulunamadı.")
exit()
# 3. Görüntüyü İşleyin ve Altyazı Üretin
# BLIP altyazılama modelleri genellikle text prompt'a ihtiyaç duymaz.
inputs = processor(images=image_pil, return_tensors="pt").to(device, model.dtype) # model.dtype ile aynı hassasiyette
print("\nModel ile altyazı üretiliyor...")
with torch.no_grad():
generated_ids = model.generate(
**inputs,
max_length=70, # Eğitimdeki TEXT_MAX_LENGTH ile uyumlu veya istediğiniz bir değer
# num_beams=3, # İsteğe bağlı: Daha kaliteli ama yavaş üretim için
# early_stopping=True # num_beams > 1 ise
)
generated_caption = processor.decode(generated_ids[0], skip_special_tokens=True)
print("\nÜretilen Türkçe Altyazı:")
print(generated_caption)
# Görüntüyü göstermek için (isteğe bağlı):
# import matplotlib.pyplot as plt
# plt.imshow(image_pil)
# plt.title(generated_caption)
# plt.axis('off')
# plt.show()
```
## Eğitim Hiperparametreleri (Örnek)
* Base Model: Salesforce/blip-image-captioning-base
* Learning Rate: 2e-5
* Training Epochs: 3
* Training Batch Size per Device: 4
* Evaluation Batch Size per Device: 1
* Gradient Accumulation Steps: 4 (Effective batch size: 16)
* Warmup Ratio: 0.1
* Weight Decay: 0.01
* Optimizer: AdamW (adamw_torch)
* Mixed Precision: FP16
* Maximum Text Length (Training): 70
* This approach was taken in anticipation that it would become disconnected from context as the length increased.
## Ortam Bilgileri ve Süreler
* Model Boyutu: Salesforce/blip-image-captioning-base (~990MB pytorch_model.bin olarak)
* Veri Kümesi: ituperceptron/image-captioning-turkish (long_captions split'inden 60.000 örnek)
* GPU: NVIDIA P100 (Kaggle üzerinde)
* Toplam Eğitim Süresi (3 epoch için): 6:57:27.93
* Saniyede eğitilen örnek sayısı: 7.186
* Saniyede atılan eğitim adımı: 0.449
* Çıkarım Hızı: Yaklaşık 5 örnek/saniye (Trainer.predict() ile test seti üzerinde (NVIDIA P100))
### CITATION
```
@misc{ogulcanakca_blip_turkish_captioning_2025,
author = {Oğulcan Akca},
title = {Fine-tuned BLIP-Base for Turkish Image Captioning},
year = {2025},
publisher = {Hugging Face},
journal = {Hugging Face Model Hub},
howpublished = {{[https://huggingface.co/ogulcanakca/blip-base-turkish-image-captioning](https://huggingface.co/ogulcanakca/blip-base-turkish-image-captioning)}}
}
```
* BLIP:
```
@inproceedings{li2022blip,
title={BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation},
author={Li, Junnan and Li, Dongxu and Xiong, Caiming and Hoi, Steven},
booktitle={International Conference on Machine Learning (ICML)},
year={2022}
}
```
## Notebook'lar
* [blip-turkish-image-captioning-0shot noteobok'u](https://www.kaggle.com/code/oulcanakca/blip-turkish-image-captioning-0shot)
* [blip-turkish-image-captioning-fine-tune notebook'u](https://www.kaggle.com/code/oulcanakca/blip-turkish-image-captioning-fine-tune)
* [blip-turkish-image-captioning-test notebook'u](https://www.kaggle.com/code/oulcanakca/blip-turkish-image-captioning-test)
* [blip-turkish-image-captioning-inference notebook'u](https://www.kaggle.com/code/oulcanakca/blip-turkish-image-captioning-inference)
|