# idealo/image-quality-assessment architecture

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

- Interactive diagram: https://gitdiagram.com/idealo/image-quality-assessment
- Repository: https://github.com/idealo/image-quality-assessment

## Overview

##### Main Components
- Data / Datasets: Represent the datasets (AVA and TID2013) and label files (stored in the data directory) that are used for training and evaluation.
- Model Configuration & Weight Storage: Show the “models/MobileNet” folder where you store configuration JSON files and HDF5 weights.
- Training Module: Capture the training pipelines split into local training (via the “train-local” script) and remote training on AWS EC2 (via the “train-ec2” script). Also include the “src/trainer” module which contains the training code and “src/handlers” for data generation, configuration loading, and model construction.
- Prediction Module: Represent the prediction interface provided either by running the “predict” script (with Docker image “nima-cpu”) or by using the evaluation code under “src/evaluater”. Also note the dedicated testing images and the sample client for TF Serving.
- TensorFlow Serving Component: Highlight the “contrib/tf_serving” directory which contains the Dockerfile, configuration, and client scripts to deploy the model via TensorFlow Serving.
- Docker & Container Infrastructure: Include the Dockerfiles (for CPU, GPU, and TFS), entrypoint scripts, and the integration with AWS (via Docker Machine and nvidia-docker on EC2) as separate components responsible for encapsulating and orchestrating the runtime environment.
- Documentation & Developer Tools: Include mkdocs (documentation) and configuration/build scripts (e.g., .travis.yml, CONTRIBUTING.md) for CI/CD and community involvement.

##### Relationships and Data Flows
- Data flows from datasets (data directory) into the training module. During training, the system uses model configurations (from the “models” directory) and generates output (trained model weights, logs, and evaluation metrics from “src/evaluater”) that are stored locally or pushed to S3 (as mentioned for EC2 training).
- The training process is started either via local or remote entrypoint scripts, which run inside Docker containers (indicated by the Dockerfiles and entrypoint scripts).
- For inference, the trained models are either invoked by the “predict” script which triggers a Docker container with “nima-cpu”, or they are deployed via the TensorFlow Serving container (built from “contrib/tf_serving/Dockerfile”), with predictions being served to external clients through the sample API calls.
- External clients (or testing pipelines) interact with the prediction endpoints and obtain image quality ratings.
- Developer documentation (via mkdocs) and community contribution guidelines (in CONTRIBUTING.md) are maintained separately.

##### Architectural Patterns & Design Principles
- Separation of Concerns: The design clearly separates the training (model building, evaluation) from prediction (inference serving), and further distinguishes local versus remote training workflows.
- Containerization: Use of Docker (with separate images for CPU, GPU, and TF Serving) encapsulates environment dependencies and ensures reproducibility across platforms.
- Modularity: The project architecture is modular – with distinct directories for data handling, model configuration, training routines, and serving scripts.
- Extensibility: The presence of configuration files and contribution guidelines suggests that new model architectures (e.g., switching the base model from MobileNet to InceptionV3) can be integrated with minimal impact on the overall system.
- Cloud Integration: Specific design for training remotely on AWS EC2 emphasizes the system’s ability to scale and integrate with cloud resources, including considerations for GPU instance orchestration and S3 storage.

##### Elements
- Each functional component (Data Provider, Trainer, Predictor, TF Serving, Documentation)
- Distinct layouts or sections for local environment versus cloud-based (EC2) workflows.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data & Model Storage
    subgraph "Data & Model Storage"
        datasets["Data / Datasets"]:::data
        modelConfig["Model Config & Weights"]:::data
    end

    %% Training Module
    subgraph "Training Module"
        trainer["Training Code: src/trainer/train.py"]:::training
        handlers["Handlers: src/handlers"]:::training
        trainLocal["Local Training Script: train-local"]:::training
        trainEC2["Remote Training Script: train-ec2"]:::training
    end

    %% Prediction Module
    subgraph "Prediction Module"
        predCode["Prediction Code: src/evaluater/predict.py"]:::prediction
        predScript["Prediction Entry Script: entrypoints/entrypoint.predict.cpu.sh"]:::prediction
    end

    %% TensorFlow Serving Component
    subgraph "TensorFlow Serving"
        tfServing["TF Serving: contrib/tf_serving"]:::serving
    end

    %% Docker & Container Infrastructure
    subgraph "Docker & Container Infrastructure"
        docker_cpu["Dockerfile (CPU): Dockerfile.cpu"]:::docker
        docker_gpu["Dockerfile (GPU): Dockerfile.gpu"]:::docker
        entryCpu["Entrypoint CPU: entrypoints/entrypoint.train.cpu.sh"]:::docker
        entryGpu["Entrypoint GPU: entrypoints/entrypoint.train.gpu.sh"]:::docker
    end

    %% Documentation & Developer Tools
    subgraph "Documentation & Dev Tools"
        docs["Documentation: mkdocs/"]:::docs
        ciCd["CI/CD: .travis.yml"]:::docs
        contrib["Community Guidelines: CONTRIBUTING.md"]:::docs
    end

    %% External Users
    external["External Clients"]:::external

    %% Data Flow Connections
    datasets -->|"training_data"| trainer
    modelConfig -->|"config_inputs"| trainer
    trainLocal -->|"triggers"| trainer
    trainEC2 -->|"triggers"| trainer
    handlers -->|"supports"| trainer
    trainer -->|"trained_model"| modelConfig
    trainer -->|"outputs_weights"| predCode
    trainer -->|"outputs_weights"| tfServing

    %% Prediction and Serving Connections
    predScript -->|"inference"| external
    tfServing -->|"serving_predictions"| external

    %% Docker Infrastructure Integration
    docker_cpu -->|"builds"| entryCpu
    docker_gpu -->|"builds"| entryGpu
    entryCpu -->|"launches"| trainer
    entryGpu -->|"launches"| trainer
    predScript ---|"containerized"| docker_cpu

    %% Styles
    classDef data fill:#a8dadc,stroke:#457b9d,stroke-width:2px;
    classDef training fill:#a3de83,stroke:#2d6a4f,stroke-width:2px;
    classDef prediction fill:#ffeb99,stroke:#f4a261,stroke-width:2px;
    classDef serving fill:#f4a261,stroke:#e76f51,stroke-width:2px;
    classDef docker fill:#ececec,stroke:#333,stroke-width:2px;
    classDef docs fill:#d8bfd8,stroke:#8a2be2,stroke-width:2px;
    classDef external fill:#f1faee,stroke:#1d3557,stroke-width:2px;

    %% Click Events
    click datasets "https://github.com/idealo/image-quality-assessment/tree/master/data/"
    click modelConfig "https://github.com/idealo/image-quality-assessment/tree/master/models/MobileNet"
    click trainer "https://github.com/idealo/image-quality-assessment/blob/master/src/trainer/train.py"
    click handlers "https://github.com/idealo/image-quality-assessment/tree/master/src/handlers/"
    click trainLocal "https://github.com/idealo/image-quality-assessment/tree/master/train-local"
    click trainEC2 "https://github.com/idealo/image-quality-assessment/tree/master/train-ec2"
    click predCode "https://github.com/idealo/image-quality-assessment/blob/master/src/evaluater/predict.py"
    click predScript "https://github.com/idealo/image-quality-assessment/blob/master/entrypoints/entrypoint.predict.cpu.sh"
    click tfServing "https://github.com/idealo/image-quality-assessment/tree/master/contrib/tf_serving"
    click docker_cpu "https://github.com/idealo/image-quality-assessment/blob/master/Dockerfile.cpu"
    click docker_gpu "https://github.com/idealo/image-quality-assessment/blob/master/Dockerfile.gpu"
    click entryCpu "https://github.com/idealo/image-quality-assessment/blob/master/entrypoints/entrypoint.train.cpu.sh"
    click entryGpu "https://github.com/idealo/image-quality-assessment/blob/master/entrypoints/entrypoint.train.gpu.sh"
    click docs "https://github.com/idealo/image-quality-assessment/tree/master/mkdocs/"
    click ciCd "https://github.com/idealo/image-quality-assessment/blob/master/.travis.yml"
    click contrib "https://github.com/idealo/image-quality-assessment/blob/master/CONTRIBUTING.md"
```
