Downloads · 30 days
0
DevilishDaoSaint/koharu-layout-rfdetr
koharu-layout-rfdetr is a object detection model from DevilishDaoSaint. Use it when you need objects located in an image. It is set up for onnxruntime. The card lists the license as other.
This repository provides an optimized ONNX Runtime export of KoharuLayout-RFDETR-2XL, configured for efficient execution in comic and manga translation pipelines, such as XianScan.
Downloads · 30 days
0
Access
Public
Updated Sep 11, 2026
Repo size
425 MB
Likes
0
Public
Click a slice to open those files.
.onnx136 MB · 100%
From the Hugging Face model README
This repository provides an optimized ONNX Runtime export of KoharuLayout-RFDETR-2XL, configured for efficient execution in comic and manga translation pipelines, such as XianScan.
The model is derived from the upstream reference checkpoint mayocream/koharu-layout-rfdetr-seg-2xl-1152 by mayocream. It localizes primary document layout elements across comic pages, specifically dialogue text, speech bubbles, sound effects, and comic panel boundaries.
To optimize for resource-constrained environments and local desktop runtimes, this export incorporates two structural modifications:
dets) and classification logits (labels), reducing inference latency by ~20% to 25% compared to the unpruned 768px model and ~4x compared to the 1152px baseline on CPU.The following table summarizes the structural and operational differences between the upstream reference checkpoint and this optimized export:
| Specification | Upstream Reference (mayocream) | Optimized Runtime Export (DevilishDaoSaint) |
|---|---|---|
| Repository | mayocream/koharu-layout-rfdetr-seg-2xl-1152 | DevilishDaoSaint/koharu-layout-rfdetr |
| Model Format | PyTorch SafeTensors (model.safetensors) | Standalone ONNX (rfdetr-seg-2xlarge.onnx) |
| Execution Framework | PyTorch (rfdetr==1.7.0) | ONNX Runtime (onnxruntime C++ / Rust / Python) |
| Input Dimensions | 1152 x 1152 x 3 | 768 x 768 x 3 |
| Vision Backbone Patch Grid | 12x12 patch size, 9,217 tokens (96x96 grid + 1 CLS) | 12x12 patch size, 4,097 tokens (64x64 grid + 1 CLS) |
| Active Network Heads | Bounding Box, Classification, Instance Mask | Bounding Box, Classification |
| Computational Graph Nodes | 2,040 nodes | 1,923 nodes (117 mask nodes pruned) |
| Output Tensors | dets [1, 300, 4], labels [1, 300, 5], masks [1, 300, 192, 192] | dets [1, 300, 4], labels [1, 300, 5] |
| File Size (Decimal / Binary) | SafeTensors weights | 136.2 MB (129.9 MiB / 136,227,882 bytes) |
| Inference Latency Range | ~5.5s to 7.5s per page (x86_64 CPU) | ~1.4s to 1.9s per page (x86_64 CPU) |
| Target Runtime | GPU workstations and training clusters | Desktop endpoints, local CPU runtimes, embedded tools |
Depending on CPU architecture, clock frequencies, thermal limits, and available threads (typically 4 to 8 physical cores on consumer hardware), expected inference latency ranges are as follows:
| Model Variant | Resolution | Active Heads | Graph Nodes | Typical CPU Latency Range | Relative Speedup |
|---|---|---|---|---|---|
| Upstream Baseline | 1152 x 1152 | Boxes + Logits + Masks | 2,040 nodes | ~5.5s to 7.5s | 1.0x (Baseline) |
| Scaled (Unpruned) | 768 x 768 | Boxes + Logits + Masks | 2,040 nodes | ~1.8s to 2.5s | ~3x faster |
| This Export (Pruned) | 768 x 768 | Boxes + Logits only | 1,923 nodes | ~1.4s to 1.9s | ~4x faster |
(Empirical reference: on an 8-core / 16-thread AMD Ryzen 7 5700G, warm inference averages ~1.64s for the pruned model versus ~2.12s for the unpruned 768px model and ~6.82s for the 1152px baseline).
The model predicts 300 object queries mapped across four functional layout categories:
| Class ID | Class Name | Description | Suggested Threshold |
|---|---|---|---|
| 0 | text | Narrative prose, dialogue text, captions, and title typography | 0.25 |
| 1 | onomatopoeia | Comic sound effects and stylized non-dialogue typography (SFX) | 0.20 |
| 2 | bubble | Speech balloons, thought bubbles, and caption boxes | 0.50 |
| 3 | panel | Individual comic frames, borders, and panel dividers | 0.50 |
Note: The model is strictly a layout detection system. It does not perform optical character recognition (OCR) or predict semantic reading sequences.
inputfloat32[1, 3, 768, 768] (Batch, Channels, Height, Width)dets
float32[1, 300, 4][cx, cy, w, h] bounded within [0.0, 1.0]. Absolute pixel boundaries are recovered via:
$$x_1 = (cx - 0.5 \cdot w) \cdot W_{\text{orig}}, \quad y_1 = (cy - 0.5 \cdot h) \cdot H_{\text{orig}}$$
$$x_2 = (cx + 0.5 \cdot w) \cdot W_{\text{orig}}, \quad y_2 = (cy + 0.5 \cdot h) \cdot H_{\text{orig}}$$labels
float32[1, 300, 5][0: text, 1: onomatopoeia, 2: bubble, 3: panel, 4: background]. Probabilities are derived using the standard sigmoid function:
$$P(\text{class}_c) = \frac{1}{1 + e^{-\text{logit}_c}}$$import numpy as np
import onnxruntime as ort
from PIL import Image
# Initialize runtime session
session = ort.InferenceSession(
"rfdetr-seg-2xlarge.onnx",
providers=["CPUExecutionProvider"]
)
# Load and prepare image
image = Image.open("manga_page.webp").convert("RGB")
orig_w, orig_h = image.size
resized = image.resize((768, 768), Image.Resampling.BILINEAR)
# Normalize using ImageNet statistics
img_arr = np.array(resized, dtype=np.float32) / 255.0
mean = np.array([0.485, 0.456, 0.406], dtype=np.float32)
std = np.array([0.229, 0.224, 0.225], dtype=np.float32)
norm_arr = (img_arr - mean) / std
input_tensor = np.transpose(norm_arr, (2, 0, 1))[np.newaxis, ...]
# Execute inference
dets_out, labels_out = session.run(["dets", "labels"], {"input": input_tensor})
dets = dets_out[0] # shape: (300, 4)
labels = labels_out[0] # shape: (300, 5)
# Extract and filter candidate predictions
thresholds = {0: 0.25, 1: 0.20, 2: 0.50, 3: 0.50}
class_names = {0: "text", 1: "onomatopoeia", 2: "bubble", 3: "panel"}
results = []
for q in range(300):
cx, cy, bw, bh = dets[q]
x1 = float((cx - 0.5 * bw) * orig_w)
y1 = float((cy - 0.5 * bh) * orig_h)
x2 = float((cx + 0.5 * bw) * orig_w)
y2 = float((cy + 0.5 * bh) * orig_h)
for c in range(4):
confidence = float(1.0 / (1.0 + np.exp(-labels[q][c])))
if confidence >= thresholds[c]:
results.append({
"class": class_names[c],
"score": round(confidence, 3),
"bbox": [round(x1, 1), round(y1, 1), round(x2, 1), round(y2, 1)]
})
print(f"Localized {len(results)} layout elements.")
All credit for the original underlying model architecture, training, and supervision belongs to:
other license designation.