How shitagaki-lab/see-through works
1. Repository purpose and top-level split
This repo is a research-to-tooling stack for “See-through,” an anime-image layer decomposition system. It is organized into three main execution surfaces: offline inference pipelines, model/vision utility code, and a Qt-based desktop UI. A separate data-preparation workflow exists for training/inspection, but the main shipping path is inference that exports layered PSDs.
2. Core inference pipeline
The central orchestration lives in inference/scripts/inference_psd.py. It takes a single image or a directory of images, runs multiple vision models, then assembles a layered PSD plus intermediate artifacts. The pipeline is the main architecture boundary: everything else in the repo supports its image → semantic masks/depth → ordered layers → PSD output flow.
3. Layer decomposition stack
The decomposition stage is built around two major model families:
- LayerDiffuse / LayerDiff 3D under common/modules/layerdiffuse, which handles transparent layer generation.
- Marigold depth under common/modules/marigold, which provides pseudo-depth estimation.
These outputs are used together to stratify character parts into ordered layers. The README indicates the current model supports up to 23 semantic layers and uses a two-stage separation for head/body.
4. Segmentation and prompt-guided masking
The repo includes a substantial SAM/grounding segmentation subsystem under common/modules/sam, plus common/modules/semanticsam.py and common/modules/extend_sam.py. This is complemented by annotators/lang_sam, which couples Grounding DINO with SAM for language-guided segmentation. These modules are the masking/region-definition layer that feeds decomposition, inpainting, and UI preview.
5. Anime-specific annotators
The annotators/ package contains domain-specific helpers that enrich the pipeline with anime-focused structure:
- anime_face_detector for face detection and landmarks/pose-related detection.
- animeinsseg for anime instance segmentation.
- bizarre_tagger and wdv3_tagger.py for tagging/attribute classification.
- gradcam.py for visualization/diagnostics.
These are optional subsystems, but they materially affect the quality of segmentation and part labeling.
6. Inpainting and refinement
Occluded or removed regions are filled using the LaMa-based subsystem in annotators/lama_inpainter. This acts as the completion step after masks/layers are split. The repo also includes refinement-related model code in annotators/animeinsseg/animeseg_refine_model, suggesting a quality-improvement boundary between raw segmentation and final clean layer output.
7. Depth and auxiliary perception modules
common/modules/depth_anything_v2 and common/modules/marigold both provide depth-related capabilities, but for different roles: one appears to be a general depth backbone family, while Marigold is the specialized pseudo-depth pipeline used by the main PSD workflow. These modules are reusable perception backbones rather than app logic.
8. PSD / layered asset output
The output boundary is PSD generation plus artifacts saved under a workspace directory. The main script writes layered PSD files and also emits intermediate depth maps and masks. This makes the system a local offline batch processor rather than a network service: inputs come from files, outputs go to disk, and later tools can inspect or further split the PSD.
9. Data preparation and heuristic post-processing
The inference/scripts/ folder also contains data-oriented utilities such as syn_data.py, parse_live2d.py, heuristic_partseg.py, and inference variants for SAM or LaMa. This indicates a second workflow: generating synthetic training data and doing heuristic refinements like depth-based or left-right layer splitting after the main decomposition.
10. UI subsystem
ui/ui is a standalone desktop application layer built with Qt. It has its own widgets, canvas, threading helpers, theming, and platform-specific frameless window support for Linux/macOS/Windows. The UI depends on the repository’s workspace layout, especially workspace/datasets/, and is designed to visualize/inspect data and likely drive the same decomposition assets produced by the inference pipeline.
11. Shared foundations
common/utils contains cross-cutting utilities for I/O, visualization, torch helpers, sampling, image/cv handling, and packaging. common/assets stores shared metadata and UI resources such as body tags and icon/theme assets. These are not core algorithms, but they are important boundaries because they define consistent data formats, visual conventions, and runtime helpers across inference, UI, and data prep.
12. Runtime and dependency boundaries
The repo is Python-first and PyTorch-centric, with optional heavy dependencies for specific tiers: detectron2, mmcv/mmdet, and SAM2 for enhanced annotators/segmentation, plus bitsandbytes for quantized low-VRAM inference. HuggingFace model downloads are part of the deployment model, so the architecture depends on external model repos as runtime assets rather than checked-in weights.
13. How to draw the diagram
A useful architecture diagram would show:
- File input on the left.
- Main inference orchestrator in the center.
- Parallel model blocks for LayerDiffuse, Marigold depth, SAM/Grounding DINO, anime annotators, and LaMa.
- A merge step that produces ordered semantic layers.
- PSD/export and workspace artifacts on the right.
- A separate UI branch reading the workspace and datasets.
- Shared utilities/assets as a foundation layer underneath all components.
Main entry points: inference_psd.py PSD pipeline · mainwindow.py Desktop UI · heuristic_partseg.py Layer split · sam SAM stack
Components 22
Inference
Offline decomposition, PSD export, and related batch scripts.
- Image input · Single images or directories passed into offline inference.
- PSD pipeline · Main end-to-end script that runs perception, decomposition, and export.
inference/scripts/inference_psd.py - Layer split · Combines semantic masks, depth, and heuristics into ordered layers.
inference/scripts/heuristic_partseg.py - PSD export · Writes layered PSDs and intermediate artifacts to workspace storage.
- SAM infer · Standalone SAM-based inference entrypoint.
inference/scripts/infer_sam.py - LaMa infer · Standalone inpainting entrypoint for completion/refinement.
inference/scripts/infer_lama.py
Annotators
Domain-specific perception, tagging, segmentation, and inpainting modules.
- Lang-SAM · Language-guided segmentation via Grounding DINO plus SAM.
annotators/lang_sam - Anime face · Face detection and landmark-related anime perception.
annotators/anime_face_detector - Anime instance seg · Anime-focused instance segmentation and refinement models.
annotators/animeinsseg - Taggers · Attribute and body-part tagging helpers for anime content.
annotators/wdv3_tagger.py - LaMa inpainter · Region completion subsystem used after mask removal.
annotators/lama_inpainter
Common
Shared model backbones, utilities, assets, and Live2D helpers.
- LayerDiffuse · Transparent layer generation and 3D-aware layer diffusion models.
common/modules/layerdiffuse - Marigold depth · Pseudo-depth estimation used by the PSD workflow.
common/modules/marigold - SAM stack · Automatic mask generation and promptable SAM segmentation.
common/modules/sam - Semantic SAM · Glue code that extends SAM with semantic region handling.
common/modules/semanticsam.py - Depth Anything · General-purpose depth model family used as a reusable perception backbone.
common/modules/depth_anything_v2 - Shared utils · Cross-cutting I/O, image, torch, and visualization helpers.
common/utils - Assets · Shared tags, icons, and model metadata used across tools.
common/assets - Live2D · Inspection and visualization helpers for Live2D-related data.
common/live2d
UI
Qt desktop application for inspection and workspace interaction.
- Workspace · Local output directory for datasets, previews, and generated PSD artifacts.
ui/ui - Desktop UI · Qt-based application for browsing, inspecting, and driving workspace assets.
ui/ui/mainwindow.py - UI widgets · Canvas, widgets, threading, and interaction components for the desktop app.
ui/ui/canvas.py
Connections 20
- Image input → PSD pipeline: load · Inputs are consumed by the main offline pipeline.
- PSD pipeline → SAM stack: segment · Builds masks and regions for decomposition.
- PSD pipeline → Lang-SAM: ground · Uses language-guided segmentation when prompts are available.
- PSD pipeline → Anime face: detect · Finds faces and landmarks for anime-specific structure.
- PSD pipeline → Anime instance seg: refine · Applies anime instance segmentation for part-level structure.
- PSD pipeline → Marigold depth: depth · Estimates pseudo-depth for ordering and stratification.
- PSD pipeline → LayerDiffuse: generate · Produces transparent layer candidates from the image.
- PSD pipeline → Taggers: label · Annotates content with tags and body-part semantics.
- PSD pipeline → Layer split: compose · Combines perception outputs into ordered layers.
- Layer split → LaMa inpainter: fill · Inpaints occluded or removed regions.
- Layer split → PSD export: export · Writes the final layered PSD and artifacts.
- SAM infer → SAM stack: uses · Standalone segmentation entrypoint.
- LaMa infer → LaMa inpainter: uses · Standalone inpainting entrypoint.
- Semantic SAM → SAM stack: extends · Adds semantic handling on top of SAM primitives.
- Anime instance seg → Depth Anything: optionally uses · Can leverage depth-related perception backbones in refinement paths.
- Desktop UI → Workspace: reads · UI inspects generated datasets and artifacts from disk.
- Desktop UI → UI widgets: builds · Main window is assembled from reusable widgets and canvas components.
- Desktop UI → Shared utils: depends on · Shares common I/O and visualization helpers.
- Desktop UI → Assets: skins · Uses shared icons, themes, and metadata.
- Live2D → Shared utils: uses · Live2D tooling relies on shared data and visualization helpers.