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 :py:class:`n2d2.cells.DeepNetCell`. Once you have trained your model, you can convert your :py:class:`n2d2.cells.Sequence` into a :py:class:`n2d2.cells.DeepNetCell` with the method :py:meth:`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 :py:class:`n2d2.cells.DeepNetCell` with the appropriate ``get_deepnet_cell`` method. .. warning:: When using ``interoperability``, you do not associate a :py:class:`n2d2.provider.DataProvider` to the :py:class:`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 :py:func:`n2d2.export.list_exportable_cell`. .. autofunction:: n2d2.export.list_exportable_cell Export C -------- Exportable cells ^^^^^^^^^^^^^^^^ Documentation ^^^^^^^^^^^^^ .. autofunction:: n2d2.export.export_c Example ^^^^^^^ .. code-block:: python 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 : .. code-block:: 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 : .. code-block:: 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 ^^^^^^^^^^^^^ .. autofunction:: n2d2.export.export_cpp Example ^^^^^^^ .. code-block:: python n2d2.export.export_cpp( DEEPNET_CELL, nb_bits=8, export_nb_stimuli_max=-1, calibration=-1) Export CPP TensorRT ------------------- Exportable cells ^^^^^^^^^^^^^^^^ Documentation ^^^^^^^^^^^^^ .. autofunction:: n2d2.export.export_tensor_rt Example ^^^^^^^ .. code-block:: python n2d2.export.export_tensor_rt(DEEPNET_CELL)