# seraj94ai/a-self-driving-car-using-behavioral-cloning architecture

> Architecture diagram of the GitHub repository seraj94ai/a-self-driving-car-using-behavioral-cloning, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/seraj94ai/a-self-driving-car-using-behavioral-cloning
- Repository: https://github.com/seraj94ai/a-self-driving-car-using-behavioral-cloning

## Overview

##### Project Type and Purpose
- This is an offline ML-based self-driving car pipeline centered on behavioral cloning.
- It consists of two distinct phases:
a. Offline Model Development (data ingestion → preprocessing/augmentation → training)
b. Online Inference & Control (load trained model → receive camera frames → predict steering → send commands to simulator/car)

##### Main Components
A. Data Storage
- IMG/ directory (raw camera images from left, center, right)
- driving_log.csv (CSV mapping image paths → steering angles, throttle, brake, speed)
B. Data Processing & Augmentation
- self_driving.ipynb (Jupyter notebook containing Python routines for:
- Reading CSV + loading images
- Data augmentation (brightness jitter, flipping, panning, zoom)
)
C. Model Training
- NVIDIA-inspired convolutional neural network implemented in Keras/TensorFlow inside the notebook
- Training loop, validation, and final export of weights to model.h5
D. Model Artifact
- model.h5 (serialized Keras model weights & architecture)
E. Inference & Control
- drive.py (Python script that:
- Loads model.h5
- Connects to Udacity self-driving car simulator or real vehicle via network socket/WebSocket
- Streams camera frames, calls model.predict(), emits steering/throttle commands
)
F. Simulator / Vehicle
- External service: Udacity Self-Driving Car Simulator or onboard car hardware

##### Architectural Patterns & Principles
- Separation of Concerns:
- Offline pipeline (data & training) is decoupled from runtime pipeline (inference & control)
- Reproducibility:
- Model artifact (model.h5) acts as the single source of truth for inference
- Data Flow Orientation:
- Linear ML pipeline with clearly demarcated stages

##### Detail Level
- Do not omit the simulator interface: it’s crucial to show the real-time loop of frames in → predictions out.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layer 1: Data Storage
    subgraph "Data Storage"
        direction TB
        IMG["IMG/"]:::datastore
        driving_log["driving_log.csv"]:::datastore
    end

    %% Layer 2 & 3: Processing, Augmentation & Training
    subgraph "Data Processing & Training"
        direction TB
        Notebook["self_driving.ipynb\n(Jupyter Notebook)"]:::process

        subgraph "Preprocessing & Augmentation"
            direction TB
            Crop["Crop"]:::process
            Resize["Resize"]:::process
            Color["Color Conversion"]:::process
            Augment["Augmentation\n(brightness, flip,\npan, zoom)"]:::process
        end

        Training["Model Training\n(CNN with Keras/TensorFlow)"]:::process
    end

    %% Layer 4: Model Artifact
    Model["model.h5"]:::datastore

    %% Layer 5: Inference & Control
    Drive["drive.py\n(Load model & control)"]:::process

    %% Layer 6: Simulator / Vehicle
    Sim["Simulator / Vehicle"]:::external

    %% Documentation
    Doc["README.md"]:::doc

    %% Connections
    IMG -->|"load raw images & logs"| Notebook
    driving_log -->|"load raw images & logs"| Notebook

    Notebook -->|"run preprocessing"| Crop
    Crop --> Resize
    Resize --> Color
    Color --> Augment
    Augment -->|"augmented data batches"| Training

    Training -->|"export model.h5"| Model
    Model -->|"load model weights"| Drive

    Drive -->|"send steering commands"| Sim
    Sim -->|"stream camera frames"| Drive

    Doc --- Notebook

    %% Click Events
    click IMG "https://github.com/seraj94ai/a-self-driving-car-using-behavioral-cloning/tree/master/IMG/"
    click driving_log "https://github.com/seraj94ai/a-self-driving-car-using-behavioral-cloning/blob/master/driving_log.csv"
    click Notebook "https://github.com/seraj94ai/a-self-driving-car-using-behavioral-cloning/blob/master/self_driving.ipynb"
    click Model "https://github.com/seraj94ai/a-self-driving-car-using-behavioral-cloning/blob/master/model.h5"
    click Drive "https://github.com/seraj94ai/a-self-driving-car-using-behavioral-cloning/blob/master/drive.py"
    click Doc "https://github.com/seraj94ai/a-self-driving-car-using-behavioral-cloning/blob/master/README.md"

    %% Styles
    classDef datastore fill:#9f6,stroke:#333,stroke-width:1px;
    classDef process fill:#6cf,stroke:#333,stroke-width:1px;
    classDef external fill:#f96,stroke:#333,stroke-width:1px;
    classDef doc fill:#ccf,stroke:#333,stroke-width:1px;
```
