Version | Stable | Test a trained model |
---|---|---|
0.1.0 |
โ
|
This project is a simple Convolutional Neural Network (CNN) implemented entirely from scratch using only low-level libraries like NumPy, PIL, and SciPyโ no deep learning frameworks (e.g., TensorFlow or PyTorch) are used. It includes image preprocessing, convolution and pooling operations, ReLU and softmax activations, forward/backward propagation, and a fully connected classifier.
Version | Stable | Test a trained model |
---|---|---|
0.1.0 |
โ
|
pickle
Make sure your dataset folder is structured like this:
data/
โโโ class1/
โ โโโ image1.png
โ โโโ image2.png
โโโ class2/
โ โโโ image1.png
โ โโโ image2.png
โโโ class../
โ โโโ ..
..
Each subfolder represents a class (e.g., cat
, dog
), and contains sample images.
To help you get started, weโve included a starter
data
folder with example class directories.
Image Preprocessing:
Feature Vector:
Feedforward + Softmax:
Backpropagation:
pip install git+https://github.com/77AXEL/CNN-FS.git
from cnnfs.model import CNN
model = CNN()
model.init(
image_size=64,
batch_size=32,
h1=128,
h2=64,
learning_rate=0.001,
epochs=400,
dataset_path="data",
max_image=200,
filters=[
[[0, -1, 0], [-1, 5, -1], [0, -1, 0]],
[[1, 0, -1], [1, 0, -1], [1, 0, -1]],
[[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]]
]
)
model.load_dataset()
model.train_model()
model.save_model()
model.load_model("model.bin")
prediction = model.predict("test_images/mycat.png")
print("Predicted class:", prediction)
[ [0, -1, 0], Sharpen
[-1, 5, -1],
[0, -1, 0] ]
[ [1, 0, -1], Edge detection
[1, 0, -1],
[1, 0, -1] ]
[[-1, -1, -1], Laplacian
[-1, 8, -1],
[-1, -1, -1] ]
Metric | Value (example) |
---|---|
Accuracy | ~90% (binary class) |
Epochs | 10โ50 |
Dataset | Custom / ~8000 imgs |
MIT License โ feel free to use, modify, and share.
PRs are welcome! You can help: