Closed cxy7452 closed 7 years ago
i would assume that the 6d matrix is exactly the decomposed form, but I am not sure. One would have to look into the code
Hi Soumith, I just got a great solution from @fmassa ,
weight6d = weight2d:view(oH,oW,nInputPlane,kH,kW,nOutputPlane):permute(1,2,6,3,4,5)
This will take care of the decomposition order, tested it and it is indeed correct!
oh wow! how the hell did he figure that out :)
In his response, it was from here:
https://github.com/soumith/cuda-convnet2.torch/blob/master/cudaconv3/src/filter_acts.cu#L1166
the correctness was tested by creating a network with 1 ccn2 local convolution layer, and another network with 1 nn local convolution layer. Then, perform the view and permute on the ccn2's layer weights, and set the nn local conolution layer's weights with the transformed weights (and set both bias to 0), and perform a forward pass using the same input for both network. The output was identical for both network which indicates that the transformation was done correctly.
This test was also suggested by @fmassa . Awesome stuff!
from the code, the weight matrix from a spatial convolution local layer is a 2d matrix:
self.weight = torch.Tensor(outputSize*nInputPlane*filterSize, nOutputPlane)
is the 1st dimension's combination order exactly like the multiplications above? or..is there a way to decompose this 2d weight matrix into the form that is like nn.SpatialConvolutionLocal? such that it is a 6d matrix like the following from nn.SpatialConvolutionLocal:
self.weight = torch.Tensor(self.oH, self.oW, nOutputPlane, nInputPlane, kH, kW)
thanks.