Delete README.md with huggingface_hub
Browse files
README.md
DELETED
|
@@ -1,135 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
language:
|
| 4 |
-
- en
|
| 5 |
-
pipeline_tag: image-classification
|
| 6 |
-
tags:
|
| 7 |
-
- pytorch
|
| 8 |
-
- edge-ai
|
| 9 |
-
- tinyml
|
| 10 |
-
- custom-architecture
|
| 11 |
-
---
|
| 12 |
-
# SaraNet: A Hardware-Inspired Neural Architecture for Edge AI
|
| 13 |
-
|
| 14 |
-
**SaraNet** (also known as *Nasko's Mirror*) is a novel neural network architecture designed from the ground up with hardware principles in mind. It challenges the conventional deep learning paradigm by completely eliminating mathematically complex activation functions (like Sigmoid, Tanh, GELU, or Mish) at the output of its neurons.
|
| 15 |
-
|
| 16 |
-
Instead, SaraNet relies on **"hardware gating"**—a physical separation of positive and negative signals at the input of specialized "mirror neurons." This design achieves state-of-the-art accuracy while using only the simplest arithmetic operations: Addition, Subtraction, and Multiplication.
|
| 17 |
-
|
| 18 |
-
There is no division. There are no exponentials ($e^x$). There are no logarithms.
|
| 19 |
-
|
| 20 |
-
This makes SaraNet **110% compatible** and unbelievably fast on resource-constrained Edge AI microcontrollers like the ESP32, Arduino, and Raspberry Pi.
|
| 21 |
-
|
| 22 |
-
---
|
| 23 |
-
|
| 24 |
-
## How SaraNet Works
|
| 25 |
-
|
| 26 |
-
### The Golden Rule of Topology (Fully Connected Invariant)
|
| 27 |
-
In standard neural networks, an activation function modifies the output of a neuron. In SaraNet, the filtering happens *before* the weights are applied.
|
| 28 |
-
|
| 29 |
-
The network is composed of three main structures:
|
| 30 |
-
1. **The Input Layer (The Dispatcher):** Outputs a set number of "threads" (e.g., 128 threads).
|
| 31 |
-
2. **The Mirrors (The Hidden Layers):** This is the core innovation. A mirror consists of two groups of neurons: Positive Neurons and Negative Neurons.
|
| 32 |
-
- Every single thread from the input reaches every single neuron in the mirror.
|
| 33 |
-
- However, each neuron has a strict "gate" at its input.
|
| 34 |
-
- **Positive Neurons** only accept signals if the value is $\ge 0$.
|
| 35 |
-
- **Negative Neurons** only accept signals if the value is $\le 0$.
|
| 36 |
-
3. **The Meeting Room:** A pure linear layer with absolutely no gates or activations, where signals are mixed freely.
|
| 37 |
-
4. **The Judge (Output Layer):** Makes the final prediction based on the extracted features.
|
| 38 |
-
|
| 39 |
-
Because the filtering (the gate) happens dynamically at the input, the network gains non-linearity without ever calculating a complex mathematical curve.
|
| 40 |
-
|
| 41 |
-
### The Code: Elegant and Fast
|
| 42 |
-
To implement this efficiently in modern frameworks like PyTorch (while still respecting the hardware logic), we use a clever optimization involving `ReLU` and subtraction to separate the signals without slow memory operations. We then use grouped 1D convolutions to compute both the positive and negative mirrors simultaneously.
|
| 43 |
-
|
| 44 |
-
```python
|
| 45 |
-
import torch
|
| 46 |
-
import torch.nn as nn
|
| 47 |
-
|
| 48 |
-
class SaraNetFashionBottleneck(nn.Module):
|
| 49 |
-
def __init__(self, in_features=784, out_features=10):
|
| 50 |
-
super().__init__()
|
| 51 |
-
|
| 52 |
-
# 1. The Dispatcher (Input Layer) -> Outputs 128 threads
|
| 53 |
-
self.input_layer = nn.Linear(in_features, 128)
|
| 54 |
-
|
| 55 |
-
# 2. Mirror Layer 1: Combines Positive (64) and Negative (64) neurons.
|
| 56 |
-
# groups=2 ensures positive signals only multiply with the first 64 neurons' weights,
|
| 57 |
-
# and negative signals only multiply with the second 64 neurons' weights.
|
| 58 |
-
self.mirror1 = nn.Conv1d(in_channels=256, out_channels=128, kernel_size=1, groups=2)
|
| 59 |
-
|
| 60 |
-
# 3. Meeting Room: A pure linear layer with NO activation functions whatsoever.
|
| 61 |
-
self.meeting_room = nn.Linear(128, 128)
|
| 62 |
-
|
| 63 |
-
# 4. Mirror Layer 2
|
| 64 |
-
self.mirror2 = nn.Conv1d(in_channels=256, out_channels=128, kernel_size=1, groups=2)
|
| 65 |
-
|
| 66 |
-
# 5. The Judge (Output Layer): Pure linear decision.
|
| 67 |
-
self.judge = nn.Linear(128, out_features)
|
| 68 |
-
|
| 69 |
-
def forward(self, x):
|
| 70 |
-
# Flatten the input image (e.g., 28x28 -> 784)
|
| 71 |
-
x = x.view(x.size(0), -1)
|
| 72 |
-
z_in = self.input_layer(x)
|
| 73 |
-
|
| 74 |
-
# --- Mirror 1 Gating ---
|
| 75 |
-
# Hardware-like gating: Fast separation of positive and negative signals
|
| 76 |
-
# using only ReLU and Subtraction. No complex math!
|
| 77 |
-
pos_signal1 = torch.relu(z_in)
|
| 78 |
-
neg_signal1 = z_in - pos_signal1
|
| 79 |
-
|
| 80 |
-
# Concatenate for the Conv1d operation -> [batch, 256, 1]
|
| 81 |
-
combined_1 = torch.cat([pos_signal1, neg_signal1], dim=-1).unsqueeze(2)
|
| 82 |
-
room_in = self.mirror1(combined_1).squeeze(2) # Output is exactly 128 threads
|
| 83 |
-
|
| 84 |
-
# --- Meeting Room ---
|
| 85 |
-
# Pass through the Meeting Room (Pure Linear Transformation)
|
| 86 |
-
z_room = self.meeting_room(room_in)
|
| 87 |
-
|
| 88 |
-
# --- Mirror 2 Gating ---
|
| 89 |
-
pos_signal2 = torch.relu(z_room)
|
| 90 |
-
neg_signal2 = z_room - pos_signal2
|
| 91 |
-
combined_2 = torch.cat([pos_signal2, neg_signal2], dim=-1).unsqueeze(2)
|
| 92 |
-
m2_out = self.mirror2(combined_2).squeeze(2)
|
| 93 |
-
|
| 94 |
-
# --- Final Decision ---
|
| 95 |
-
out = self.judge(m2_out)
|
| 96 |
-
return out
|
| 97 |
-
```
|
| 98 |
-
|
| 99 |
-
---
|
| 100 |
-
|
| 101 |
-
## The Benchmark: SaraNet vs. Mish
|
| 102 |
-
|
| 103 |
-
To prove the viability of SaraNet, we tested it against **Mish** ($x \cdot \tanh(\ln(1 + e^x))$), one of the most advanced and computationally expensive activation functions in modern Deep Learning.
|
| 104 |
-
|
| 105 |
-
### Experimental Setup
|
| 106 |
-
- **Dataset:** FashionMNIST (classifying 10 types of clothing from 28x28 pixel images).
|
| 107 |
-
- **Network Sizes:** Both networks used an identical parameter count constraint.
|
| 108 |
-
- **SaraNet Size:** 784 $\rightarrow$ 128 $\rightarrow$ [64 Pos + 64 Neg] $\rightarrow$ 128 $\rightarrow$ [64 Pos + 64 Neg] $\rightarrow$ 10.
|
| 109 |
-
- **Mish MLP Size:** 784 $\rightarrow$ 128 $\rightarrow$ 128 $\rightarrow$ 128 $\rightarrow$ 128 $\rightarrow$ 10.
|
| 110 |
-
- **Protocol:** 10 independent training runs with different random seeds for exactly 5 epochs each.
|
| 111 |
-
|
| 112 |
-
### Results
|
| 113 |
-
The results were staggering. Despite having absolutely no mathematical activation curves, SaraNet matched the performance of Mish:
|
| 114 |
-
- **Mish Average Accuracy:** 87.17%
|
| 115 |
-
- **SaraNet Average Accuracy:** **86.67%** (with a peak of **87.38%**)
|
| 116 |
-
|
| 117 |
-
SaraNet achieves nearly identical results to state-of-the-art functions using only raw, linear processing power mixed with binary gating.
|
| 118 |
-
|
| 119 |
-
---
|
| 120 |
-
|
| 121 |
-
## The TinyML / Edge AI Revolution
|
| 122 |
-
|
| 123 |
-
While a 0.5% accuracy difference on a GPU is trivial, the **hardware implications are revolutionary**.
|
| 124 |
-
|
| 125 |
-
Mish requires calculating $e^x$, $\ln$, and $\tanh$. On a standard GPU, these are fast. But on an **ESP32, an Arduino, or a Raspberry Pi Pico**, computing a single logarithm can take thousands of CPU clock cycles because these chips lack a dedicated Floating Point Unit (FPU) for transcendental math.
|
| 126 |
-
|
| 127 |
-
**SaraNet bypasses this entirely.**
|
| 128 |
-
Because SaraNet only uses:
|
| 129 |
-
1. **Multiplication** (Weights)
|
| 130 |
-
2. **Addition** (Accumulation)
|
| 131 |
-
3. **Subtraction** (The Negative Gate)
|
| 132 |
-
|
| 133 |
-
It can be compiled down to **pure INT8 (8-bit Integer) operations**. There is no division. There are no exponentials.
|
| 134 |
-
|
| 135 |
-
This means you can take a fully trained SaraNet model, flash it onto a \$2 microcontroller running on a coin-cell battery, and it will execute inferences **orders of magnitude faster** and with a fraction of the energy consumption compared to a standard Neural Network. SaraNet is not just an alternative architecture—it is the ultimate Edge AI solution.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|