Downloads · 30 days
0
khanhromvn/manga_bubble_seg
manga_bubble_seg is a image segmentation model from khanhromvn. Use it for the image segmentation task on the model card, and read the license before you ship it in a product. It is set up for ultralytics. The card lists the license as agpl-3.0.
<div align="center" <img src="https://img.shields.io/badge/YOLO-v8m--seg-00FFFF?style=for-the-badge&logo=yolo&logoColor=white" alt="YOLOv8m-seg"/ <img src="https://img.shields.io/badge/License-MIT-green?style=for-the-…
Downloads · 30 days
0
Access
Public
Updated Nov 13, 2025
Repo size
327 MB
Likes
3
Public
Click a slice to open those files.
.onnx109 MB · 100%
From the Hugging Face model README
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:
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% |
Model phát hiện các loại bubble sau:
| 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 |
pip install ultralytics
pip install huggingface_hub
pip install opencv-python
pip install pillow
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")
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}")
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)
# 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
)
| 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.
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"
)
# 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
)
# 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
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
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
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
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
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)
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}},
}
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:
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: