This repository contains Python bindings for CompiledNN (written by B-Human).
This package requires the following dependencies:
- Python 3 (with NumPy) (Ubuntu/Debian: python3, python3-numpy)
- Boost Python (with NumPy) (Ubuntu/Debian: libboost-python-dev, libboost-numpy-dev)
- HDF5 (Ubuntu/Debian: libhdf5-dev)
- Protocol Buffers (both compiler and library) (Ubuntu/Debian: protobuf-compiler, libprotobuf-dev)
PyCompiledNN can be installed via pip install git+https://github.com/h3ndrk/PyCompiledNN.git
.
- Make sure all submodules are cloned:
git submodule update --init
- Configure project:
cmake -Bbuild .
- Build project:
cmake --build build
- Observe the file
PyCompiledNN.so
in thebuild
directory
For testing, you should be able to import the module in Python without errors:
- Change into build directory:
cd build
- Run an interactive Python REPL:
python
- Import the module:
import PyCompiledNN
The API is very similar to the C++ version:
import PyCompiledNN
model = PyCompiledNN.Model()
model.load('model.hdf5')
# Optionally, indicate which input tensors should be converted from unsigned chars to floats in the beginning.
# model.setInputUInt8(0);
nn = PyCompiledNN.CompiledNN()
nn.compile(model)
# ... fill nn.input(i) with data
nn.apply()
# ... obtain the results from nn.output(i)
The input()
and output()
methods return NumPy ndarray
s:
input_array = numpy.zeros((32, 32, 1))
numpy.copyto(nn.input(0), input_array, casting='no')
nn.apply()
print(nn.output(0))