# akarifrites/moodeng_is_cute architecture

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

- Interactive diagram: https://gitdiagram.com/akarifrites/moodeng_is_cute
- Repository: https://github.com/akarifrites/moodeng_is_cute

## Overview

##### Project’s Type and Purpose
- This project is a full-scale baseline system for an acoustic scene classification challenge. Its purpose is to train and evaluate low-complexity deep learning models that classify audio recordings under resource constraints.
- It is built with PyTorch and PyTorch Lightning, makes use of Weights & Biases for logging and experiment tracking, and includes tools for model export to ONNX and quantization.

##### File Structure
- Data & Dataset: The folder “dataset” (specifically dataset/dcase24.py) and “split_setup” CSV files define how the input audio data is organized, along with external dataset preparation.
- Model Components: The “models” directory is home to different network definitions – “baseline.py”, “baseline_devices.py”, “mel.py”, “mobilenet.py” – representing the neural network architectures.
- Training and Inference: Scripts such as “run_training.py”, “run_training_devices.py”, “run_inference2.py”, and “recording2.py” indicate separate pipelines for training, device-specific training, inference, and even recording-based tests.
- Checkpoints and Logs: Checkpoints are stored in directories like “DCASE24_Task1” and “lightning_logs”. Additionally, “wandb” folders track experiments.
- ONNX and Quantization: The “onnx_runtime” and “quantization” folders contain scripts for exporting the model to ONNX (with both dynamic and static quantized versions), testing ONNX, and performing quantization operations.
- Helpers and Utilities: The “helpers” folder contains utility functions (including ones related to NeSsi) that aid with parameter counting and other support tasks.

##### Core Components and Their Relationships
a. Data Preparation and Loading:
- Data Ingestion: The repository expects a dataset (audio files and meta-information) to be placed in a specified directory. The “dataset/dcase24.py” module handles this.
- Data Splitting: “split_setup” contains CSV files (split5.csv, split100.csv, etc.) which define the training splits.
b. Model Definition and Architecture:
- The “models” directory defines the baseline network. There is an emphasis on low-complexity architecture (with detailed parameter and MAC calculations shown in the README).
- Separate versions (e.g., baseline and mobilenet) may be defined for variations including channel-specific processing when addressing device variations.
c. Training Pipeline:
- The training loop is implemented using PyTorch Lightning (see “run_training.py” and “run_training_devices.py”), which integrates checkpoints (saved in “DCASE24_Task1” and “lightning_logs”) and logging to Weights & Biases (under “wandb”).
d. Inference and Evaluation:
- Inference scripts (e.g., “run_inference2.py”, “tools/model_infer.py”) process data post-training to generate predictions and evaluation metrics which are stored under the “predictions” folder.
e. Export and Quantization:
- Conversion of the trained model to 16-bit and even 8-bit precision is handled via the “quantization” and “onnx_runtime” folders. Here, scripts like “export_to_onnx.py” and “quantize.py” perform model export and optimization.
f. Experiment Tracking and Logging:
- The use of Weights & Biases is evident by the “wandb” directory structure, which captures logs, configurations, and training artifacts.

## Diagram (Mermaid)

```mermaid
flowchart TD

  subgraph "Data Layer"
    D1["Dataset (audio files & meta)"]:::dataColor
    D2["CSV Splits (split_setup)"]:::dataColor
  end

  subgraph "Preprocessing & Data Loading"
    PL["Data Loader (dataset/dcase24.py)"]:::dataColor
  end

  subgraph "Model Definition & Architecture"
    MD1["Baseline (models/baseline.py)"]:::modelColor
    MD2["Baseline Devices (models/baseline_devices.py)"]:::modelColor
    MD3["MobileNet (models/mobilenet.py)"]:::modelColor
    MD4["Mel (models/mel.py)"]:::modelColor
    MD5["TestModel1 (models/testmodel_1.py)"]:::modelColor
  end

  subgraph "Training Engine (PyTorch Lightning)"
    T1["Training Script (run_training.py)"]:::trainingColor
    T2["Device Training (run_training_devices.py)"]:::trainingColor
    T3["Checkpoints & Logs (lightning_logs)"]:::trainingColor
  end

  subgraph "Experiment Tracking & Logging"
    E1["Weights & Biases (wandb)"]:::loggingColor
  end

  subgraph "Inference & Deployment"
    I1["Inference Script (run_inference2.py)"]:::inferenceColor
    I2["Model Inference (tools/model_infer.py)"]:::inferenceColor
    I3["ONNX Export (onnx_runtime)"]:::inferenceColor
    I4["Quantization (quantization)"]:::inferenceColor
    I5["Predictions (predictions)"]:::inferenceColor
  end

  subgraph "Utilities & Helpers"
    U1["Helpers (helpers)"]:::helperColor
    U2["Model Helpers (models/helpers)"]:::helperColor
  end

  subgraph "Recording Testing"
    R1["Recording (recording2.py)"]:::testingColor
  end

  %% Flow Connections
  D1 -->|"audio_data"| PL
  D2 -->|"split_info"| PL

  PL -->|"preprocessed_audio"| T1
  PL -->|"preprocessed_audio"| T2

  T1 -->|"trains_on"| MD1
  T1 --> MD2
  T1 --> MD3
  T1 --> MD4
  T1 --> MD5

  T2 -->|"device_specific_train"| MD2

  T1 -->|"saves_ckpts"| T3
  T2 --> T3

  T1 -->|"logs_experiment"| E1
  T2 --> E1
  T3 -->|"checkpoint_data"| E1

  T1 -->|"model_ready"| I1
  T2 --> I1

  I1 -->|"inference_results"| I5
  I2 -->|"refined_inference"| I5
  I1 --> I2

  R1 -->|"recorded_input"| I1

  %% Utilization of Helpers by Model & Training modules
  MD1 -.-> U1
  MD2 -.-> U1
  MD3 -.-> U1
  MD4 -.-> U1
  MD5 -.-> U1
  T1 -.-> U1
  T2 -.-> U1
  MD1 -.-> U2
  MD2 -.-> U2
  MD3 -.-> U2
  MD4 -.-> U2
  MD5 -.-> U2

  %% Click Events
  click PL "https://github.com/akarifrites/moodeng_is_cute/blob/main/dataset/dcase24.py"
  click D2 "https://github.com/akarifrites/moodeng_is_cute/tree/main/split_setup/"
  click MD1 "https://github.com/akarifrites/moodeng_is_cute/blob/main/models/baseline.py"
  click MD2 "https://github.com/akarifrites/moodeng_is_cute/blob/main/models/baseline_devices.py"
  click MD3 "https://github.com/akarifrites/moodeng_is_cute/blob/main/models/mobilenet.py"
  click MD4 "https://github.com/akarifrites/moodeng_is_cute/blob/main/models/mel.py"
  click MD5 "https://github.com/akarifrites/moodeng_is_cute/blob/main/models/testmodel_1.py"
  click T1 "https://github.com/akarifrites/moodeng_is_cute/blob/main/run_training.py"
  click T2 "https://github.com/akarifrites/moodeng_is_cute/blob/main/run_training_devices.py"
  click T3 "https://github.com/akarifrites/moodeng_is_cute/tree/main/lightning_logs/"
  click E1 "https://github.com/akarifrites/moodeng_is_cute/tree/main/wandb/"
  click I1 "https://github.com/akarifrites/moodeng_is_cute/blob/main/run_inference2.py"
  click I2 "https://github.com/akarifrites/moodeng_is_cute/blob/main/tools/model_infer.py"
  click I5 "https://github.com/akarifrites/moodeng_is_cute/tree/main/predictions/"
  click I3 "https://github.com/akarifrites/moodeng_is_cute/tree/main/onnx_runtime/"
  click I4 "https://github.com/akarifrites/moodeng_is_cute/tree/main/quantization/"
  click U1 "https://github.com/akarifrites/moodeng_is_cute/tree/main/helpers/"
  click U2 "https://github.com/akarifrites/moodeng_is_cute/tree/main/models/helpers/"
  click R1 "https://github.com/akarifrites/moodeng_is_cute/blob/main/recording2.py"

  %% Styles
  classDef dataColor fill:#FFDDC1,stroke:#333,stroke-width:2px;
  classDef modelColor fill:#C1FFD7,stroke:#333,stroke-width:2px;
  classDef trainingColor fill:#C1D4FF,stroke:#333,stroke-width:2px;
  classDef loggingColor fill:#F9D7FF,stroke:#333,stroke-width:2px;
  classDef inferenceColor fill:#FFF3C1,stroke:#333,stroke-width:2px;
  classDef helperColor fill:#D7F9FF,stroke:#333,stroke-width:2px;
  classDef testingColor fill:#FFD7D7,stroke:#333,stroke-width:2px;
```
