A pure numpy-based inference framework for CNN. The aim of numpy-cnn is to deploy CNN model with low-cost and few adjustment including embedded systems. Also in order to enlarge the application scope, we support ONNX format, which enables the converting of trained model within various DL frameworks (PyTorch).
- Extremely streamlined Intermediate Representation (IR).
- Pure numpy implementations, which is easy to deploy.
- Ravel numpy weights storage, which largely simplifies the loading process.
- Optimized codes, which achieve ~30% speed up compared to PyTorch 1.1.0 cpu.
All the elements (layers, operations, activation fuctions) are abstracted to be layer
, and a json formatted flow
is applied to build the computation graph. We support 3 ways of building a network:
- PyTorch-like
from cnnumpy import *
# ========== write a net manually ==========
class CustomNet(Net):
def __init__(self):
self.conv = Conv2d(3, 64, 3, 1)
self.relu = ReLU()
self.pool = Maxpool(2)
self.upsample = UpSample(2)
self.concatenate = Concatenate()
self.sigmoid = Sigmoid()
def forward(self, x):
x = self.conv(x)
x = self.relu(x)
y = self.pool(x)
y = self.upsample(y)
z = self.concatenate([x, y])
return self.sigmoid(z)
- Json-like (based on our IR)
# ========== load net from json ==========
layer = [('conv', 'conv', (3, 64, 3, 1)),
('relu', 'relu', None),
('pool', 'maxpool', (2,)),
('up', 'upsample', (2,)),
('concat', 'concat', None),
('sigmoid', 'sigmoid', None)]
flow = [('x', ['conv', 'relu'], 'x'),
('x', ['pool', 'up'], 'y'),
(['x','y'], ['concat', 'sigmoid'], 'z')]
net = Net()
net.load_json(layer, flow)
- ONNX-converted (all the demos) Coming soon.
Using show() to plot the structure of net (networkx and matplotlib needed)
net.show()
demo.py
includes the plot. The result of UNET and HED are shown as flowing:
HED
Here we release some supported demos.
Demo for scene text detector with model CRAFT.
Run python main.py
inside folder craft_text_detector
. 2 files (same level folder with main.py
) are needed (craft.txt, craft.npy)
The detected result is shown as following:
Demo for edge detector with model HED. Run python main.py
inside folder hed_edge_detector
. 2 files (same level folder with main.py
) are needed (hed.txt, hed.npy)
The detected result is shown as following:
Demo for image classification with resnet18. python main.py
inside folder resnet18
. 2 files (same level folder with main.py
) are needed (res.txt, res.npy)
The detected result is shown as following:
Demo for image classification with mobilenet-v1. python main.py
inside folder mobilenet-v1
. 2 files (same level folder with main.py
) are needed (mobile.txt, mobile.npy)
The detected result is shown as following:
Demo for Unet Segmetn trained with data here. 1. python main.py
inside folder unet-segment
. 2 files (same level folder with main.py
) are needed (unet.txt, unet.npy)
The detected result is shown as following: