Hello everybody!
I am currently attempting to implement a max pooling operation in the Nengo DL converter. The converter code for this is pretty straight forward and is similar to the one in the converter for the AveragePool layer:
@nengo_dl.Converter.register(MaxPool2D)
class ConvertMaxPool2D(nengo_dl.converter.LayerConverter):
unsupported_args = [("padding", "valid")]
def convert(self, node_id):
...
pool_transform = MaxPool(
self.input_shape(node_id),
kernel_size=pool_size,
strides=strides,
padding=padding
)
self.add_connection(node_id, output, transform=pool_transform)
return output
Now the big challenge there is the “MaxPool” tranformation in the end of the code sample. This one is not provided by Nengo DL and therefore must be implemented.
So my first question is: is there any specific reason why max pooling is not (yet) implemented? And secondly, what steps have to be taken when implementing a new transformation like that?
I already gave implementing the transformation a go by adapting the existing nengo.Convolution
transformation.
For this, I first created a new class plus the (apparently) needed build function:
class MaxPool(Transform):
...
@Builder.register(MaxPool)
def build_maxpool(
model, transform, sig_in, decoders=None, encoders=None, rng=np.random
):
...
model.add_op(
MaxPoolInc(
sig_in, pooled, transform, tag="%s.apply_weights" % transform
)
)
...
class MaxPoolInc(Operator):
def make_step(self, signals, dt, rng):
...
def step_max_pool():
Y += max_pool2d(
input=X,
ksize=self.maxpool.kernel_size,
strides=stride,
padding=pad
)
return step_max_pool
...
As you can see, in the build function, there is a MaxPoolInc operator, that uses the max_pool2d operation from the tensorflow package. When I try to make this work, I get an error that the MaxPoolInc operator also needs to be registered. After further inspection, I found the corresponding code for the nengo.Convolution
transformation in the nengo_dl.transform_builders.py
file, line 33:
@Builder.register(ConvInc)
@Builder.register(ConvSet)
class ConvIncBuilder(OpBuilder):
"""
Build a group of `nengo.builder.transforms.ConvInc` operators.
"""
...
This class however seems to be rather complicated and long (more than 150 lines).
So my question now is, what does this ConvIncBuilder
do and what do I need to do to make my own transformation work. If needed, I can also try to provide an MVE.
Thanks in advance!
Cheers.