Skip to content

Use Custom Layer

Takuya Takeuchi edited this page Dec 29, 2022 · 1 revision

Abstracts

NcnnDotNet supports to define custom layers on application side. It means that developer needs not to define and write them in C++ code.

Examples

class YourCustomLayer : CustomLayer
{
    public YourCustomLayer()
    {
    }

    protected override unsafe int OnForward(Mat bottomBlob, Mat topBlob, Option opt)
    {
        // Do NOT dispose bottomBlob, topBlob and opt!!!
        return 0;
    }

}

private static YourCustomLayer YourCustomLayerCreator(IntPtr userData)
{
    return new YourCustomLayer();
}

using var net = new Net();
using var reg = new CustomLayerRegister("YourCustomLayer", YourCustomLayerCreator);
net.RegisterCustomLayer(reg);

References

You can see the following examples uses custom layers.

Clone this wiki locally