Skip to content

How to add a new layer or implementation?

yaitaissa edited this page Aug 23, 2024 · 1 revision

Add a new layer

Here are exposed the few steps to implement a new layer in ACETONE:

  • Create a script layer_name.py in the layers folder
  • Create the class layer_name with at least the following methods:
    • __init__: Create the object
    • forward_path_layer: The Python implementation of the layer
    • generate_inference_code_layer: The function generating a string corresponding to the C code of the layer
  • Create the corresponding template template_layer_name.c.tpl in the templates/layers folder
  • Add to the parser(s) (depending on if the layer is implemented on the corresponding format) the function to read and create the layer (in the file create_layers.py for ONNX, or directly in the parser file for other formats) in the format_importer folder.

Add a new version

Here are exposed the few steps to implement a new implementation of a pre-existing layer in ACETONE:

  • Create a folder in the layers folder
  • Move the pre-existing implementation of the layer to this folder
  • Transforme the layer in an "empty" version (forward_path_layer and generate_inference_code_layer are left as abstract methods) and put the pre-existing verions in a new class inheriting from the "empty" version.
  • Create your new implementation by inheriting from the "empty" version and adding your forward_path_layer and generate_inference_code_layer methods (don't forget to add a corresponding template and to join all the templates for the layer in a same sub-folder).
  • Add a default version in the create_dict_version method of the CodeGenerator class (in the neura_network.py file)
  • Add a layer_implementation.py file in the versioning/version_implementation folder and creates one instantiation function per version and one global
  • Add the global function in versioning's implemented dictionary.

Clone this wiki locally