# wtglad/deep_sheep architecture

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

- Interactive diagram: https://gitdiagram.com/wtglad/deep_sheep
- Repository: https://github.com/wtglad/deep_sheep

## Overview

##### Project type and purpose
- This is a machine-learning classification system (“Deep Sheep”) for sorting sheep vs. non-sheep water-drinker images.
- It provides both training and inference functionality, with packaging for distribution (via PyPI) and a special trainer implementation targeting Google Cloud Platform (GCP).

##### File structure
Top‐level files:
- basic_test/…      – local test assets or unit tests for quick iteration
- classifier.py      – the inference interface (loads a trained model, runs prediction)
- deep_sheep.py      – CLI entry point for end users
- model_trainer.py   – local trainer abstraction for offline experimentation
- requirements.txt   – Python dependencies
- readme.md          – high-level overview and documentation pointer
ds-gcp package (for GCP training + distribution):
- setup.py           – packaging config for PyPI
- dist/…             – built sdist (deep_sheep-0.1.tar.gz)
- deep_sheep.egg-info/… – metadata for the package
- trainer/model_trainer_gcp.py – trainer implementation that spins up GCP resources (e.g., Cloud Storage, AI Platform).

##### README for additional context
- Confirms the goal: sort sheep images vs non-sheep.
- Points to a Google Doc for more detailed architecture/usage.
- Encourages community feedback.

##### Main components
a. Data Sources & Storage
- Raw image store (local folder or Google Cloud Storage bucket).
- Labeled dataset repository (e.g., CSV or TFRecords).
b. Data Preprocessing
- Scripts (inside model_trainer.py or GCP trainer) that resize/augment images.
c. Model Training
- Local Trainer (model_trainer.py) – runs on developer’s machine.
- GCP Trainer (trainer/model_trainer_gcp.py) – submits jobs to GCP AI Platform, reads/writes to Cloud Storage.
d. Model Artifact Storage
- Local FS (for dev) or GCP bucket (for production).
e. Packaging & Deployment
- setup.py + dist/… → PyPI package “deep_sheep”.
- Versioning and metadata (deep_sheep.egg-info).
f. Inference / Classification
- CLI entry point (deep_sheep.py) calls classifier.py
- classifier.py loads model artifact, processes input images, returns labels.
g. Optional Monitoring / Logging (implied for production GCP jobs).

##### Relationships and data flows
1) Data ingestion → preprocessing → model training
2) Training job writes model artifact → artifact stored in bucket
3) setup.py packages code → published to PyPI → installed by end users
4) CLI (deep_sheep.py) uses installed package → classifier loads model from local or remote storage → returns predictions

##### Architectural patterns and design principles
- Separation of concerns: training vs inference code in different modules.
- Modular packaging: all core logic lives under a distributable Python package (ds-gcp).
- Cloud‐native training: trainer abstraction lets you swap local vs GCP without touching core logic.
- CLI abstraction: single entry point (deep_sheep.py) for end users.

##### Detail level
- Under “GCP Trainer” indicate external services: “Cloud Storage”, “AI Platform Training Job”.
- Local developer environment separately from cloud infrastructure.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Data & Storage"
        RawLocal["Raw Image Store (Local)"]:::data
        RawGCS["Raw Image Store (GCS Bucket)"]:::data
        Labeled["Labeled Dataset (CSV/TFRecords)"]:::data
    end

    subgraph "Preprocessing"
        Preprocessor["Preprocessor\n(resize, augment, normalize)"]:::compute
    end

    subgraph "Training"
        LocalTrainer["Local Trainer\n(model_trainer.py)"]:::compute
        GCPTrainer["GCP Trainer\n(trainer/model_trainer_gcp.py)"]:::compute
        CloudStorage["Cloud Storage"]:::data
        AIPlatform["AI Platform Training Job"]:::compute
    end

    subgraph "Model Artifact Storage"
        LocalFS["Model Artifacts (Local)"]:::data
        GCSArtifacts["Model Artifacts (GCS Bucket)"]:::data
    end

    subgraph "Packaging & Deployment"
        Setup["setup.py"]:::packaging
        Dist["sdist (deep_sheep-0.1.tar.gz)"]:::packaging
        EggInfo["deep_sheep.egg-info"]:::packaging
    end

    subgraph "Inference / CLI"
        CLI["CLI Entry Point\n(deep_sheep.py)"]:::inference
        Classifier["Classifier Module\n(classifier.py)"]:::inference
    end

    Tests["basic_test/"]:::data
    Readme["readme.md"]:::data
    Requirements["requirements.txt"]:::data

    RawLocal --> Preprocessor
    RawGCS --> Preprocessor
    Labeled --> Preprocessor

    Preprocessor --> LocalTrainer
    Preprocessor --> GCPTrainer

    GCPTrainer --> CloudStorage
    GCPTrainer --> AIPlatform
    AIPlatform --> CloudStorage

    LocalTrainer --> LocalFS
    CloudStorage --> GCSArtifacts

    Setup --> Dist
    Setup --> EggInfo

    CLI -.-> Classifier
    Classifier --> LocalFS
    Classifier --> GCSArtifacts

    Tests --> LocalTrainer
    Requirements --> LocalTrainer
    Requirements --> Setup

    click CLI "https://github.com/wtglad/deep_sheep/blob/main/deep_sheep.py"
    click Classifier "https://github.com/wtglad/deep_sheep/blob/main/classifier.py"
    click LocalTrainer "https://github.com/wtglad/deep_sheep/blob/main/model_trainer.py"
    click GCPTrainer "https://github.com/wtglad/deep_sheep/blob/main/ds-gcp/trainer/model_trainer_gcp.py"
    click Setup "https://github.com/wtglad/deep_sheep/blob/main/ds-gcp/setup.py"
    click Dist "https://github.com/wtglad/deep_sheep/blob/main/ds-gcp/dist/deep_sheep-0.1.tar.gz"
    click EggInfo "https://github.com/wtglad/deep_sheep/tree/main/ds-gcp/deep_sheep.egg-info/"
    click Tests "https://github.com/wtglad/deep_sheep/tree/main/basic_test/"
    click Readme "https://github.com/wtglad/deep_sheep/blob/main/readme.md"
    click Requirements "https://github.com/wtglad/deep_sheep/blob/main/requirements.txt"

    classDef data fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef compute fill:#90EE90,stroke:#000,stroke-width:1px
    classDef packaging fill:#FFA500,stroke:#000,stroke-width:1px
    classDef inference fill:#DDA0DD,stroke:#000,stroke-width:1px
```
