Export¶
In this section, we will present how to generate an N2D2 export with the Python API. Exports are standalone code which are generated by N2D2.
If you want more specific information about an export please refer to it in the export section.
With the Python API, you can only export an n2d2.cells.DeepNetCell
.
Once you have trained your model, you can convert your n2d2.cells.Sequence
into a n2d2.cells.DeepNetCell
with the method n2d2.cells.Sequence.to_deepnet_cell()
.
If you have used another way to train your model such as the interoperability with Keras or PyTorch, you can retrieve the n2d2.cells.DeepNetCell
with the appropriate get_deepnet_cell
method.
Warning
When using interoperability
, you do not associate a n2d2.provider.DataProvider
to the n2d2.cells.DeepNetCell
.
So if you want to calibrate your network, you need ot specify a data provider otherwise N2D2 will fail to generate the export.
Listing available cells for an export¶
If you want to get the list available cells for an export you can use the function n2d2.export.list_exportable_cell()
.
Export C¶
Exportable cells¶
Documentation¶
Example¶
n2d2.export.export_c(
DEEPNET_CELL,
nb_bits=8,
export_nb_stimuli_max=-1,
calibration=-1)
Frequently asked question¶
Scaling and ElemWise are the only layers supported in Fixed-point scaling mode¶
If you try to export an untrained model to C in int8, you may come across this error :
RuntimeError: Scaling and ElemWise are the only layers supported in Fixed-point scaling mode.
This is due to the weights parameter being initialized with high value. If you look at the log you may see warning lines like this :
Scaling (8.78614) > 1 for layer "model/dense/MatMul:0" is not supported with Single/Double-shift scaling. Falling back to Fixed-point scaling for this layer.
Training the model before exporting it will probably solve this issue.
Export CPP¶
Exportable cells¶
Documentation¶
Example¶
n2d2.export.export_cpp(
DEEPNET_CELL,
nb_bits=8,
export_nb_stimuli_max=-1,
calibration=-1)
Export CPP TensorRT¶
Exportable cells¶
Documentation¶
Example¶
n2d2.export.export_tensor_rt(DEEPNET_CELL)