# ssthurai/tinyml architecture

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

- Interactive diagram: https://gitdiagram.com/ssthurai/tinyml
- Repository: https://github.com/ssthurai/tinyml

## Overview

##### Main Components
- Projects: Clearly mark three separate projects (MCUNet, NetAug, TinyTL). (Even though MCUNet appears as its own folder, the file tree details for NetAug and TinyTL are more elaborate; nonetheless, they all are part of the overall TinyML initiative.)
- Experiment/Training Pipelines:
– For NetAug, modules like train.py, eval.py, and a suite of bash scripts (located in netaug/bash) are responsible for triggering training and evaluation tasks.
– For TinyTL, look at tinytl_fgvc_train.py, the experiment scripts (under tinytl/exp_scripts) and dataset setup scripts (tinytl/dataset_setup_scripts).
- Configuration and Setup:
– NetAug makes use of configuration files (e.g., netaug/configs/default.yaml and netaug/configs/netaug.yaml) to standardize experiments.
– TinyTL uses dataset setup scripts for initializing and managing datasets.
- Model Architectures:
– In NetAug, models are defined in two subdirectories: “models/base” (baseline architectures) and “models/netaug” (augmented modifications). In TinyTL, the core neural network and module definitions reside in tinytl/tinytl/model.
- Utility and Support Modules:
– Shared utilities such as learning rate schedulers, distributed training utilities, and evaluation metrics are found under netaug/utils and tinytl’s utils.
- Data Handling:
– In TinyTL, there is a dedicated “data_providers” module to handle dataset-specific configurations and processing.

##### Relationships and Flows
- Model & Utility Interaction: Illustrate how training scripts rely on the “models” for network architecture and “utils” for tasks like learning rate scheduling, distributed computing support, and metric evaluation.
- Data Pipeline: For TinyTL, indicate how the “data_providers” module fetches and preprocesses data, feeding it to model training and evaluation components.
- Modular Design: Emphasize the separation of concerns by showing that each project segment (NetAug and TinyTL) has its own dedicated configuration, experiment scripts, models, and utilities, though they might share common design principles inherent to TinyML (e.g., memory-efficiency, modularity).

##### Architectural Patterns and Design Principles
– Top Layer: Experiment orchestration (bash scripts, training scripts)
– Middle Layer: Model definitions (base networks versus augmented models) and configuration management.
– Bottom Layer: Utility modules (data handling, evaluation, distributed support) and any lower-level hardware abstraction.
- Modularity & Separation of Concerns: Indicate how each project branch encapsulates its functionality while serving the common goal of efficient on-device learning.
- Extensibility: Identify extension points (such as “models/netaug/utils.py” or “tinytl/tinytl/data_providers”) where further methods or modules might be added for new TinyML tasks.

##### Final Assembly
- Branch down to represent each project (NetAug, TinyTL, MCUNet) in separate sections, with internal structures showing experiment scripts, configuration management, model architectures, and supporting utilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level Node
    TinyML_Hub["TinyML Hub"]:::tinyml

    %% Branch: MCUNet
    MCUNet["MCUNet"]:::project
    TinyML_Hub --> MCUNet

    %% Branch: NetAug
    subgraph "NetAug"
        direction TB
        NetAug_Train["NetAug Training (train.py)"]:::experiment
        NetAug_Bash["NetAug Bash Scripts"]:::experiment
        NetAug_Configs["NetAug Configs"]:::config
        NetAug_Baseline["NetAug Baseline Models"]:::model
        NetAug_Augmented["NetAug Augmented Models"]:::model
        NetAug_Utils["NetAug Utils"]:::utils
    end
    TinyML_Hub --> NetAug_Train

    %% NetAug Relationships
    NetAug_Bash -->|"triggers"| NetAug_Train
    NetAug_Train -->|"reads_config"| NetAug_Configs
    NetAug_Train -->|"calls_base"| NetAug_Baseline
    NetAug_Train -->|"calls_augmented"| NetAug_Augmented
    NetAug_Baseline -->|"uses_utils"| NetAug_Utils
    NetAug_Augmented -->|"uses_utils"| NetAug_Utils

    %% Branch: TinyTL
    subgraph "TinyTL"
        direction TB
        TinyTL_Train["TinyTL Training (tinytl_fgvc_train.py)"]:::experiment
        TinyTL_Exp["TinyTL Exp Scripts"]:::experiment
        TinyTL_Dataset["TinyTL Dataset Setup"]:::data
        TinyTL_DataProviders["TinyTL Data Providers"]:::data
        TinyTL_Model["TinyTL Model"]:::model
        TinyTL_Utils["TinyTL Utils"]:::utils
    end
    TinyML_Hub --> TinyTL_Train

    %% TinyTL Relationships
    TinyTL_Train -->|"triggers_exp"| TinyTL_Exp
    TinyTL_Train -->|"reads_dataset"| TinyTL_Dataset
    TinyTL_Dataset -->|"provides_data"| TinyTL_DataProviders
    TinyTL_Train -->|"calls_model"| TinyTL_Model
    TinyTL_DataProviders -->|"feeds_model"| TinyTL_Model
    TinyTL_Model -->|"uses_utils"| TinyTL_Utils

    %% Click Events for MCUNet
    click MCUNet "https://github.com/ssthurai/tinyml/tree/master/mcunet/"

    %% Click Events for NetAug Components
    click NetAug_Train "https://github.com/ssthurai/tinyml/blob/master/netaug/train.py"
    click NetAug_Bash "https://github.com/ssthurai/tinyml/tree/master/netaug/bash/"
    click NetAug_Configs "https://github.com/ssthurai/tinyml/tree/master/netaug/configs/"
    click NetAug_Baseline "https://github.com/ssthurai/tinyml/tree/master/netaug/models/base/"
    click NetAug_Augmented "https://github.com/ssthurai/tinyml/tree/master/netaug/models/netaug/"
    click NetAug_Utils "https://github.com/ssthurai/tinyml/tree/master/netaug/utils/"

    %% Click Events for TinyTL Components
    click TinyTL_Train "https://github.com/ssthurai/tinyml/blob/master/tinytl_fgvc_train.py"
    click TinyTL_Exp "https://github.com/ssthurai/tinyml/tree/master/tinytl/exp_scripts/"
    click TinyTL_Dataset "https://github.com/ssthurai/tinyml/tree/master/tinytl/dataset_setup_scripts/"
    click TinyTL_DataProviders "https://github.com/ssthurai/tinyml/tree/master/tinytl/tinytl/data_providers/"
    click TinyTL_Model "https://github.com/ssthurai/tinyml/tree/master/tinytl/tinytl/model/"
    click TinyTL_Utils "https://github.com/ssthurai/tinyml/tree/master/tinytl/tinytl/utils/"

    %% Styles
    classDef tinyml fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef project fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef experiment fill:#ffeeba,stroke:#856404,stroke-width:2px;
    classDef config fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef model fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef utils fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef data fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
