# Dendritic MobileNet Project

## Overview
This project enhances a **MobileNetV3-Small** computer vision model by integrating **Dendritic Computing** concepts using the [PerforatedAI](https://github.com/PerforatedAI/PerforatedAI) library. 

Developed for the **Perforated AI Dendritic Optimization Hackathon**, this project demonstrates how adding artificial dendrites to standard PyTorch models can potentially improve accuracy or parameter efficiency ("smarter, smaller, cheaper") for edge vision tasks.



## Project Impact
Optimizing computer vision models for edge devices is critical for applications where bandwidth, privacy, or latency are constraints. By demonstrating that dendritic integration can improve accuracy without a proportional increase in computational cost (or maintain accuracy with fewer parameters), this project paves the way for smarter IoT devices, efficient surveillance systems, and responsive autonomous agents that can run complex vision tasks locally.

## Usage Instructions

### Installation

1.  **Clone the Repository**:
    ```bash
    git clone https://github.com/PerforatedAI/PerforatedAI.git
    cd PerforatedAI/Examples/hackathonProjects/dendritic_mobilenet
    ```

2.  **Install Dependencies**:
    ```bash
    pip install -r requirements.txt
    ```


### Running the Training
To train the model and generate the results graph:

```bash
# Ensure PerforatedAI is in your PYTHONPATH
export PYTHONPATH=$PYTHONPATH:/path/to/PerforatedAI

# Standard Training (Optimal Hyperparameters)
python train.py
```

### Running the Dataset Split Benchmark (New!)
To compare **Standard vs. Dendritic MobileNet** across varying dataset sizes (10% to 100%), use the benchmark script:

```bash
# Fast Verification (1 Epoch per split)
python run_benchmark.py --epochs 1

# Full Benchmark (15 Epochs per split)
python run_benchmark.py --epochs 15
```

## Hyperparameter Sweep
This project is configured to run a **WandB Sweep** automatically. The `train.py` script initializes a sweep controller and agent to test Dendrite Counts, Batch Sizes, and Learning Rates.

## Results

### Overall Performance (Optimal Configuration)
| Metric | Baseline (MobileNetV3-Small) | Dendritic (8 Dendrites) |
| :--- | :--- | :--- |
| **Parameters** | ~1.5M | ~4.1M |
| **Validation Accuracy** | *89.23% (Baseline)* | **91.42%** |

*Note: Baseline accuracy is from the model before dendritic switching. Dendritic results are from our actual hackathon training runs.*



### Remaining Error Reduction
Moving from 89.23% accuracy (10.77% error) to 91.42% accuracy (8.58% error) represents a significant reduction in error.
Error Reduction: (10.77 - 8.58) / 10.77 ≈ **20.3% reduction in error**.

## Raw Results Graph
The graph below is automatically generated by the Perforated AI library during training. It confirms the correct addition of dendrites and visualizes the training progress.

![Raw Results Graph](dendrites_8_bs_64_lr_0_001.png)

## Weights and Biases Sweep Report
[W&B Sweep Report](https://wandb.ai/raghunathsundar1-chennai-institute-of-technology/hackathon-dendritic-vision)

### Example Training Run
[View 50-Epoch Run Details](https://wandb.ai/raghunathsundar1-chennai-institute-of-technology/PerforatedAI-Examples_hackathonProjects_dendritic_mobilenet/runs/lzzrpiyc)

## Project Structure
- `model.py`: Defines the `DendriticVisionModel` class.
- `train.py`: Main training script with WandB integration and dataset splitting logic.
- `run_benchmark.py`: Orchestrator script for running the multi-split comparison.
- `requirements.txt`: Project dependencies.


