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