Skip to content

How to add new Plugins

Philipp edited this page Apr 3, 2020 · 5 revisions

To create a new plugin for the Neural-Network-Translator, a new python class has to be added in one of the folders (frontend, backend or conversation).

All plugins need a unique identifier to differentiate between the available plugins and a brief description of the use case of the plugin.

In the following sections, the process for creating specific plugins will be described in more detail.

Frontend

Frontend plugins transform a given input file, for example, an h5-file, containing the architecture of a neural network and the weights, produced by the training phase with a framework into an intermediate JSON format specified within this project.

A new frontend plugin has to be inherited from the FrontendPlugin class. Therefore, all frontend plugins have to provide a method with the following signature to convert an input to the intermediate format:
def transform_to_intermediate_format(self, input)

The intermediate JSON schema description can be found in the repository or as a described version here.
A new frontend plugin has to provide a JSON format following exactly this JSON schema as it is validated after the transformation to guarantee the correctness of the produced intermediate format.

All frontend plugins have to be placed in the folder /frontend to be detected as available frontend plugins.

Conversion

Conversion plugins can perform different transformations on the intermediate format, such as converting float values to integer values, etc. The input and output of those plugins have to be a valid intermediate JSON format as stated before.

A new conversion plugin has to be inherited from the ConversionPlugin class. Therefore, all conversion plugins have to provide a method with the following signature in order process the given input and perform the specific conversion:
def process(self, input)

Within the converter, conversions are performed after the transformation from the frontend to an intermediate format. In the first step, the conversions required by the backend plugin are performed. Afterward, the conversions specified by the user are executed.

All conversion plugins have to be placed in the folder /conversion to be detected as an available conversion plugin.

Backend

Backend plugins convert data from the intermediate format into a specific output format which can be flashed and run on a microcontroller. For example, a plugin for the Arduino platform transforms the intermediate format into C code.

A new backend plugin has to inherit from the BackendPlugin class. Therefore, all backend plugins have to provide a method with the following signature to convert data from the intermediate format into a specific output format:
def translate_to_native_code(self, input)

In addition to an identifier and a description, required conversions can be specified in the field prerequisites. The corresponding conversion plugins will be executed directly after the transformation into the intermediate format.

For the conversion to C code, there already exists a library with commonly needed methods as described here. This library can be utilized to simplify the creation of new backend plugins for C code.

All backend plugins have to be placed in the folder /backend to be detected as available backend plugin.

Clone this wiki locally