# shitagaki-lab/see-through architecture

> Architecture diagram of the GitHub repository shitagaki-lab/see-through, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shitagaki-lab/see-through
- Repository: https://github.com/shitagaki-lab/see-through

## Overview

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/scripts/inference_psd.py`](https://github.com/shitagaki-lab/see-through/blob/main/inference/scripts/inference_psd.py) (PSD pipeline), [`ui/ui/mainwindow.py`](https://github.com/shitagaki-lab/see-through/blob/main/ui/ui/mainwindow.py) (Desktop UI), [`inference/scripts/heuristic_partseg.py`](https://github.com/shitagaki-lab/see-through/blob/main/inference/scripts/heuristic_partseg.py) (Layer split), [`common/modules/sam`](https://github.com/shitagaki-lab/see-through/tree/main/common/modules/sam) (SAM stack)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Inference"]
  node_inputs["Image input<br/>file source"]
  node_inference_psd["PSD pipeline<br/>orchestrator<br/>[inference_psd.py]"]
  node_layer_split["Layer split<br/>decomposition"]
  node_psd_export["PSD export<br/>output writer"]
  node_infer_sam["SAM infer<br/>segmentation script<br/>[infer_sam.py]"]
  node_infer_lama["LaMa infer<br/>inpaint script<br/>[infer_lama.py]"]
end

subgraph group_annotators["Annotators"]
  node_lang_sam[("Lang-SAM<br/>grounded segmentation")]
  node_anime_face["Anime face<br/>face detector"]
  node_animeinsseg[("Anime instance seg<br/>instance segmentation")]
  node_taggers["Taggers<br/>classification<br/>[wdv3_tagger.py]"]
  node_lama_inpainter[("LaMa inpainter<br/>inpainting")]
end

subgraph group_common["Common"]
  node_layerdiffuse[("LayerDiffuse<br/>generative layers")]
  node_marigold[("Marigold depth<br/>depth pipeline")]
  node_sam_stack[("SAM stack<br/>masking subsystem")]
  node_semantic_sam["Semantic SAM<br/>mask adapter<br/>[semanticsam.py]"]
  node_depth_anything[("Depth Anything<br/>depth backbone")]
  node_shared_utils["Shared utils<br/>utility layer"]
  node_assets["Assets<br/>metadata/resources"]
  node_live2d["Live2D<br/>data tooling"]
end

subgraph group_ui["UI"]
  node_workspace["Workspace<br/>artifact store"]
  node_qt_ui["Desktop UI<br/>qt app<br/>[mainwindow.py]"]
  node_ui_widgets["UI widgets<br/>controls<br/>[canvas.py]"]
end

node_inputs -->|"load"| node_inference_psd
node_inference_psd -->|"segment"| node_sam_stack
node_inference_psd -->|"ground"| node_lang_sam
node_inference_psd -->|"detect"| node_anime_face
node_inference_psd -->|"refine"| node_animeinsseg
node_inference_psd -->|"depth"| node_marigold
node_inference_psd -->|"generate"| node_layerdiffuse
node_inference_psd -->|"label"| node_taggers
node_inference_psd -->|"compose"| node_layer_split
node_layer_split -->|"fill"| node_lama_inpainter
node_layer_split -->|"export"| node_psd_export
node_infer_sam -->|"uses"| node_sam_stack
node_infer_lama -->|"uses"| node_lama_inpainter
node_semantic_sam -.->|"extends"| node_sam_stack
node_animeinsseg -.->|"optionally uses"| node_depth_anything
node_qt_ui -->|"reads"| node_workspace
node_qt_ui -->|"builds"| node_ui_widgets
node_qt_ui -->|"depends on"| node_shared_utils
node_qt_ui -->|"skins"| node_assets
node_live2d -.->|"uses"| node_shared_utils

click node_inference_psd "https://github.com/shitagaki-lab/see-through/blob/main/inference/scripts/inference_psd.py"
click node_layer_split "https://github.com/shitagaki-lab/see-through/blob/main/inference/scripts/heuristic_partseg.py"
click node_infer_sam "https://github.com/shitagaki-lab/see-through/blob/main/inference/scripts/infer_sam.py"
click node_infer_lama "https://github.com/shitagaki-lab/see-through/blob/main/inference/scripts/infer_lama.py"
click node_layerdiffuse "https://github.com/shitagaki-lab/see-through/tree/main/common/modules/layerdiffuse"
click node_marigold "https://github.com/shitagaki-lab/see-through/tree/main/common/modules/marigold"
click node_sam_stack "https://github.com/shitagaki-lab/see-through/tree/main/common/modules/sam"
click node_semantic_sam "https://github.com/shitagaki-lab/see-through/blob/main/common/modules/semanticsam.py"
click node_depth_anything "https://github.com/shitagaki-lab/see-through/tree/main/common/modules/depth_anything_v2"
click node_lang_sam "https://github.com/shitagaki-lab/see-through/tree/main/annotators/lang_sam"
click node_anime_face "https://github.com/shitagaki-lab/see-through/tree/main/annotators/anime_face_detector"
click node_animeinsseg "https://github.com/shitagaki-lab/see-through/tree/main/annotators/animeinsseg"
click node_taggers "https://github.com/shitagaki-lab/see-through/blob/main/annotators/wdv3_tagger.py"
click node_lama_inpainter "https://github.com/shitagaki-lab/see-through/tree/main/annotators/lama_inpainter"
click node_shared_utils "https://github.com/shitagaki-lab/see-through/tree/main/common/utils"
click node_assets "https://github.com/shitagaki-lab/see-through/tree/main/common/assets"
click node_live2d "https://github.com/shitagaki-lab/see-through/tree/main/common/live2d"
click node_workspace "https://github.com/shitagaki-lab/see-through/tree/main/ui/ui"
click node_qt_ui "https://github.com/shitagaki-lab/see-through/blob/main/ui/ui/mainwindow.py"
click node_ui_widgets "https://github.com/shitagaki-lab/see-through/blob/main/ui/ui/canvas.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_inputs,node_inference_psd,node_layer_split,node_psd_export,node_infer_sam,node_infer_lama toneBlue
class node_lang_sam,node_anime_face,node_animeinsseg,node_taggers,node_lama_inpainter toneAmber
class node_layerdiffuse,node_marigold,node_sam_stack,node_semantic_sam,node_depth_anything,node_shared_utils,node_assets,node_live2d toneMint
class node_workspace,node_qt_ui,node_ui_widgets toneRose
```

## Components

### Inference

Offline decomposition, PSD export, and related batch scripts.

- **Image input**: file source · Single images or directories passed into offline inference.
- [PSD pipeline](https://github.com/shitagaki-lab/see-through/blob/main/inference/scripts/inference_psd.py): orchestrator · Main end-to-end script that runs perception, decomposition, and export. · `inference/scripts/inference_psd.py`
- [Layer split](https://github.com/shitagaki-lab/see-through/blob/main/inference/scripts/heuristic_partseg.py): decomposition · Combines semantic masks, depth, and heuristics into ordered layers. · `inference/scripts/heuristic_partseg.py`
- **PSD export**: output writer · Writes layered PSDs and intermediate artifacts to workspace storage.
- [SAM infer](https://github.com/shitagaki-lab/see-through/blob/main/inference/scripts/infer_sam.py): segmentation script · Standalone SAM-based inference entrypoint. · `inference/scripts/infer_sam.py`
- [LaMa infer](https://github.com/shitagaki-lab/see-through/blob/main/inference/scripts/infer_lama.py): inpaint script · Standalone inpainting entrypoint for completion/refinement. · `inference/scripts/infer_lama.py`

### Annotators

Domain-specific perception, tagging, segmentation, and inpainting modules.

- [Lang-SAM](https://github.com/shitagaki-lab/see-through/tree/main/annotators/lang_sam): grounded segmentation · Language-guided segmentation via Grounding DINO plus SAM. · `annotators/lang_sam`
- [Anime face](https://github.com/shitagaki-lab/see-through/tree/main/annotators/anime_face_detector): face detector · Face detection and landmark-related anime perception. · `annotators/anime_face_detector`
- [Anime instance seg](https://github.com/shitagaki-lab/see-through/tree/main/annotators/animeinsseg): instance segmentation · Anime-focused instance segmentation and refinement models. · `annotators/animeinsseg`
- [Taggers](https://github.com/shitagaki-lab/see-through/blob/main/annotators/wdv3_tagger.py): classification · Attribute and body-part tagging helpers for anime content. · `annotators/wdv3_tagger.py`
- [LaMa inpainter](https://github.com/shitagaki-lab/see-through/tree/main/annotators/lama_inpainter): inpainting · Region completion subsystem used after mask removal. · `annotators/lama_inpainter`

### Common

Shared model backbones, utilities, assets, and Live2D helpers.

- [LayerDiffuse](https://github.com/shitagaki-lab/see-through/tree/main/common/modules/layerdiffuse): generative layers · Transparent layer generation and 3D-aware layer diffusion models. · `common/modules/layerdiffuse`
- [Marigold depth](https://github.com/shitagaki-lab/see-through/tree/main/common/modules/marigold): depth pipeline · Pseudo-depth estimation used by the PSD workflow. · `common/modules/marigold`
- [SAM stack](https://github.com/shitagaki-lab/see-through/tree/main/common/modules/sam): masking subsystem · Automatic mask generation and promptable SAM segmentation. · `common/modules/sam`
- [Semantic SAM](https://github.com/shitagaki-lab/see-through/blob/main/common/modules/semanticsam.py): mask adapter · Glue code that extends SAM with semantic region handling. · `common/modules/semanticsam.py`
- [Depth Anything](https://github.com/shitagaki-lab/see-through/tree/main/common/modules/depth_anything_v2): depth backbone · General-purpose depth model family used as a reusable perception backbone. · `common/modules/depth_anything_v2`
- [Shared utils](https://github.com/shitagaki-lab/see-through/tree/main/common/utils): utility layer · Cross-cutting I/O, image, torch, and visualization helpers. · `common/utils`
- [Assets](https://github.com/shitagaki-lab/see-through/tree/main/common/assets): metadata/resources · Shared tags, icons, and model metadata used across tools. · `common/assets`
- [Live2D](https://github.com/shitagaki-lab/see-through/tree/main/common/live2d): data tooling · Inspection and visualization helpers for Live2D-related data. · `common/live2d`

### UI

Qt desktop application for inspection and workspace interaction.

- [Workspace](https://github.com/shitagaki-lab/see-through/tree/main/ui/ui): artifact store · Local output directory for datasets, previews, and generated PSD artifacts. · `ui/ui`
- [Desktop UI](https://github.com/shitagaki-lab/see-through/blob/main/ui/ui/mainwindow.py): qt app · Qt-based application for browsing, inspecting, and driving workspace assets. · `ui/ui/mainwindow.py`
- [UI widgets](https://github.com/shitagaki-lab/see-through/blob/main/ui/ui/canvas.py): controls · Canvas, widgets, threading, and interaction components for the desktop app. · `ui/ui/canvas.py`

## Connections

- 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.
