# amazingdd/ecc-snn architecture

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

- Interactive diagram: https://gitdiagram.com/amazingdd/ecc-snn
- Repository: https://github.com/amazingdd/ecc-snn

## Overview

##### Project type and purpose
- ECC-SNN is a research-oriented machine-learning pipeline implementing cost-effective edge-cloud collaboration for spiking neural networks.
- It provides Python scripts to prepare data, train and update edge/cloud models, and evaluate performance under different offloading thresholds.

##### File structure
- Top-level Python entry points:
- prepare.py (data & model initialization)
- update.py (task-by-task model updates)
- evaluation.py (performance measurement with thresholding)
- models/ directory: definitions of base networks (ResNet, VGG, ViT) and their spiking variants.
- scripts/ directory: utilities for I/O (imagenet_io.py), latency measurement, model inference, and a lightweight service wrapper.
- utils.py: shared helper functions.

##### README for additional insights
- The workflow is organized in two stages: Setup (prepare.py) and Running (update.py → evaluation.py).
- Edge-cloud collaboration is controlled by parameters (–cloud, –edge, –thr).
- Pretraining, distillation, and patience hyperparameters govern the training pipeline.

##### Elements
- Clear labels for each component (e.g., “Edge Spiking NN”, “Cloud ViT Service”)
- Dataset → Trainer
- Trainer → Model Checkpoints
- Edge Inference → Decision → [Local/Cloud] → Result
- Blue rectangles for compute modules (prepare/update/eval)
- Orange parallelograms for decision points

## Diagram (Mermaid)

```mermaid
graph TD
    %% Data & Models Layer
    subgraph "Data & Models"
        direction TB
        Dataset["ImageNet/CIFAR-100 Data"]:::data
        PrepareData["Data Prep & Loader\n(prepare.py & imagenet_io)"]:::compute
        click PrepareData "https://github.com/amazingdd/ecc-snn/blob/main/prepare.py"
        click PrepareData "https://github.com/amazingdd/ecc-snn/blob/main/scripts/imagenet_io.py"
        
        subgraph "Model Zoo"
            direction TB
            Base["Base Model API\n(models/base.py)"]:::compute
            click Base "https://github.com/amazingdd/ecc-snn/blob/main/models/base.py"
            CloudResNet["ResNet\n(models/resnet.py)"]:::compute
            click CloudResNet "https://github.com/amazingdd/ecc-snn/blob/main/models/resnet.py"
            CloudVGG["VGG\n(models/vgg.py)"]:::compute
            click CloudVGG "https://github.com/amazingdd/ecc-snn/blob/main/models/vgg.py"
            CloudViT["ViT\n(models/vit.py)"]:::compute
            click CloudViT "https://github.com/amazingdd/ecc-snn/blob/main/models/vit.py"
            SpikeResNet["SpikeResNet\n(models/spikeresnet.py)"]:::compute
            click SpikeResNet "https://github.com/amazingdd/ecc-snn/blob/main/models/spikeresnet.py"
            SpikeVGG["SpikeVGG\n(models/spikevgg.py)"]:::compute
            click SpikeVGG "https://github.com/amazingdd/ecc-snn/blob/main/models/spikevgg.py"
            SpikeViT["SpikeViT\n(models/spikevit.py)"]:::compute
            click SpikeViT "https://github.com/amazingdd/ecc-snn/blob/main/models/spikevit.py"
        end
    end

    %% Training & Update Pipeline Layer
    subgraph "Training & Update Pipeline"
        direction TB
        Update["Model Training & Update\n(update.py)"]:::compute
        click Update "https://github.com/amazingdd/ecc-snn/blob/main/update.py"
        Checkpoints["Model Checkpoints"]:::data
    end

    %% Runtime Inference & Decision Layer
    subgraph "Runtime Inference & Decision"
        direction TB
        EdgeInfer["Edge Spiking NN Inference\n(scripts/model_infer.py)"]:::compute
        click EdgeInfer "https://github.com/amazingdd/ecc-snn/blob/main/scripts/model_infer.py"
        Decision["Offloading Decision\n(evaluation.py)"]:::decision
        click Decision "https://github.com/amazingdd/ecc-snn/blob/main/evaluation.py"
        CloudService["Cloud Inference Service\n(scripts/service.py)"]:::service
        click CloudService "https://github.com/amazingdd/ecc-snn/blob/main/scripts/service.py"
        ResultEdge["Edge Prediction Result"]:::compute
    end

    %% Evaluation & Metrics Layer
    subgraph "Evaluation & Metrics"
        direction TB
        Evaluation["Evaluation & Metrics Collector\n(evaluation.py)"]:::compute
        click Evaluation "https://github.com/amazingdd/ecc-snn/blob/main/evaluation.py"
        LatencyEval["Latency Measurement\n(scripts/latency_eval.py)"]:::compute
        click LatencyEval "https://github.com/amazingdd/ecc-snn/blob/main/scripts/latency_eval.py"
    end

    %% Utility Layer
    Utils["Shared Utilities\n(utils.py)"]:::compute
    click Utils "https://github.com/amazingdd/ecc-snn/blob/main/utils.py"

    %% Connections
    Dataset --> PrepareData
    PrepareData --> Update
    Base --> Update
    CloudResNet --> Update
    CloudVGG --> Update
    CloudViT --> Update
    SpikeResNet --> Update
    SpikeVGG --> Update
    SpikeViT --> Update
    Update --> Checkpoints

    Checkpoints --> EdgeInfer
    EdgeInfer --> Decision
    Decision -->|confidence>=thr| ResultEdge
    Decision -.->|confidence<thr| CloudService
    CloudService --> Decision
    Decision --> ResultEdge

    ResultEdge --> Evaluation
    ResultEdge --> LatencyEval
    Evaluation --> LatencyEval

    Utils --> PrepareData
    Utils --> Update
    Utils --> EdgeInfer
    Utils --> Decision
    Utils --> Evaluation

    %% Styles
    classDef compute fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef data fill:#98FB98,stroke:#000,stroke-width:1px
    classDef decision fill:#FFA500,stroke:#000,stroke-width:1px
    classDef service fill:#FFD700,stroke:#000,stroke-width:1px
```
