How to convert Flatten layer to Conv2D?

Hi, I am trying to implement sliding windows using Conv2D, so I need to convert Flatten layer to Conv2D and FCN to Conv2D, which shows as follows, how do this in mxnet?
image

Hi Alvin,

I’m not exactly sure what the diagram is conveying there. Can you post an example in out pair of what you want to achieve and what you have now.

Or describe in more detailed terms what you want to convert. For example what do you mean converting a Flatten layer to a Conv2D? You wanna replace a flatten layer with a conv layer?

I don’t understand the question as phrased currently

Hi Sad,
Thanks for reply. what I want to do is to implement sliding windows with convolution so that speed up the prediction.
below screen shots come from a lesson on deeplearning.ai which taught by Andrew Ng.


From above graph, you can see we feed in an image with a dimension(14x14x3) to the network, then we get a output of vector with dimension (4), let’s take it as the probabilities of belonging to 4 different classes.

now in order to locate all objects in an image with dimension(16x16x3), so we have to slide window(14x14x3) at 4 different locations, please refer to below graph, it is ok but for the lower speed. if we can implement a sliding windows with convolution then we can detect all objects in one look through the whole image instead of 4 look on 4 sub-images.

I am glad to let you know I’ve already got the answer by making several experiments.
For the Flatten layer, just create an identity matrix and set it to the weight to the Conv2D and make the bias all 0.
For the FCN layer, just reshape the weight with Conv2D shape and set it to the weight of Conv2D and copy the bias as well.
It is easy, thanks again.

Thanks for the detailed explanation and contribution. This would be very helpful for other members of the community that run into the same issue