How to get per channel convolution in tensorflow like the conv2d parameter "groups" in Pytorch?

Viewed 1260

I am working on a project for which I am referring a network which has been built in Pytorch. One of its layer has conv2d layer with group = some value. While I am building the project in Tensorflow . How do I do this particular layer considering I didn't find any group parameter in the conv2d layer of tensorflow. I searched online but couldn't find anything concrete like what group says is it is a per-channel convolution. The close thing I found was tf.nn.separable_conv2d but still not sure how to set the arguments in it.

The Pytorch layer is conv2d(input ,weight , groups = x ) where input and weight are 4d tensors. Could anyone help out how I create this layer in Tensorflow.

2 Answers

I think you should check the definition of conv2d in PyTorch. Your first two parameters should be integers not 4D tensors.

Group is 1 by default what you should not alter in your case. I think in Tensorfolow if group > 1 you should use SeparableConv2D.

If you increase the group you get the depth-wise convolution, where each input channel is getting specific kernels per se.

The only rule you should have is that both in and out channels should be dividable by group number.

Group convolution is supported in Tensorflow 1.14.0. Please refer this pull request:

https://github.com/tensorflow/tensorflow/pull/25818

The difference being instead of 'groups' parameter, the input depth shape can be a multiple of number of input filters.

Related