I am trying to implement a own layer with Keras functional API. The idea is to transpose the convolutional operator. So far I got:
k1 = self.tied_to.kernel
self.kernel = K.transpose(k1)
The code works if I just pass the kernel of the former layer without doing anything to it. The kernel is defined in the shape 3x3, so transposing it should work nicely. But the problem is that the kernel is in the form of a tensor with shape 3x3x1x1 and K.transpose
transposes the complete tensor. How do I transpose only the kernel itself, so I get again a kernel of the form 3x3x1x1?
You want to use K.permute_dimensions
.
I'm not sure about what you want to transpose, but I see two possibilities.
K.permute_dimensions(k1, (1,0,2,3))
K.permute_dimensions(k1, (0,1,3,2))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.