# tirth-byte/galaxy-zoo architecture

> Architecture diagram of the GitHub repository tirth-byte/galaxy-zoo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tirth-byte/galaxy-zoo
- Repository: https://github.com/tirth-byte/galaxy-zoo

## Overview

#### Purpose and Entry Points
This repository is a Python/PyTorch image-classification pipeline for assigning galaxy images to seven morphology classes using transfer-learned EfficientNet-B0. Primary operational entry points are dataset acquisition/preparation (`dataset.py`), model training (`train.py`), optional CSV-oriented training logic (`train_csv.py`), and batch inference/report generation (`predict.py`). `index.html` is a static browser dashboard, not part of the ML runtime.

#### Central Configuration Contract
`config.py` centralizes class definitions, filesystem locations, hyperparameters, and training/runtime constants consumed across the pipeline. It is the main contract connecting data loading, model output dimensionality, training behavior, checkpoint locations, and inference labels.
- `config.py`
- `train.py`
- `predict.py`

#### Data Acquisition and Dataset Boundary
Dataset preparation is handled by `dataset.py`. It can download source data through Kaggle credentials and organize images into class-oriented directories suitable for supervised training. The boundary is filesystem-based: prepared image folders become the input to PyTorch dataset/dataloader construction; raw external Kaggle data and local user-supplied images remain outside the model code.
- `dataset.py`
- `requirements.txt`

#### Image Transforms and Loading
The dataset stage defines image preprocessing and augmentation, then emits PyTorch loaders for training and validation. These loaders carry image tensors plus class targets into the training loop. EfficientNet-compatible normalization and resize behavior should remain consistent between this stage and inference preprocessing.
- `dataset.py`
- `train.py`
- `predict.py`

#### Model Construction
`model.py` owns the EfficientNet-B0 classifier definition. It adapts the pretrained model’s final classification layers to the repository’s seven galaxy classes, forming the shared network contract for both training and prediction. Training produces a checkpoint/state artifact that inference reloads.
- `model.py`
- `train.py`
- `predict.py`

#### Training and Evaluation Pipeline
`train.py` orchestrates transfer learning: it receives loaders, instantiates the model, optimizes cross-entropy loss, evaluates validation metrics, and applies early stopping plus cosine-annealing learning-rate scheduling. It produces persisted model checkpoints and diagnostics such as training-history and confusion-matrix images under the output artifact area.
- `train.py`
- `model.py`
- `output`

`train_csv.py` is a secondary training-oriented pipeline and should be treated as a separate/alternative input-flow path until its relationship to `train.py` is verified.
- `train_csv.py`

#### Batch Inference and Reporting
`predict.py` accepts unseen files from a local input directory, applies inference preprocessing, runs logits through the trained classifier, converts scores to probabilities and predicted labels, and writes consumable reports. Outputs include a master CSV and formatted Excel results, making this the stakeholder-facing delivery boundary.
- `predict.py`
- `output`
- `config.py`

#### Runtime and External Dependencies
The primary runtime is Python 3.8+ with PyTorch and EfficientNet-related dependencies declared in `requirements.txt`. Kaggle is the material external service for automated dataset download and requires local `kaggle.json` credentials. The static dashboard runs directly in a browser from `index.html`; the nested `attendance-bot` package appears unrelated to the galaxy-classification pipeline based on the provided repository structure.
- `requirements.txt`
- `dataset.py`
- `index.html`
- `attendance-bot/package.json`

Main entry points: [`config.py`](https://github.com/tirth-byte/galaxy-zoo/blob/main/config.py) (Pipeline configuration), [`train.py`](https://github.com/tirth-byte/galaxy-zoo/blob/main/train.py) (Training pipeline), [`dataset.py`](https://github.com/tirth-byte/galaxy-zoo/blob/main/dataset.py) (Dataset preparation), [`model.py`](https://github.com/tirth-byte/galaxy-zoo/blob/main/model.py) (EfficientNet-B0 model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_kaggle(("Kaggle dataset<br/>external service"))
  node_dataset["Dataset preparation<br/>Python entry point<br/>[dataset.py]"]
  node_loaders["Transforms &amp; loaders<br/>data loading<br/>[dataset.py]"]
end

subgraph group_ml["ML runtime"]
  node_config["Pipeline configuration<br/>shared contract<br/>[config.py]"]
  node_model{{"EfficientNet-B0 model<br/>model definition<br/>[model.py]"}}
  node_trainer["Training pipeline<br/>Python entry point<br/>[train.py]"]
  node_optimization["Optimization &amp; evaluation<br/>training loop<br/>[train.py]"]
  node_csvtrainer["CSV training path<br/>alternative entry point<br/>[train_csv.py]"]
  node_artifacts[("Model &amp; diagnostics<br/>artifact directory")]
end

subgraph group_delivery["Inference delivery"]
  node_predict["Batch prediction<br/>Python entry point<br/>[predict.py]"]
  node_inference["Inference preprocessing<br/>inference stage<br/>[predict.py]"]
  node_reports["CSV &amp; Excel reports<br/>delivery artifact"]
end

node_deps["Python dependencies<br/>[requirements.txt]"]
node_dashboard["Static dashboard<br/>browser page<br/>[index.html]"]
node_attendance["Attendance bot<br/>unrelated package<br/>[package.json]"]

node_deps -.->|"provides runtime"| node_dataset
node_deps -.->|"provides runtime"| node_trainer
node_kaggle -->|"downloads raw data"| node_dataset
node_config -->|"uses paths &amp; classes"| node_dataset
node_dataset -->|"prepared image folders"| node_loaders
node_config -->|"uses class contract"| node_loaders
node_loaders -->|"train/validation batches"| node_trainer
node_config -->|"uses hyperparameters"| node_trainer
node_config -->|"sets output classes"| node_model
node_model -->|"instantiated for training"| node_trainer
node_trainer -->|"runs"| node_optimization
node_optimization -->|"writes checkpoint &amp; diagnostics"| node_artifacts
node_csvtrainer -.->|"may produce training artifacts"| node_artifacts
node_config -->|"supplies labels &amp; paths"| node_predict
node_artifacts -->|"reloads trained checkpoint"| node_predict
node_predict -->|"processes input files"| node_inference
node_model -->|"produces logits"| node_inference
node_inference -->|"writes labels &amp; probabilities"| node_reports

click node_deps "https://github.com/tirth-byte/galaxy-zoo/blob/main/requirements.txt"
click node_dataset "https://github.com/tirth-byte/galaxy-zoo/blob/main/dataset.py"
click node_loaders "https://github.com/tirth-byte/galaxy-zoo/blob/main/dataset.py"
click node_config "https://github.com/tirth-byte/galaxy-zoo/blob/main/config.py"
click node_model "https://github.com/tirth-byte/galaxy-zoo/blob/main/model.py"
click node_trainer "https://github.com/tirth-byte/galaxy-zoo/blob/main/train.py"
click node_optimization "https://github.com/tirth-byte/galaxy-zoo/blob/main/train.py"
click node_csvtrainer "https://github.com/tirth-byte/galaxy-zoo/blob/main/train_csv.py"
click node_artifacts "https://github.com/tirth-byte/galaxy-zoo/tree/main/output"
click node_predict "https://github.com/tirth-byte/galaxy-zoo/blob/main/predict.py"
click node_inference "https://github.com/tirth-byte/galaxy-zoo/blob/main/predict.py"
click node_reports "https://github.com/tirth-byte/galaxy-zoo/tree/main/output"
click node_dashboard "https://github.com/tirth-byte/galaxy-zoo/blob/main/index.html"
click node_attendance "https://github.com/tirth-byte/galaxy-zoo/blob/main/attendance-bot/package.json"

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_kaggle,node_dataset,node_loaders toneBlue
class node_config,node_model,node_trainer,node_optimization,node_csvtrainer,node_artifacts toneAmber
class node_predict,node_inference,node_reports toneMint
class node_deps,node_dashboard,node_attendance toneNeutral
```

## Components

### Data preparation

- **Kaggle dataset**: external service · Download source requiring local Kaggle credentials.
- [Dataset preparation](https://github.com/tirth-byte/galaxy-zoo/blob/main/dataset.py): Python entry point · Downloads and organizes class-oriented image folders. · `dataset.py`
- [Transforms & loaders](https://github.com/tirth-byte/galaxy-zoo/blob/main/dataset.py): data loading · Augments and normalizes images into training and validation tensors. · `dataset.py`

### ML runtime

- [Pipeline configuration](https://github.com/tirth-byte/galaxy-zoo/blob/main/config.py): shared contract · Classes, paths, hyperparameters, and runtime constants. · `config.py`
- [EfficientNet-B0 model](https://github.com/tirth-byte/galaxy-zoo/blob/main/model.py): model definition · Pretrained network adapted for seven morphology classes. · `model.py`
- [Training pipeline](https://github.com/tirth-byte/galaxy-zoo/blob/main/train.py): Python entry point · Orchestrates fitting, validation, and artifact creation. · `train.py`
- [Optimization & evaluation](https://github.com/tirth-byte/galaxy-zoo/blob/main/train.py): training loop · Cross-entropy fitting with cosine scheduling and early stopping. · `train.py`
- [CSV training path](https://github.com/tirth-byte/galaxy-zoo/blob/main/train_csv.py): alternative entry point · Secondary training flow with relationship to the main trainer unverified. · `train_csv.py`
- [Model & diagnostics](https://github.com/tirth-byte/galaxy-zoo/tree/main/output): artifact directory · Checkpoints, history, and confusion-matrix outputs. · `output`

### Inference delivery

- [Batch prediction](https://github.com/tirth-byte/galaxy-zoo/blob/main/predict.py): Python entry point · Classifies local unseen images and generates stakeholder reports. · `predict.py`
- [Inference preprocessing](https://github.com/tirth-byte/galaxy-zoo/blob/main/predict.py): inference stage · Applies compatible resize and normalization before scoring. · `predict.py`
- [CSV & Excel reports](https://github.com/tirth-byte/galaxy-zoo/tree/main/output): delivery artifact · Master CSV and formatted Excel prediction results. · `output`

### Other components

- [Python dependencies](https://github.com/tirth-byte/galaxy-zoo/blob/main/requirements.txt): dependencies · PyTorch, EfficientNet, and Kaggle runtime packages. · `requirements.txt`
- [Static dashboard](https://github.com/tirth-byte/galaxy-zoo/blob/main/index.html): browser page · Standalone browser dashboard outside the ML runtime. · `index.html`
- [Attendance bot](https://github.com/tirth-byte/galaxy-zoo/blob/main/attendance-bot/package.json): unrelated package · Nested package unrelated to the galaxy pipeline. · `attendance-bot/package.json`

## Connections

- Python dependencies → Dataset preparation: provides runtime
- Python dependencies → Training pipeline: provides runtime
- Kaggle dataset → Dataset preparation: downloads raw data
- Pipeline configuration → Dataset preparation: uses paths & classes
- Dataset preparation → Transforms & loaders: prepared image folders
- Pipeline configuration → Transforms & loaders: uses class contract
- Transforms & loaders → Training pipeline: train/validation batches
- Pipeline configuration → Training pipeline: uses hyperparameters
- Pipeline configuration → EfficientNet-B0 model: sets output classes
- EfficientNet-B0 model → Training pipeline: instantiated for training
- Training pipeline → Optimization & evaluation: runs
- Optimization & evaluation → Model & diagnostics: writes checkpoint & diagnostics
- CSV training path → Model & diagnostics: may produce training artifacts
- Pipeline configuration → Batch prediction: supplies labels & paths
- Model & diagnostics → Batch prediction: reloads trained checkpoint
- Batch prediction → Inference preprocessing: processes input files
- EfficientNet-B0 model → Inference preprocessing: produces logits
- Inference preprocessing → CSV & Excel reports: writes labels & probabilities
