Manga Bubble Segmentation Model

YOLOv8m-seg MIT License 5K Images 640x640

📋 Mô Tả Model

Manga Bubble Segmentation là mô hình phân đoạn chuyên biệt dựa trên YOLOv8m-seg architecture, được huấn luyện để phát hiện và phân đoạn các bong bóng hội thoại (speech bubbles) trong truyện tranh manga. Model có khả năng nhận diện chính xác vùng text trong các loại bubble khác nhau, phục vụ cho các ứng dụng:

  • 📚 Manga Translation - Tự động hóa quy trình dịch truyện
  • 🎨 Content Editing - Chỉnh sửa và làm sạch bubble
  • 🔍 Text Extraction - Trích xuất text từ manga
  • 🤖 OCR Pipeline - Tiền xử lý cho nhận diện chữ
  • 📖 Digital Comic Processing - Xử lý truyện tranh số

🎯 Tính Năng Chính

  • Phân đoạn chính xác các speech bubble trong manga
  • YOLOv8m-seg architecture - Cân bằng tốc độ & độ chính xác
  • 640x640 resolution - Tối ưu cho manga pages
  • 5,000 ảnh huấn luyện - Dataset đa dạng
  • 100 epochs - Model đã hội tụ hoàn toàn
  • Pretrained weights - Sẵn sàng sử dụng
  • MIT License - Miễn phí cho mục đích thương mại

📊 Thông Tin Dataset

Dataset: khanhromvn/manga_bubble_dataset

Split Số Ảnh Tỷ Lệ
Train 4,500 90.0%
Validation 350 7.0%
Test 150 3.0%
Tổng 5,000 100%

Đặc Điểm Dataset

  • 📖 5,000 trang manga chất lượng cao
  • 💬 Text bubbles với các kiểu dáng đa dạng
  • 🎭 Nhiều thể loại manga (shonen, shoujo, seinen, etc.)
  • 📝 Text tiếng Nhật trong các bubble
  • 🎨 Nhiều phong cách vẽ khác nhau

🏷️ Classes

Model phát hiện các loại bubble sau:

  • Speech Bubble - Bong bóng hội thoại thông thường
  • Thought Bubble - Bong bóng suy nghĩ
  • Narration Box - Hộp tường thuật
  • Sound Effect - Hiệu ứng âm thanh (có thể)

⚙️ Cấu Hình Huấn Luyện

Tham Số Giá Trị
Architecture YOLOv8m-seg
Pretrained Yes
Epochs 100
Image Size 640x640
Batch Size Auto (-1)
Workers 4
Save Period 10 epochs
Device Auto (GPU/CPU)
Optimizer AdamW

🚀 Hướng Dẫn Sử Dụng

Cài Đặt

pip install ultralytics
pip install huggingface_hub
pip install opencv-python
pip install pillow

Inference Cơ Bản

from ultralytics import YOLO
from huggingface_hub import hf_hub_download

# Tải model từ Hugging Face
model_path = hf_hub_download(
    repo_id="khanhromvn/manga_bubble_seg",
    filename="best.pt"
)

# Load model
model = YOLO(model_path)

# Chạy inference trên ảnh manga
results = model("manga_page.jpg")

# Hiển thị kết quả
results[0].show()

# Lưu kết quả
results[0].save("output_segmented.jpg")

Xử Lý Nhiều Trang Manga

import os
from pathlib import Path

# Đường dẫn folder chứa manga
manga_folder = "manga_chapter_01"
output_folder = "segmented_output"

# Tạo folder output
os.makedirs(output_folder, exist_ok=True)

# Xử lý tất cả ảnh
image_files = list(Path(manga_folder).glob("*.jpg")) + \
              list(Path(manga_folder).glob("*.png"))

for img_path in image_files:
    results = model(str(img_path))
    output_path = os.path.join(output_folder, img_path.name)
    results[0].save(output_path)
    print(f"Đã xử lý: {img_path.name}")

Trích Xuất Masks của Bubble

import numpy as np
import cv2

# Chạy inference
results = model("manga_page.jpg")

# Lấy masks
masks = results[0].masks.data.cpu().numpy()  # Shape: (N, H, W)
boxes = results[0].boxes.data.cpu().numpy()  # Bounding boxes
classes = results[0].boxes.cls.cpu().numpy()  # Class IDs

# Xử lý từng bubble
for i, mask in enumerate(masks):
    # Resize mask về kích thước ảnh gốc
    mask_resized = cv2.resize(mask, (original_width, original_height))
    
    # Tạo mask binary
    mask_binary = (mask_resized > 0.5).astype(np.uint8) * 255
    
    # Lưu mask
    cv2.imwrite(f"bubble_mask_{i}.png", mask_binary)
    
    # Crop vùng bubble từ ảnh gốc
    x1, y1, x2, y2 = boxes[i][:4].astype(int)
    bubble_crop = original_image[y1:y2, x1:x2]
    cv2.imwrite(f"bubble_crop_{i}.png", bubble_crop)

Tham Số Inference Nâng Cao

# Tùy chỉnh tham số inference
results = model.predict(
    source="manga_page.jpg",
    conf=0.25,        # Ngưỡng confidence (giảm để detect nhiều hơn)
    iou=0.7,          # IoU threshold cho NMS
    imgsz=640,        # Kích thước ảnh input
    device="cuda:0",  # Sử dụng GPU
    save=True,        # Tự động lưu kết quả
    show_labels=True, # Hiển thị nhãn class
    show_conf=True,   # Hiển thị confidence score
    augment=False,    # Test-time augmentation
    agnostic_nms=False # Class-agnostic NMS
)

📈 Kết Quả Đánh Giá

Metrics Chính

Metric Giá Trị
mAP50 TBD
mAP50-95 TBD
Precision TBD
Recall TBD
Inference Time (GPU) ~15ms/image
Inference Time (CPU) ~80ms/image

Lưu ý: Metrics chi tiết sẽ được cập nhật sau khi đánh giá đầy đủ trên test set.

Khả Năng của Model

  • ✅ Phát hiện chính xác bubble trong manga đen trắng
  • ✅ Xử lý được nhiều phong cách vẽ khác nhau
  • ✅ Hoạt động tốt với bubble có text dày đặc
  • ✅ Phân đoạn chính xác ranh giới bubble
  • ✅ Inference thời gian thực

🎓 Huấn Luyện Model

Train từ Đầu

from ultralytics import YOLO

# Load pretrained YOLOv8m-seg
model = YOLO("yolov8m-seg.pt")

# Train trên manga dataset
results = model.train(
    data="manga_bubble.yaml",
    epochs=100,
    imgsz=640,
    batch=-1,        # Auto batch size
    workers=4,       # Số worker threads
    save_period=10,  # Lưu checkpoint mỗi 10 epochs
    device="auto",   # Auto detect GPU/CPU
    project="manga_training",
    name="bubble_seg_v1"
)

Fine-tuning Model

# Load model này để fine-tune
model = YOLO("khanhromvn/manga_bubble_seg")

# Fine-tune trên dataset riêng
results = model.train(
    data="your_manga_dataset.yaml",
    epochs=50,
    imgsz=640,
    batch=-1,
    workers=4
)

Cấu Hình Dataset (manga_bubble.yaml)

# Dataset paths
path: ./manga_dataset
train: images/train
val: images/val
test: images/test

# Classes
names:
  0: speech_bubble
  1: thought_bubble
  2: narration_box
  3: sound_effect

📁 Cấu Trúc File Model

manga_bubble_seg/
├── best.pt              # Weights tốt nhất
├── last.pt              # Weights epoch cuối
├── weights/             # Checkpoints (epoch 10, 20, 30...)
│   ├── epoch10.pt
│   ├── epoch20.pt
│   └── ...
├── config.yaml          # Cấu hình training
└── README.md            # File này

🔧 Yêu Cầu Hệ Thống

ultralytics>=8.0.0
torch>=2.0.0
torchvision>=0.15.0
opencv-python>=4.8.0
numpy>=1.23.0
Pillow>=9.5.0
huggingface_hub>=0.16.0

💡 Use Cases

1. Pipeline Dịch Manga Tự Động

from ultralytics import YOLO
import easyocr

# Load models
bubble_model = YOLO("khanhromvn/manga_bubble_seg")
reader = easyocr.Reader(['ja', 'en'])

def process_manga_page(image_path):
    # 1. Phát hiện bubbles
    results = bubble_model(image_path)
    
    # 2. Trích xuất text từ mỗi bubble
    for i, mask in enumerate(results[0].masks.data):
        bubble_region = extract_bubble(mask)
        
        # 3. OCR
        text = reader.readtext(bubble_region)
        
        # 4. Dịch text (sử dụng translation API)
        translated = translate(text, target='vi')
        
        # 5. Vẽ text đã dịch lên bubble
        draw_text_on_bubble(bubble_region, translated)
    
    return processed_image

2. Làm Sạch Bubble (Text Removal)

import cv2
import numpy as np

def clean_bubble(image, model):
    results = model(image)
    
    for mask in results[0].masks.data:
        # Tạo mask binary
        mask_np = mask.cpu().numpy()
        
        # Inpainting để xóa text
        cleaned = cv2.inpaint(
            image, 
            mask_np.astype(np.uint8), 
            inpaintRadius=3,
            flags=cv2.INPAINT_TELEA
        )
    
    return cleaned

3. Text Extraction cho OCR Training

def extract_text_regions(manga_folder, output_folder):
    model = YOLO("khanhromvn/manga_bubble_seg")
    
    for img_path in Path(manga_folder).glob("*.jpg"):
        results = model(str(img_path))
        image = cv2.imread(str(img_path))
        
        for i, box in enumerate(results[0].boxes.data):
            x1, y1, x2, y2 = box[:4].int().tolist()
            
            # Crop bubble region
            bubble = image[y1:y2, x1:x2]
            
            # Lưu cho OCR training
            output_path = f"{output_folder}/{img_path.stem}_bubble_{i}.jpg"
            cv2.imwrite(output_path, bubble)

📝 Citation

Nếu bạn sử dụng model này trong nghiên cứu hoặc dự án, vui lòng trích dẫn:

@misc{manga-bubble-seg,
  author = {khanhromvn},
  title = {Manga Bubble Segmentation Model},
  year = {2024},
  publisher = {Hugging Face},
  howpublished = {\url{https://huggingface.co/khanhromvn/manga_bubble_seg}},
}

🤝 Đóng Góp

Rất hoan nghênh mọi đóng góp! Nếu bạn phát hiện lỗi hoặc có đề xuất:

  1. Mở issue trên repository
  2. Submit pull request với cải tiến
  3. Chia sẻ kết quả và use cases của bạn

📧 Liên Hệ

📜 License

Model này được phát hành dưới MIT License. Xem file LICENSE để biết chi tiết.

Bạn có quyền:

  • ✅ Sử dụng thương mại
  • ✅ Chỉnh sửa
  • ✅ Phân phối
  • ✅ Sử dụng riêng tư

🙏 Cảm Ơn

  • Ultralytics vì framework YOLOv8 tuyệt vời
  • Hugging Face vì nền tảng hosting model
  • Manga community vì sự hỗ trợ và phản hồi
  • Dataset contributors vì công sức chuẩn bị dữ liệu

🔍 Hạn Chế & Lưu Ý

  • Model hoạt động tốt nhất với manga đen trắng (không màu)
  • Độ chính xác có thể giảm với manga có nét vẽ phức tạp
  • Sound effects lớn và trang trí có thể không được phát hiện chính xác
  • Bubble chồng chéo nhiều có thể gây khó khăn cho segmentation

🎯 Roadmap

  • Hỗ trợ manga có màu
  • Phân loại chi tiết hơn (nhiều loại bubble)
  • Tăng kích thước dataset lên 10K+
  • Tối ưu hóa cho mobile deployment
  • Web demo cho inference trực tiếp

⭐ Nếu model này hữu ích cho bạn, hãy cho một star! ⭐
Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support