# arvkr/bodyscan architecture

> Architecture diagram of the GitHub repository arvkr/bodyscan, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arvkr/bodyscan
- Repository: https://github.com/arvkr/bodyscan

## Overview

##### Main Components

a) Input Processing Layer
- Image input handling
- EXIF data extraction for camera intrinsics

b) Parallel Processing Pipeline
- Depth Estimation Network Branch
- Object Detection Branch (RetinaNet)

c) Measurement Processing Layer
- Measurement calculation module
- Body fat percentage computation (Navy formula)

##### Detailed Component Breakdown

a) Core Processing Components:
- Data Loading Module (dataloader.py, loaders/)
- Model Module (models/)
- Options Module (options/)
- Utility Functions (util/)
- NMS Library (lib/nms/)

b) Model Architecture:
- Create two parallel branches:
1. Depth Estimation Network
- Based on Hourglass architecture (models/hourglass.py)
- Input/output tensors
2. RetinaNet Object Detection
- Feature extraction
- NMS post-processing

##### Data Flow Representation

- Image input → Data Loading
- Data → Parallel Processing (Depth + Detection)
- Processing Results → Measurement Calculation
- Measurements → Body Fat Estimation

##### Technical Details

Annotations showing:
- PyTorch as the primary framework
- CUDA support for GPU acceleration (based on NMS implementation)
- Key dependencies (OpenCV, scikit-image, etc.)
- File formats (.jpg input, .npy depth maps)

##### Implementation Details

Create subsections showing:
- Model checkpoint handling (checkpoints/)
- Data preprocessing pipeline
- Post-processing steps
- Measurement calculation logic

##### Additional Elements

Include:
- Input/Output specifications
- System requirements
- GPU/CPU processing indicators
- Error handling flow
- Key configuration parameters

- Parallel processing of depth estimation and body part detection
- Integration of camera intrinsics
- Measurement calculation pipeline
- Body fat percentage computation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        IMG[Image Input]:::input
        EXIF[EXIF Data]:::input
    end

    subgraph "Data Loading"
        DL["Data Loading Module"]:::core
        AF["Aligned Data Loader"]:::core
        IF["Image Folder"]:::core
    end

    subgraph "Parallel Processing"
        subgraph "Depth Estimation Branch"
            DEN["Depth Network"]:::model
            P2P["Pix2Pix Model"]:::model
            GD["Get Depth"]:::process
        end

        subgraph "Object Detection Branch"
            RET["RetinaNet"]:::model
            NMS["NMS Library"]:::process
            ANC["Anchor Handling"]:::process
            BBX["Bbox Extraction"]:::process
        end
    end

    subgraph "Measurement Processing"
        MP["Measure Body"]:::process
        CD["Class Definitions"]:::data
        BF["Body Fat Calculation"]:::process
    end

    subgraph "Core Framework"
        BM["Base Model"]:::core
        NET["Networks"]:::core
        MOD["Model"]:::core
    end

    subgraph "Configuration"
        BO["Base Options"]:::config
        MO["Measure Options"]:::config
        TO["Train Options"]:::config
    end

    subgraph "Storage"
        IN["Input Storage"]:::storage
        OUT["Output Storage"]:::storage
        CKP["Checkpoints"]:::storage
    end

    subgraph "Utilities"
        UTIL["Utility Functions"]:::util
        LOSS["Loss Functions"]:::util
    end

    %% Connections
    IMG --> DL
    EXIF --> DL
    DL --> AF
    DL --> IF
    AF --> DEN
    AF --> RET
    DEN --> P2P
    P2P --> GD
    RET --> NMS
    RET --> ANC
    NMS --> BBX
    GD --> MP
    BBX --> MP
    MP --> BF
    CD --> MP
    BM --> NET
    NET --> MOD
    BO --> MO
    BO --> TO
    IN --> DL
    MP --> OUT
    LOSS --> DEN
    LOSS --> RET
    UTIL --> MP

    %% Click Events
    click DL "https://github.com/arvkr/BodyScan/blob/master/dataloader.py"
    click AF "https://github.com/arvkr/BodyScan/blob/master/loaders/aligned_data_loader.py"
    click IF "https://github.com/arvkr/BodyScan/blob/master/loaders/image_folder.py"
    click DEN "https://github.com/arvkr/BodyScan/blob/master/models/hourglass.py"
    click P2P "https://github.com/arvkr/BodyScan/blob/master/models/pix2pix_model.py"
    click NMS "https://github.com/arvkr/BodyScan/tree/master/lib/nms"
    click ANC "https://github.com/arvkr/BodyScan/blob/master/anchors.py"
    click BBX "https://github.com/arvkr/BodyScan/blob/master/bbox_extraction.py"
    click MP "https://github.com/arvkr/BodyScan/blob/master/measure_body.py"
    click CD "https://github.com/arvkr/BodyScan/blob/master/classes.csv"
    click BM "https://github.com/arvkr/BodyScan/blob/master/models/base_model.py"
    click NET "https://github.com/arvkr/BodyScan/blob/master/models/networks.py"
    click MOD "https://github.com/arvkr/BodyScan/blob/master/model.py"
    click BO "https://github.com/arvkr/BodyScan/blob/master/options/base_options.py"
    click MO "https://github.com/arvkr/BodyScan/blob/master/options/measure_options.py"
    click TO "https://github.com/arvkr/BodyScan/blob/master/options/train_options.py"
    click UTIL "https://github.com/arvkr/BodyScan/blob/master/util/util.py"
    click IN "https://github.com/arvkr/BodyScan/tree/master/data/inputs"
    click OUT "https://github.com/arvkr/BodyScan/tree/master/data/outputs"
    click CKP "https://github.com/arvkr/BodyScan/tree/master/checkpoints/test_local"
    click LOSS "https://github.com/arvkr/BodyScan/blob/master/losses.py"
    click GD "https://github.com/arvkr/BodyScan/blob/master/get_depth.py"

    %% Styles
    classDef input fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef core fill:#ff9e64,stroke:#333,stroke-width:2px
    classDef model fill:#90ee90,stroke:#333,stroke-width:2px
    classDef process fill:#ffd700,stroke:#333,stroke-width:2px
    classDef data fill:#c8a2c8,stroke:#333,stroke-width:2px
    classDef config fill:#ffb6c1,stroke:#333,stroke-width:2px
    classDef storage fill:#b8860b,stroke:#333,stroke-width:2px
    classDef util fill:#d3d3d3,stroke:#333,stroke-width:2px
```
