How to implement new layers#
Make sure you have a developer installation of blowtorch as described in Installation.
Rust part#
Write an implementation of the layer in Rust. This can have any form you want it to have. Place the layer as a new file in
rust/src, f.e. asbatch_norm.rs.Implement the
Layerinterface for your Layer inlayer_implementations.rs. You might have to import your layer first with ausedirective.Export the layer in the library, by adding it to the
nnmodule. This might require you to first add the module via mod batch_norm at the top, then adding it as an export via adding under pub mod nn a line likepub use batch_norm::BatchNorm.Add a
usedirective for your module into the models template file. ! Import the layer from the public export of the library directly, e.g. withuse blowtorch::nn::BatchNorm.
Python part#
Create a new layer in
python/blowtorch/layers, f.e._batch_norm.py.Implement the
Layerinterface in_interfaces.pyaccording to the docstrings given there.Add your layer with a fitting name to the
LAYER_DISPATCHdictionary in_parsing.py, f.e. “BatchNorm”: BatchNorm. This might require you to import your layer first. Do a relative import with a leading., such asfrom ._batch_norm import BatchNorm.
Schema#
Navigate to
python/blowtorch/schemaand add a fitting jsonschema for your python class: Which attributes are required, which form do they have etc. You will have to add it to the defs in the bottom, see theconvolutionexample.Add the schema to the
anyOfattribute in the layer array.