I am trying to obtain the output of a hybrid block, and feed it into a symbol block; but I am unsure as to how should i implement it.
More specifically, I am looking to modify the ConvPredictor in GluonCV’s Single Shot Detection Model by adding a Deformable Convolution layer in . The Deformable Convolution is presented as a symbol, but requires offset data generated from a Convolution Layer.
The source code from GluonCV’s repo is provided below:
class ConvPredictor(HybridBlock): def __init__(self, num_channel, kernel=(3, 3), pad=(1, 1), stride=(1, 1), activation=None, use_bias=True, in_channels=0, **kwargs): super(ConvPredictor, self).__init__(**kwargs) with self.name_scope(): self.predictor = nn.Conv2D( num_channel, kernel, strides=stride, padding=pad, activation=activation, use_bias=use_bias, in_channels=in_channels, weight_initializer=mx.init.Xavier(magnitude=2), bias_initializer='zeros') def hybrid_forward(self, F, x): return self.predictor(x)
I was thinking of feeding the convolution layer’s output into the symbol inside its hybrid_forward() method, but I don’t see a way to do so without re-initializing the symbol repeatedly inside the method. I would like to do so in it’s init() method but I am not sure how to link its output to the input of the symbol.