0

I am tying to implement a Depthwise 3D convolution. In the process, I am using a tf.nn.conv3d operation, where I utilize as input a 5D tensor, with shapes [batch, depth, height, width, channels] and a filter with exactly the same dimension than input: [filter_depth, filter_height, filter_width, in_channels, out_channels]. In_channels must match between input and filters arguments.

The script to test the conv3d operation is very simple, and as follow:

def run3():
    in_ = np.random.rand(1, 100, 6, 6, 3)
    filter = np.random.rand(3, 3, 3, 3, 3)
    a = tf.nn.conv3d(input=in_, filters=filter, strides=(1, 1, 1, 1, 1), padding="SAME", dilations=(1, 2, 1, 1, 1),
                     data_format="NDHWC")
    print(a.shape)

I am using in the input N,D,H,W,C = 1,100,6,6,3 and in filters, D,H,W,in_c,out_c = 3,3,3,3,3 I am applying dilation = 2 in the Depth dimension.

When I run this code snippet, I get the next error:

File "C:\repos\vct-ml-sbd\models\DepthwiseConv3D.py", line 284, in run3 a = tf.nn.conv3d(input=in_, filters=filter, strides=(1, 1, 1, 1, 1), padding="SAME", dilations=(1, 2, 1, 1, 1), File "C:\miniconda3\envs\tfgpu27\lib\site-packages\tensorflow\python\util\traceback_utils.py", line 153, in error_handler raise e.with_traceback(filtered_tb) from None File "C:\miniconda3\envs\tfgpu27\lib\site-packages\tensorflow\python\eager\execute.py", line 58, in quick_execute tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name, tensorflow.python.framework.errors_impl.NotFoundError: No algorithm worked! [Op:Conv3D]

The same code but with dilations = (1,1,1,1,1), it is, 1 in D dimension works! It also works with dilations = (1,2,1,1,1) if padding is set to "VALID". It seems that the issue has to do with using dilation_rate != 1 with padding = "SAME".

According tensorflow primitive documentation, dilations in the batch and depth dimensions must be 1, BUT this error is obtained only when I set the dilation rate to (1,1,1,1,2), so in that case, it is considering last dimension as Depth dimension when it is the Channel dimension according to data_format="NDHWC"

I have tried using Conv3D layer with next code:

def run33():
    in_ = np.random.rand(1, 100, 6, 6, 3)
    m = Conv3D(filters=1, kernel_size=(3, 3, 3), dilation_rate=(2, 1, 1), padding="SAME")
    a = m(in_)
    print(a.shape)

Then it works, resulting in a tensor (1,100,6,6,1)

I am using tensorflow 2.7

Any help is wellcomed! Thanks

0 Answers0