# jatin-mehra119/csiro-image2biomass architecture

> Architecture diagram of the GitHub repository jatin-mehra119/csiro-image2biomass, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jatin-mehra119/csiro-image2biomass
- Repository: https://github.com/jatin-mehra119/csiro-image2biomass

## Overview

1. **Repository purpose and top-level split**
   This repo is organized around a single ML product: predicting pasture biomass from field images plus tabular/contextual data. Architecturally it has two main planes:
   - an **offline training/analysis plane** at the repository root
   - an **online inference plane** under `API/`

2. **Inputs and data boundary**
   The training pipeline consumes:
   - image datasets in `train/` and `test/`
   - tabular data from `train.csv` and `test.csv`
   - likely derived or auxiliary features such as NDVI and ground-truth measurements, as described in the README  
   These inputs are the source of truth for model fitting and evaluation.

3. **Offline training orchestration**
   The root scripts `main.py` and `train.py` are the primary training entry points. They appear to orchestrate model fitting, validation, and checkpoint creation. This is where the repo’s predictive models are built, rather than served.

4. **Auxiliary modeling path**
   `aux_model.py` suggests a separate branch of modeling for auxiliary data or a secondary learner. The README explicitly references an “auxiliary model” and an “ensemble,” so the training architecture likely combines:
   - a main biomass model
   - one or more auxiliary models
   - an ensemble or checkpoint selection strategy

5. **Exploration and dataset inspection**
   `EDA.py` is a standalone analysis workflow for inspecting distributions, sample images, and summary statistics. It is not part of the serving path, but it supports model development by validating the data before training.

6. **Model artifact layer**
   The README references saved weight directories such as `Models_Seeded_Ensemble/` and `Models_Aux_Only/`. These are the persistence boundary between training and inference:
   - training scripts write `.pth` model weights here
   - the API loads those artifacts for prediction

7. **Inference service architecture**
   `API/` is a separate service package, likely built with FastAPI as indicated by the README. Its structure is cleanly divided into:
   - `API/main.py`: application bootstrap / server entry point
   - `API/api/endpoints.py`: request routes
   - `API/models/`: model architecture and inference logic
   - `API/core/config.py`: runtime configuration

8. **Request/response contracts**
   `API/models/schemas.py` defines the API’s input and output shapes, which is important for diagramming the service boundary. This layer is what decouples client requests from internal model code and ensures stable prediction payloads.

9. **Serving-time model logic**
   `API/models/architectures.py` and `API/models/inference.py` separate network definition from prediction execution. In the architecture diagram, this is the point where incoming API requests are transformed into model-ready inputs, then passed through loaded checkpoints to produce biomass predictions.

10. **Deployment and runtime**
   The repo is designed to run both locally and in containerized form:
   - `uvicorn API.main:app --reload` starts the inference server
   - `dockerfile` packages the application for consistent deployment
   The README also notes a Hugging Face Space deployment, so the same inference service is intended to be hosted remotely as an API endpoint.

11. **Experiment tracking**
   Training is tracked in Weights & Biases, which functions as an observability layer for the offline pipeline. It records model metrics, likely across the main and auxiliary training runs, but does not affect runtime inference.

12. **How the data flows end-to-end**
   The overall lifecycle is:
   - raw image/tabular data enter the training scripts
   - models are trained and evaluated offline
   - best checkpoints are saved as `.pth` artifacts
   - the API loads those checkpoints on startup
   - client requests hit the endpoint layer
   - inference code returns biomass predictions

13. **Key architectural boundary to show in a diagram**
   The most important boundary is between **training-time computation** and **serving-time inference**. Everything under the repo root primarily produces model artifacts; everything under `API/` consumes those artifacts and exposes them as a prediction service.

Main entry points: [`train.py`](https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/train.py) (Train loop), [`API/models/inference.py`](https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/models/inference.py) (Inference), [`API/main.py`](https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/main.py) (API app), [`API/api/endpoints.py`](https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/api/endpoints.py) (Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Offline training"]
  node_main_py["Main train<br/>trainer entry<br/>[main.py]"]
  node_train_py["Train loop<br/>training orchestration<br/>[train.py]"]
  node_aux_model_py["Aux model<br/>aux learner<br/>[aux_model.py]"]
  node_eda_py["EDA<br/>analysis workflow<br/>[EDA.py]"]
  node_wandb(("W&B<br/>experiment tracking"))
end

subgraph group_serving["Inference API"]
  node_api_main["API app<br/>service bootstrap<br/>[main.py]"]
  node_endpoints["Routes<br/>request layer<br/>[endpoints.py]"]
  node_config["Config<br/>[config.py]"]
  node_schemas["Schemas<br/>contract<br/>[schemas.py]"]
  node_architectures["Arch defs<br/>model definition<br/>[architectures.py]"]
  node_inference["Inference<br/>prediction engine<br/>[inference.py]"]
end

subgraph group_data["Data and artifacts"]
  node_train_data[("Train set<br/>dataset")]
  node_test_data[("Test set<br/>dataset")]
  node_train_csv["Train CSV<br/>tabular input"]
  node_test_csv["Test CSV<br/>tabular input"]
  node_plots["Plots<br/>analysis output"]
  node_weights[("Model weights<br/>artifact store")]
  node_aux_weights[("Aux weights<br/>artifact store")]
end

node_train_data -->|"inputs"| node_main_py
node_test_data -->|"eval data"| node_train_py
node_train_csv -->|"labels"| node_main_py
node_test_csv -->|"eval metadata"| node_train_py
node_eda_py -.->|"inspect"| node_train_data
node_eda_py -->|"outputs"| node_plots
node_main_py -->|"orchestrates"| node_train_py
node_train_py -.->|"branch"| node_aux_model_py
node_train_py -->|"logs"| node_wandb
node_aux_model_py -->|"writes"| node_aux_weights
node_train_py -->|"writes"| node_weights
node_weights -->|"loads"| node_api_main
node_aux_weights -->|"loads"| node_inference
node_api_main -->|"configures"| node_config
node_api_main -->|"mounts"| node_endpoints
node_endpoints -->|"validates"| node_schemas
node_endpoints -->|"calls"| node_inference
node_inference -->|"uses"| node_architectures
node_inference -->|"runs"| node_weights
node_inference -->|"formats"| node_schemas
node_api_main -.->|"initializes"| node_inference

click node_plots "https://github.com/jatin-mehra119/csiro-image2biomass/tree/main/plots"
click node_main_py "https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/main.py"
click node_train_py "https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/train.py"
click node_aux_model_py "https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/aux_model.py"
click node_eda_py "https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/EDA.py"
click node_api_main "https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/main.py"
click node_endpoints "https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/api/endpoints.py"
click node_config "https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/core/config.py"
click node_schemas "https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/models/schemas.py"
click node_architectures "https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/models/architectures.py"
click node_inference "https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/models/inference.py"

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_main_py,node_train_py,node_aux_model_py,node_eda_py,node_wandb toneBlue
class node_api_main,node_endpoints,node_config,node_schemas,node_architectures,node_inference toneAmber
class node_train_data,node_test_data,node_train_csv,node_test_csv,node_plots,node_weights,node_aux_weights toneMint
```

## Components

### Offline training

Root-level scripts and analysis used to build biomass models and checkpoints.

- [Main train](https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/main.py): trainer entry · Primary offline training entry point. · `main.py`
- [Train loop](https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/train.py): training orchestration · Model fitting, validation, and checkpoint workflow. · `train.py`
- [Aux model](https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/aux_model.py): aux learner · Secondary modeling path for auxiliary data or ensemble support. · `aux_model.py`
- [EDA](https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/EDA.py): analysis workflow · Dataset inspection and exploratory analysis. · `EDA.py`
- **W&B**: experiment tracking · Tracks offline training metrics and runs.

### Inference API

FastAPI service that loads trained artifacts and returns predictions.

- [API app](https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/main.py): service bootstrap · Server startup and application wiring. · `API/main.py`
- [Routes](https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/api/endpoints.py): request layer · HTTP endpoint definitions. · `API/api/endpoints.py`
- [Config](https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/core/config.py): runtime config · Service configuration and environment settings. · `API/core/config.py`
- [Schemas](https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/models/schemas.py): contract · Request and response payload definitions. · `API/models/schemas.py`
- [Arch defs](https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/models/architectures.py): model definition · Serving-time network and model structure definitions. · `API/models/architectures.py`
- [Inference](https://github.com/jatin-mehra119/csiro-image2biomass/blob/main/API/models/inference.py): prediction engine · Loads checkpoints and produces biomass predictions. · `API/models/inference.py`

### Data and artifacts

Training inputs, generated model weights, and analysis outputs.

- **Train set**: dataset · Image and tabular training inputs.
- **Test set**: dataset · Held-out evaluation inputs.
- **Train CSV**: tabular input · Training metadata and labels.
- **Test CSV**: tabular input · Evaluation metadata and labels.
- [Plots](https://github.com/jatin-mehra119/csiro-image2biomass/tree/main/plots): analysis output · Generated visualizations from exploration or training. · `plots`
- **Model weights**: artifact store · Saved checkpoints consumed by serving.
- **Aux weights**: artifact store · Auxiliary model checkpoints consumed by serving.

## Connections

- Train set → Main train: inputs · Image training data feeds the main training entry point.
- Test set → Train loop: eval data · Held-out data is used for validation and evaluation.
- Train CSV → Main train: labels · Tabular labels and metadata drive training.
- Test CSV → Train loop: eval metadata · Tabular evaluation data supports model assessment.
- EDA → Train set: inspect · Exploration validates data distributions and samples.
- EDA → Plots: outputs · EDA produces visual summaries and charts.
- Main train → Train loop: orchestrates · Primary entry point hands control to the training loop.
- Train loop → Aux model: branch · Training may invoke auxiliary modeling or ensemble paths.
- Train loop → W&B: logs · Training metrics and runs are tracked externally.
- Aux model → Aux weights: writes · Auxiliary training saves its own checkpoints.
- Train loop → Model weights: writes · Main training saves model artifacts for later serving.
- Model weights → API app: loads · API startup loads the primary trained checkpoint.
- Aux weights → Inference: loads · Inference may use auxiliary checkpoints or ensemble members.
- API app → Config: configures · Service bootstrapping reads runtime settings.
- API app → Routes: mounts · Application bootstrap attaches request routes.
- Routes → Schemas: validates · Routes use schemas to validate request and response shapes.
- Routes → Inference: calls · HTTP handlers delegate prediction work to inference logic.
- Inference → Arch defs: uses · Prediction code relies on model definitions.
- Inference → Model weights: runs · Inference executes loaded trained weights.
- Inference → Schemas: formats · Inference output is shaped for API contracts.
- API app → Inference: initializes · Server startup prepares the prediction pipeline.
