# huaxiaozhong1/tensorflow-lite-apps-on-raspberry-pi-3 architecture

> Architecture diagram of the GitHub repository huaxiaozhong1/tensorflow-lite-apps-on-raspberry-pi-3, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/huaxiaozhong1/tensorflow-lite-apps-on-raspberry-pi-3
- Repository: https://github.com/huaxiaozhong1/tensorflow-lite-apps-on-raspberry-pi-3

## Overview

##### Main Components
- Docker Build Environment (Host):
- Ubuntu 18.04 host running a Docker container based on the tensorflow/tensorflow:1.12.0-devel image.
- Inside the container, note that the project uses a modified build setup: the new Makefile (found in the “make” folder) and additional source code under the “camera” directory (for camera image processing).
- Cross-compilation tool-chain installation (e.g., crossbuild-essential-armhf), which allows building for ARM targets.
- Downloading of TensorFlow Lite dependencies, and the building process that generates libtensorflow-lite.a and the demo executables.

- Static Libraries & External Dependencies:
- Static ARM libraries (from the “arm-linux-gnueabihf” directory) such as libjpeg.a, librt.a, and those for video4linux (libv4l* libraries). These libraries are copied from the Pi board (or provided in the repository) into the container.
- External dependencies (like libjpeg-dev and libv4l-dev) that are installed both in the container and on the Pi board.

- Demo Applications Components:
- Two demo apps: “camera” and “label_image” (source code in “camera” and “label_image” directories). The “camera” app includes functions for handling bitmap images (helpers and label integration) while “label_image” might be focused on running image classification.
- The “data” directory contains assets (an image, a labels file, and a mobilenet_v2 TFLite model) required by the apps.
- The “test” directory provides example logs from running these applications which helps indicate expected results.

- Raspberry Pi 3 Execution Environment:
- Raspberry Pi 3 board as a separate execution unit running Raspbian. On the board, the built executables along with the necessary assets (copied from the host’s container) are run.
- Attached camera and NFS setups used to share files between the host and board.

##### Architectural Patterns & Design Principles
- Separation of concerns:
- The build process (Docker container with TensorFlow Lite tools and modified Makefile) is entirely separate from the runtime environment (Raspberry Pi 3 board).
- The “camera” and “label_image” modules are modular demo apps which can be represented as distinct components that leverage the shared TensorFlow Lite library (libtensorflow-lite.a).
- That the system utilizes a cross-compilation pattern for embedded systems, with clear segregation between the host build environment and the target deployment environment.

##### Relevant Technologies & Frameworks
- Docker for containerized build environment,
- TensorFlow Lite (v1.12.0) as the underlying ML framework,
- Cross-compilation toolchain (crossbuild-essential-armhf),
- Libraries for image processing and camera handling (e.g., libjpeg, libv4l family),
- Raspbian OS on Raspberry Pi 3 as the target execution platform.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build Environment (Host)
    subgraph "Build Environment (Host: Ubuntu 18.04)"
        subgraph "Docker Container (tensorflow/tensorflow:1.12.0-devel)"
            build["Docker Build Process\n(Cross-compilation Setup & Build)"]:::build
            make_file["Modified Makefile"]:::file
            cross["Cross-compilation Toolchain\n(crossbuild-essential-armhf)"]:::tool
            tf_build["Build Process:\nDownloads TF Lite deps, builds libtensorflow-lite.a\nand demo executables"]:::process
        end
    end

    %% ARM Libraries & External Dependencies
    subgraph "ARM Libraries & Dependencies"
        libs["Static ARM Libraries\n(e.g., libjpeg.a, librt.a, libv4l* libs)"]:::lib
        deps["External Dependencies\n(libjpeg-dev, libv4l-dev)"]:::dep
    end

    %% Demo Applications
    subgraph "Demo Applications"
        camera["Camera Application\n(Image Processing & Bitmap Helpers)"]:::app
        label["Label Image Application\n(Image Classification)"]:::app
    end

    %% Data Assets & Test Logs
    subgraph "Data & Tests"
        data["Data Assets\n(Model, Image, Labels)"]:::data
        tests["Test Logs\n(Example Execution Logs)"]:::test
    end

    %% Execution Environment (Raspberry Pi 3)
    subgraph "Execution Environment (Raspberry Pi 3 - Raspbian)"
        pi["Raspberry Pi 3"]:::pi
        demo["Demo Executables\n(camera & label_image)"]:::app2
        nfs["NFS Shared Files"]:::nfs
        camera_device["Attached Camera"]:::device
    end

    %% Build Pipeline Connections inside Docker Container
    build -->|"Invokes"| make_file
    make_file -->|"Initiates"| cross
    cross -->|"Compiles to produce"| tf_build

    %% Linking with static libraries
    tf_build -->|"Links with"| libs
    libs <-->|"Provided along"| deps

    %% Deployment to Raspberry Pi
    tf_build -->|"Deploys executables & libs"| pi
    pi -->|"Runs"| demo

    %% Runtime Flow for Demo Applications
    camera -->|"Uses"| data
    label -->|"Uses"| data

    %% Additional Pi connections
    pi -->|"Shares files via"| nfs
    pi -->|"Operates with"| camera_device

    %% Styling Classes
    classDef build fill:#F9E79F,stroke:#BA4A00,stroke-width:2px;
    classDef process fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef tool fill:#FDEBD0,stroke:#E67E22,stroke-width:2px;
    classDef file fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef lib fill:#D5F5E3,stroke:#2ECC71,stroke-width:2px;
    classDef dep fill:#D6EAF8,stroke:#3498DB,stroke-width:2px;
    classDef app fill:#FADBD8,stroke:#E74C3C,stroke-width:2px;
    classDef data fill:#FCF3CF,stroke:#F1C40F,stroke-width:2px;
    classDef test fill:#EBDEF0,stroke:#AF7AC5,stroke-width:2px;
    classDef pi fill:#D6DBDF,stroke:#7B7D7D,stroke-width:2px;
    classDef app2 fill:#FDEDEC,stroke:#E74C3C,stroke-width:2px;
    classDef nfs fill:#F0E68C,stroke:#B7950B,stroke-width:2px;
    classDef device fill:#AED6F1,stroke:#2471A3,stroke-width:2px;

    %% Click Events for Component Mapping
    click make_file "https://github.com/huaxiaozhong1/tensorflow-lite-apps-on-raspberry-pi-3/tree/master/make/Makefile"
    click libs "https://github.com/huaxiaozhong1/tensorflow-lite-apps-on-raspberry-pi-3/tree/master/arm-linux-gnueabihf"
    click camera "https://github.com/huaxiaozhong1/tensorflow-lite-apps-on-raspberry-pi-3/tree/master/camera"
    click label "https://github.com/huaxiaozhong1/tensorflow-lite-apps-on-raspberry-pi-3/tree/master/label_image"
    click data "https://github.com/huaxiaozhong1/tensorflow-lite-apps-on-raspberry-pi-3/tree/master/data"
    click tests "https://github.com/huaxiaozhong1/tensorflow-lite-apps-on-raspberry-pi-3/tree/master/test"
```
