(Chinese Guide)NumPy_CNN:由NumPy实现的卷积神经网络中文介绍
NumPy_CNN contains CNN modules that is implemented in pure NumPy. Using these modules (defiend in Modules directory), in a PyTorch-like manner, we can easily build CNNs.
The meaning of this project is to, by converting optimized C codes into Python codes, demostrate how a CNN works (in my understanding).
In mnist_cnn-final_test.md one can see the format for building a CNN, which can achieve 99.33% test accuracy on MNIST.
First download the whold directory.
- If you have jupyter notebook, try to run main.ipynb.
- Otherwise, run main.py, which does the same job.
Note that it may take a while to run with the default setting, so you may like to train with your prefered parameters.
The two main files both first declared a CNN class, defining its network structure, the loss function and the optimizer. Then it starts training and testing.
With similar way of defining the network, you can build your own network, including CNN and simple BP.
nn.py: Similar to torch.nn in PyTorch, nn.py defines network layers(convolution, linear), loss functions(MSE, CrossEntropy) and optimizers(Adam, RMSProp) classes, which will be used in defining networks.
matrix_functions.py: is used to boost functions matmul() and einsum(), when you have installed torch. This is because NumPy often does not use multi-kernel to compute matrix multiply. However, without torch module, the program is still runnable.
mnist.py is used to read MNIST dataset in directory data. The code is not written by me, and I'd like to thank the original author.
one_hot.py is used to encode one hot for labels.