# jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen architecture

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

- Interactive diagram: https://gitdiagram.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen
- Repository: https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen

## Overview

1. **What this repository is**
   SegmentPose3D is a Python 3.8+ pipeline for multi-person 3D human pose estimation and SMPL mesh reconstruction from images. It is organized as a small core package plus scripts, with heavy lifting delegated to vendored third-party models.

2. **Top-level architecture**
   The repo is centered on `src/pose3d/`, which contains the orchestration logic and the domain-specific pipeline stages. `scripts/` provides entry points for single-image, batch, debug, and validation runs. `external/` contains third-party model implementations that are installed separately and treated as upstream dependencies.

3. **Primary data flow**
   The main flow is: input image → person detection → per-person segmentation → 3D SMPL pose/shape estimation → mesh export and visualization. The repository is built around processing multiple people independently and then optionally recombining them into a spatially consistent scene.

4. **Pipeline orchestration boundary**
   `src/pose3d/pipeline.py` is the central coordinator. It likely sequences the detector, segmentation module, SMPL estimator, and visualization/output steps, making it the best place to model the end-to-end runtime graph. This is the main architectural boundary between user-facing invocation and model-specific work.

5. **Person detection subsystem**
   `src/pose3d/person_detector.py` handles the first stage: locating all people in the image, typically via YOLO/Ultralytics as noted in the README. Its output is the set of person instances that downstream stages operate on, so it defines the per-person branching point in the pipeline.

6. **Segmentation subsystem**
   `src/pose3d/sam2_segmentation.py` performs instance segmentation using SAM2. This stage narrows each detection into a precise person mask, which helps isolate each human before pose estimation. Architecturally, it sits between coarse detection and 3D reconstruction.

7. **3D pose and mesh reconstruction**
   `src/pose3d/smpl_estimator.py` is the reconstruction stage and depends on the vendored HMR2/4D-Humans implementation under `external/4D-Humans`. It estimates SMPL parameters and produces per-person meshes, making this the computational core of the system.

8. **Spatial composition and visualization**
   The README indicates the pipeline preserves relative positions and can emit a combined “all people” mesh. That composition step is part of the output assembly stage, while `src/pose3d/viz.py` is responsible for generating 2D pose overlays and 3D renders for inspection.

9. **Configuration and device selection**
   `src/pose3d/config.py` and `src/pose3d/devices.py` define runtime settings and hardware behavior. The project is explicitly CPU-friendly, so device selection is an architectural concern rather than a minor implementation detail, especially for machines without CUDA.

10. **User-facing entry points**
   The `scripts/` directory exposes the pipeline in several modes: single image processing, folder/batch processing, debugging, and targeted tests for SAM2 and the full pipeline. `src/pose3d/app_gradio.py` suggests an optional interactive UI layer, distinct from the batch/CLI workflow.

11. **External dependency boundary**
   `external/sam2` and `external/4D-Humans` are embedded third-party codebases, not core application modules. The repository’s own code wraps these packages rather than reimplementing them, which is an important boundary when drawing the architecture diagram.

12. **Inputs, outputs, and storage**
   The `data/input/` folder is the canonical ingest location, and `data/outputs/` is the main artifact sink. Outputs are structured into meshes, 2D pose images, and 3D renders, with SMPL model files stored separately under `models/smpl/` due to licensing constraints.

13. **Operational characteristics**
   This is primarily an offline image-processing pipeline, not a networked service. Its architecture emphasizes local execution, repeatable processing, and artifact generation over request/response interaction.

Main entry points: [`src/pose3d/pipeline.py`](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/pipeline.py) (Pipeline), [`src/pose3d/sam2_segmentation.py`](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/sam2_segmentation.py) (SAM2 segmentation), [`src/pose3d/smpl_estimator.py`](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/smpl_estimator.py) (SMPL estimator), [`src/pose3d/config.py`](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/config.py) (Config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_src["Core package"]
  node_n_pipeline["Pipeline<br/>orchestrator<br/>[pipeline.py]"]
  node_n_detector["Person detector<br/>detection<br/>[person_detector.py]"]
  node_n_segmentation["SAM2 segmentation"]
  node_n_smpl["SMPL estimator<br/>reconstruction<br/>[smpl_estimator.py]"]
  node_n_viz["Visualization<br/>rendering<br/>[viz.py]"]
  node_n_config["Config<br/>settings<br/>[config.py]"]
  node_n_devices["Devices<br/>hardware<br/>[devices.py]"]
  node_n_ui["Gradio UI<br/>interactive-ui<br/>[app_gradio.py]"]
end

subgraph group_grp_scripts["Entry points"]
  node_n_run_demo["Demo run<br/>cli<br/>[run_demo.py]"]
  node_n_batch["Batch run<br/>cli<br/>[batch_process.py]"]
  node_n_debug["Debug projection<br/>debug-cli"]
  node_n_test_pipe["Pipeline test<br/>validation-cli<br/>[test_pipeline.py]"]
  node_n_test_sam2["SAM2 test<br/>validation-cli<br/>[test_sam2.py]"]
  node_n_print_sig["Signature print<br/>utility-cli<br/>[print_signature.py]"]
end

subgraph group_grp_external["Vendored deps"]
  node_n_4dh["4D-Humans<br/>vendor-model"]
  node_n_sam2["SAM2<br/>vendor-model"]
end

subgraph group_grp_artifacts["Data and models"]
  node_n_input[("Input data<br/>dataset")]
  node_n_outputs[("Outputs<br/>artifacts")]
  node_n_segmented[("Segmented data<br/>artifacts")]
  node_n_smpl_models[("SMPL models<br/>assets")]
end

node_n_run_demo -->|"starts"| node_n_pipeline
node_n_batch -->|"starts"| node_n_pipeline
node_n_debug -->|"starts"| node_n_pipeline
node_n_test_pipe -->|"checks"| node_n_pipeline
node_n_test_sam2 -->|"checks"| node_n_segmentation
node_n_pipeline -->|"calls"| node_n_detector
node_n_pipeline -->|"calls"| node_n_segmentation
node_n_pipeline -->|"calls"| node_n_smpl
node_n_pipeline -->|"calls"| node_n_viz
node_n_pipeline -->|"uses"| node_n_config
node_n_pipeline -->|"uses"| node_n_devices
node_n_pipeline -->|"reads"| node_n_input
node_n_pipeline -->|"writes"| node_n_outputs
node_n_segmentation -->|"depends on"| node_n_sam2
node_n_smpl -->|"depends on"| node_n_4dh
node_n_segmentation -->|"writes"| node_n_segmented
node_n_smpl -->|"loads"| node_n_smpl_models
node_n_ui -->|"drives"| node_n_pipeline
node_n_print_sig -->|"inspects"| node_n_config

click node_n_pipeline "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/pipeline.py"
click node_n_detector "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/person_detector.py"
click node_n_segmentation "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/sam2_segmentation.py"
click node_n_smpl "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/smpl_estimator.py"
click node_n_viz "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/viz.py"
click node_n_config "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/config.py"
click node_n_devices "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/devices.py"
click node_n_ui "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/app_gradio.py"
click node_n_run_demo "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/scripts/run_demo.py"
click node_n_batch "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/scripts/batch_process.py"
click node_n_debug "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/scripts/debug_projection.py"
click node_n_test_pipe "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/scripts/test_pipeline.py"
click node_n_test_sam2 "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/scripts/test_sam2.py"
click node_n_print_sig "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/scripts/print_signature.py"
click node_n_4dh "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/tree/main/external/4D-Humans"
click node_n_sam2 "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/tree/main/external/sam2"
click node_n_input "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/tree/main/data/input"
click node_n_outputs "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/tree/main/data/outputs"
click node_n_segmented "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/tree/main/data/segmented"
click node_n_smpl_models "https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/tree/main/models/smpl"

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_n_pipeline,node_n_detector,node_n_segmentation,node_n_smpl,node_n_viz,node_n_config,node_n_devices,node_n_ui toneBlue
class node_n_run_demo,node_n_batch,node_n_debug,node_n_test_pipe,node_n_test_sam2,node_n_print_sig toneAmber
class node_n_4dh,node_n_sam2 toneMint
class node_n_input,node_n_outputs,node_n_segmented,node_n_smpl_models toneRose
```

## Components

### Core package

Repository-owned orchestration and domain logic under src/pose3d.

- [Pipeline](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/pipeline.py): orchestrator · Central end-to-end coordinator for image processing and result assembly. · `src/pose3d/pipeline.py`
- [Person detector](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/person_detector.py): detection · Finds people in the input image and defines the per-person branching point. · `src/pose3d/person_detector.py`
- [SAM2 segmentation](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/sam2_segmentation.py): segmentation · Refines detections into per-person masks for isolated downstream reconstruction. · `src/pose3d/sam2_segmentation.py`
- [SMPL estimator](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/smpl_estimator.py): reconstruction · Estimates SMPL pose/shape and produces per-person 3D meshes. · `src/pose3d/smpl_estimator.py`
- [Visualization](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/viz.py): rendering · Produces pose overlays and 3D inspection renders. · `src/pose3d/viz.py`
- [Config](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/config.py): settings · Runtime settings and application configuration. · `src/pose3d/config.py`
- [Devices](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/devices.py): hardware · Hardware and CPU/CUDA selection behavior. · `src/pose3d/devices.py`
- [Gradio UI](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/src/pose3d/app_gradio.py): interactive-ui · Optional interactive front end for manual exploration. · `src/pose3d/app_gradio.py`

### Entry points

CLI and debug runners under scripts/.

- [Demo run](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/scripts/run_demo.py): cli · Single-image demo entry point. · `scripts/run_demo.py`
- [Batch run](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/scripts/batch_process.py): cli · Folder or batch processing entry point. · `scripts/batch_process.py`
- [Debug projection](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/scripts/debug_projection.py): debug-cli · Debugging and projection-oriented runner. · `scripts/debug_projection.py`
- [Pipeline test](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/scripts/test_pipeline.py): validation-cli · Targeted script for exercising the full pipeline. · `scripts/test_pipeline.py`
- [SAM2 test](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/scripts/test_sam2.py): validation-cli · Targeted script for exercising segmentation integration. · `scripts/test_sam2.py`
- [Signature print](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/blob/main/scripts/print_signature.py): utility-cli · Utility script for inspecting or printing signatures. · `scripts/print_signature.py`

### Vendored deps

Third-party model code treated as upstream dependencies.

- [4D-Humans](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/tree/main/external/4D-Humans): vendor-model · Vendored third-party HMR2/4D-Humans implementation used by the SMPL stage. · `external/4D-Humans`
- [SAM2](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/tree/main/external/sam2): vendor-model · Vendored third-party SAM2 implementation used for segmentation. · `external/sam2`

### Data and models

Input/output folders and SMPL assets used by the pipeline.

- [Input data](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/tree/main/data/input): dataset · Canonical ingest location for source images. · `data/input`
- [Outputs](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/tree/main/data/outputs): artifacts · Primary sink for meshes, overlays, and renders. · `data/outputs`
- [Segmented data](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/tree/main/data/segmented): artifacts · Intermediate segmented outputs used during processing. · `data/segmented`
- [SMPL models](https://github.com/jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen/tree/main/models/smpl): assets · Licensed SMPL model files required by reconstruction. · `models/smpl`

## Connections

- Demo run → Pipeline: starts · Demo script invokes the main pipeline.
- Batch run → Pipeline: starts · Batch script drives repeated pipeline execution.
- Debug projection → Pipeline: starts · Debug runner exercises the pipeline with inspection hooks.
- Pipeline test → Pipeline: checks · Validation script runs the full pipeline path.
- SAM2 test → SAM2 segmentation: checks · Validation script focuses on the SAM2 integration.
- Pipeline → Person detector: calls · Pipeline begins by locating people in the image.
- Pipeline → SAM2 segmentation: calls · Pipeline refines person regions into masks.
- Pipeline → SMPL estimator: calls · Pipeline reconstructs 3D pose and meshes per person.
- Pipeline → Visualization: calls · Pipeline generates visual inspection outputs.
- Pipeline → Config: uses · Pipeline reads runtime configuration.
- Pipeline → Devices: uses · Pipeline selects execution device behavior.
- Pipeline → Input data: reads · Pipeline consumes images from the input area.
- Pipeline → Outputs: writes · Pipeline emits final meshes and visual artifacts.
- SAM2 segmentation → SAM2: depends on · Segmentation wraps the vendored SAM2 model code.
- SMPL estimator → 4D-Humans: depends on · SMPL estimation relies on the vendored 4D-Humans implementation.
- SAM2 segmentation → Segmented data: writes · Segmentation may persist intermediate masked data.
- SMPL estimator → SMPL models: loads · Reconstruction requires licensed SMPL assets.
- Gradio UI → Pipeline: drives · Interactive UI provides an alternate way to launch the pipeline.
- Signature print → Config: inspects · Utility script relates to runtime signatures and configuration.
