Add a registery to add thridparty layers
berleon opened this issue · 3 comments
I want to create my own layer. Currently the way to go is to add the layer directly to cxxnet
. This means I have to fork the repo and ensure that my fork stays up to date.
There should be a simpler way to create a new layer.
Is it possible to create some kind of a static LayerRegistery
. A new layer can be simple added to the registery with a name and its class. A possible signature might be template<LAYER> void LayerRegistery::register<LAYER>(const std::stirng & name)
.
Well kind of of. Let's say I need a loss layer with the hamming distance as loss function. Then I could create a layer as described in #220. In this process I would add an new index number to layer.h for my HammingDistanceLayer. But adding the HammingDistanceLayer to cxxnet comes with a big costs. Now I have to maintain a fork of cxxnet. I think there should be a way for any thrid party to add new layers to cxxnet without forking the repo.
Let me explain it in detail with a little example:
in cxxnet create a function to register new layers:
template<LAYER>
static void registerLayer<LAYER>(const std::string & name, size_t id) {
// registers LAYER with name and id.
// LAYER can now be used in the network description
}
in my library that uses cxxnet, I create a new HammingDistanceLayer.
template<typename xpu>
class HammingDistanceLayer: public LossLayerBase<xpu> {
public:
// my layer definition ...
};
Now I have to tell cxxnet about my new layer.
So I call the registerLayer function before loading my network.
void main() {
cxxnet::registerLayer<HammingDistanceLayer>("hamming_distance", 345);
// load a network with HammingDistanceLayer
}
A problem could be to make sure that every Layer has its own id.
Thanks for the suggestion! Currently we are busy building next generation toolkit MXNET (https://github.com/dmlc/mxnet). We are using registry there.