|
|
--- |
|
|
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) |
|
|
|