How jnr-10/segmentpose3d-bodysegmentusingsam_smpl3dmeshgen works
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: pipeline.py Pipeline · sam2_segmentation.py SAM2 segmentation · smpl_estimator.py SMPL estimator · config.py Config
Components 20
Core package
Repository-owned orchestration and domain logic under src/pose3d.
- Pipeline · Central end-to-end coordinator for image processing and result assembly.
src/pose3d/pipeline.py - Person detector · Finds people in the input image and defines the per-person branching point.
src/pose3d/person_detector.py - SAM2 segmentation · Refines detections into per-person masks for isolated downstream reconstruction.
src/pose3d/sam2_segmentation.py - SMPL estimator · Estimates SMPL pose/shape and produces per-person 3D meshes.
src/pose3d/smpl_estimator.py - Visualization · Produces pose overlays and 3D inspection renders.
src/pose3d/viz.py - Config · Runtime settings and application configuration.
src/pose3d/config.py - Devices · Hardware and CPU/CUDA selection behavior.
src/pose3d/devices.py - Gradio UI · Optional interactive front end for manual exploration.
src/pose3d/app_gradio.py
Entry points
CLI and debug runners under scripts/.
- Demo run · Single-image demo entry point.
scripts/run_demo.py - Batch run · Folder or batch processing entry point.
scripts/batch_process.py - Debug projection · Debugging and projection-oriented runner.
scripts/debug_projection.py - Pipeline test · Targeted script for exercising the full pipeline.
scripts/test_pipeline.py - SAM2 test · Targeted script for exercising segmentation integration.
scripts/test_sam2.py - Signature print · Utility script for inspecting or printing signatures.
scripts/print_signature.py
Vendored deps
Third-party model code treated as upstream dependencies.
Data and models
Input/output folders and SMPL assets used by the pipeline.
- Input data · Canonical ingest location for source images.
data/input - Outputs · Primary sink for meshes, overlays, and renders.
data/outputs - Segmented data · Intermediate segmented outputs used during processing.
data/segmented - SMPL models · Licensed SMPL model files required by reconstruction.
models/smpl
Connections 19
- 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.