You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
With Gluon API you can set_data on a parameter. So for a convolutional layer you can select the weight (which will be the kernel) and call set_data on this with the kernel of your choosing. You must make sure you have the correct shape, with the dimensions being (filter, channel, height, width). So if we wanted a single sobel kernel applied to a single channel input we could for the following:
import mxnet as mx
# kernel of your choosing (e.g. a sobel filter)
kernel = mx.nd.array(((1,0,-1),
(2,0,-2),
(1,0,-1)))
# add dimensions for filters, and input channel
# both of which will have shape 1, since single filter and single input channel
weight = kernel.expand_dims(0).expand_dims(0)
conv = mx.gluon.nn.Conv2D(channels=1, kernel_size=(3,3), padding=(1,1))
conv._in_channels = 1
conv.initialize()
conv.weight.set_data(weight)
How to perform 2D convolution with user defined kernel just like sobel filter? Kindly provide example
The text was updated successfully, but these errors were encountered: