Keras

DeepPanel: Comic Panel Extractor (Keras Model)

Model Card β€’ Hugging Face Repo β€’ Download .keras file


πŸ“– Overview

deeppanel_model.keras is a fully trained TensorFlow/Keras model for automatic comic panel extraction.

It takes a full comic book page (or any illustrated page) as input and outputs a binary mask that highlights every individual panel. The post-processing code then uses OpenCV to crop each detected panel into its own clean image.

This model was originally developed as DeepPanel and has been retrained/fine-tuned specifically for Western and manga-style comics.

What it does

  • Input: One comic page (JPG/PNG)
  • Output: Mask of panel regions β†’ cropped panel images
  • Works on any resolution (automatically resized internally to 256Γ—256 for inference, then scaled back)
  • Handles multi-panel pages, overlapping speech bubbles, and complex layouts

πŸ“¦ Model File

File Size Format Description
deeppanel_model.keras ~XX MB Keras v3 Full model (architecture + weights)

Direct download link:

https://huggingface.co/codeShare/comic-panel-extract/resolve/main/deeppanel_model.keras

πŸš€ Quick Start (Colab / Local)

1. Install dependencies

pip install tensorflow opencv-python-headless numpy tqdm huggingface_hub

2. Download + Load the model

from huggingface_hub import hf_hub_download
import tensorflow as tf

model_path = hf_hub_download(
    repo_id="codeShare/comic-panel-extract",
    filename="deeppanel_model.keras"
)

model = tf.keras.models.load_model(model_path)
print("βœ… DeepPanel model loaded!")

3. Full extraction pipeline (copy-paste ready)

See the exact code used in the original Colab notebook (link will be added once public).

Or use the minimal working example below:

import cv2
import numpy as np
from huggingface_hub import hf_hub_download
import tensorflow as tf
import os
from tqdm import tqdm

# Load model once
model_path = hf_hub_download(repo_id="codeShare/comic-panel-extract", filename="deeppanel_model.keras")
model = tf.keras.models.load_model(model_path)

def extract_panels_from_page(image_path, output_folder="panels"):
    os.makedirs(output_folder, exist_ok=True)
    
    # Preprocess
    img = cv2.imread(image_path)
    original_shape = img.shape[:2]
    resized = cv2.resize(cv2.cvtColor(img, cv2.COLOR_BGR2RGB), (256, 256)) / 255.0
    input_tensor = np.expand_dims(resized, axis=0).astype(np.float32)
    
    # Predict mask
    mask_pred = model.predict(input_tensor, verbose=0)[0]
    if len(mask_pred.shape) == 3 and mask_pred.shape[-1] == 1:
        mask_pred = mask_pred.squeeze(axis=-1)
    
    # Post-process
    mask = cv2.resize((mask_pred > 0.5).astype(np.uint8) * 255, (original_shape[1], original_shape[0]))
    contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    
    page_name = os.path.splitext(os.path.basename(image_path))[0]
    count = 0
    for contour in contours:
        x, y, w, h = cv2.boundingRect(contour)
        if w < 30 or h < 30:
            continue
        panel = img[y:y+h, x:x+w]
        cv2.imwrite(f"{output_folder}/{page_name}_panel_{count:02d}.jpg", panel)
        count += 1
    
    return count

# Example usage
panels_extracted = extract_panels_from_page("my_comic_page.jpg", "extracted_panels")
print(f"Extracted {panels_extracted} panels!")

πŸ“‚ Related Resources


🎯 Intended Use Cases

  • Bulk comic/manga digitization pipelines
  • Preparing training data for AI comic colorizers, inpainters, or speech bubble removers
  • Building web apps that auto-split comic pages into panels
  • Research on layout analysis for illustrated books

Works best on:

  • Clear black-and-white or color comics
  • Standard Western comic pages and Japanese manga

Limitations:

  • Very low-resolution or heavily compressed scans may give poorer results
  • Extremely artistic/experimental layouts (full-bleed splash pages) may need manual correction

πŸ› οΈ Technical Details

  • Framework: TensorFlow 2.x + Keras 3
  • Architecture: U-Net style (encoder-decoder) optimized for segmentation
  • Input size during inference: 256Γ—256 (automatically resized)
  • Output: Single-channel probability mask
  • License: MIT (model weights + code)

πŸ“œ Citation

If you use this model in your project, please cite:

@misc{deeppanel-comic-extractor-2026,
  title        = {DeepPanel: Comic Panel Extractor},
  author       = {codeShare},
  year         = {2026},
  howpublished = {\url{https://huggingface.co/codeShare/comic-panel-extract}},
  note         = {Keras model for automatic comic panel detection}
}
Downloads last month
102
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support