A numpy based CNN implementation for classifying images
A numpy based CNN implementation for classifying images.
status: archived
Follow the steps listed below for using this repository after cloning it.
For examples, you can look at the code in fully_connected_network.py and cnn.py.
I placed the data inside a folder called data within the project root folder (this code works by default with cifar10, for other datasets, the filereader in utilities can't be used).
After placing data, the directory structure looks as follows
from layers.fully_connected import FullyConnected
from layers.convolution import Convolution
from layers.flatten import Flatten
from layers.activation import Elu, Softmax
from loss.losses import CategoricalCrossEntropy
from utilities.model import Model
model = Model(
Convolution(filters=5, padding='same'),
Elu(),
Pooling(mode='max', kernel_shape=(2, 2), stride=2),
Flatten(),
FullyConnected(units=10),
Softmax(),
name='cnn-model'
)
model.set_loss(CategoricalCrossEntropy)
model.train(data, labels)
prediction = model.predict(data)
accuracy = model.evaluate(data, labels)
model.load_weights()
Note: You will have to have similar directory structure.This was a fun project that started out as me trying to implement a CNN by myself for classifying cifar10 images. In process, I was able to implement a reusable (numpy based) library-ish code for creating CNNs with adam optimization.
Anyone wanting to understand how backpropagation works in CNNs is welcome to try out this code, but for all practical usage there are better frameworks with performances that this code cannot even come close to replicating.
The CNN implemented here is based on Andrej Karpathy's notes