# google-ai-edge/models-samples architecture

> Architecture diagram of the GitHub repository google-ai-edge/models-samples, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/google-ai-edge/models-samples
- Repository: https://github.com/google-ai-edge/models-samples

## Overview

##### Project type and purpose
- This is a collection of sample pipelines (JAX and PyTorch) for converting AI models to TensorFlow Lite, designed to run in Google Colab.
- It is not a full-stack application or microservice system, but a set of data-processing/conversion workflows.

##### File structure
- Top-level directories:
– convert_jax: contains a Jupyter notebook to convert a JAX-trained MNIST model to TFLite.
– convert_pytorch: contains multiple notebooks illustrating segmentation and classification model conversion to TFLite.
- No backend/frontend separation; this is purely batch-style data pipelines.
- No deployment manifests or service configurations—execution happens interactively in Colab.

##### README for additional insights
- Confirms purpose: run these notebooks in personal Google accounts, download pre-trained PyTorch models, convert them to TFLite.
- Implied dependencies: PyTorch, JAX, TensorFlow, TFLite converter, Google Drive or Colab storage.

##### Main components
a. Environment layer
– Google Colab VM (host for execution)
– Storage: Colab local disk or Google Drive mount
b. Model source layer
– Pre-trained JAX MNIST model (remote URL/storage)
– Pre-trained PyTorch models (ConvNeXt V2, MobileViT, SegNext, DIS)
c. Conversion pipeline components
– Notebook runtime: Python + required libs (torch, jax, tensorflow, tflite-converter)
– Data loading module (download or mount storage)
– Conversion scripts/functions (e.g., PyTorch→ONNX→TensorFlow→TFLite or JAX→TensorFlow→TFLite)
d. Output artifacts
– TensorFlow Lite (.tflite) model files
– Quantized variants (if quantization steps included)

##### Architectural patterns and design principles
- Pipeline pattern: sequential stages (load → convert → optimize → export)
- Reusable conversion functions shared across notebooks
- Isolation per notebook (each sample runs independently)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Environment Layer
    subgraph "Environment Layer"
        direction TB
        ColabVM["Google Colab VM"]:::environment
        PythonRuntime["Python Runtime<br/>(torch-1.x, jax, tf-2.x, tflite-converter)"]:::environment
    end

    ColabVM --> PythonRuntime
    PythonRuntime --> Download

    %% Model Source Layer
    subgraph "Model Source Layer"
        direction TB
        JAXModel["Pre-trained JAX MNIST Model"]:::data
        PyTorchModels["Pre-trained PyTorch Models"]:::data
    end

    JAXModel --> JAXNotebook
    PyTorchModels --> PTNotebooks

    %% JAX Conversion Pipeline
    subgraph "JAX Conversion Pipeline"
        direction TB
        JAXNotebook["JAX Conversion Notebook"]:::process
        DownloadJAX["Download Weights"]:::process
        ConvertJAX["Convert JAX→TensorFlow"]:::process
        QuantizeJAX["Quantize (optional)"]:::process
        ExportJAX["Export .tflite"]:::output
    end

    JAXNotebook --> DownloadJAX --> ConvertJAX --> QuantizeJAX --> ExportJAX

    %% PyTorch Conversion Samples
    subgraph "PyTorch Conversion Samples"
        direction TB
        PTNotebooks["Entry Point Notebooks"]:::process
        subgraph "Notebooks"
            direction TB
            DISNotebook["DIS Segmentation & Quantization"]:::process
            ConvNextNotebook["ConvNeXt V2 Classification"]:::process
            MobileViTNotebook["MobileViT Classification"]:::process
            SegNextNotebook["SegNext Segmentation & Quantization"]:::process
        end
        DownloadPT["Download Weights"]:::process
        ConvertPT["Convert PyTorch→ONNX→TF"]:::process
        QuantizePT["Quantize (optional)"]:::process
        ExportPT["Export .tflite"]:::output
    end

    PTNotebooks --> DISNotebook
    PTNotebooks --> ConvNextNotebook
    PTNotebooks --> MobileViTNotebook
    PTNotebooks --> SegNextNotebook
    DISNotebook --> DownloadPT
    ConvNextNotebook --> DownloadPT
    MobileViTNotebook --> DownloadPT
    SegNextNotebook --> DownloadPT
    DownloadPT --> ConvertPT --> QuantizePT --> ExportPT

    %% Storage Layer
    subgraph "Storage"
        direction TB
        Drive["Google Drive Mount"]:::environment
        LocalDisk["Colab Local Disk"]:::environment
        TFLiteArtifacts[".tflite Artifacts"]:::output
    end

    PythonRuntime --> Drive
    PythonRuntime --> LocalDisk
    ExportJAX --> TFLiteArtifacts
    ExportPT --> TFLiteArtifacts
    TFLiteArtifacts --> Drive

    %% Documentation
    README["Project README & Dependencies"]:::data

    %% Click Events
    click JAXNotebook "https://github.com/google-ai-edge/models-samples/blob/main/convert_jax/JAX_MNIST_to_LiteRT.ipynb"
    click DISNotebook "https://github.com/google-ai-edge/models-samples/blob/main/convert_pytorch/DIS_segmentation_and_quantization.ipynb"
    click ConvNextNotebook "https://github.com/google-ai-edge/models-samples/blob/main/convert_pytorch/Image_classification_with_convnext_v2.ipynb"
    click MobileViTNotebook "https://github.com/google-ai-edge/models-samples/blob/main/convert_pytorch/Image_classification_with_mobile_vit.ipynb"
    click SegNextNotebook "https://github.com/google-ai-edge/models-samples/blob/main/convert_pytorch/SegNext_segmentation_and_quantization.ipynb"
    click README "https://github.com/google-ai-edge/models-samples/blob/main/README.md"

    %% Styles
    classDef environment fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef data fill:#90EE90,stroke:#000,stroke-width:1px
    classDef process fill:#FFA500,stroke:#000,stroke-width:1px
    classDef output fill:#D3D3D3,stroke:#000,stroke-width:1px
```
