rwallace
rwallace

Reputation: 33475

conv1d data_format deprecation warning

I have some TensorFlow code that looks like this:

input_layer = tf.reshape(X, [-1, length, channels])

conv1_filters = 10
conv1_kernel_size = 5
conv1 = tf.layers.conv1d(
    inputs=input_layer,
    filters=conv1_filters,
    kernel_size=conv1_kernel_size,
    padding='same',
    activation=tf.nn.relu,
    )

It actually works correctly, but with TF 1.6.0 it now gets a warning:

WARNING:tensorflow:From C:\Users\w\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\util\deprecation.py:497: calling conv1d (from tensorflow.python.ops.nn_ops) with data_format=NHWC is deprecated and will be removed in a future version. Instructions for updating: NHWC for data_format is deprecated, use NWC instead

Okay so maybe I ought to update my code. I tried adding a parameter to the conv1d call:

    data_format='NWC',

but that gets an error:

ValueError: The data_format argument must be one of "channels_first", "channels_last". Received: NWC

Okay, I tried doing as the error message said:

    data_format='channels_last',

But that gets the original deprecation warning.

Is there something else I should be doing, or should I just ignore the warning?

Upvotes: 3

Views: 2703

Answers (1)

xdurch0
xdurch0

Reputation: 10474

I was wondering the same thing and your question motivated me to look into this. Calling tf.layers.conv1d actually results in a long stream of convolution-related classes/methods being called (ops using ops using ops...).

To be precise (skip this if not interested):

  • layers.conv1d uses layers._Conv (base class for all conv layers).
  • layers._Conv calls nn_ops.Convolution as its _convolution_op.
  • nn_ops.Convolution uses _WithSpaceToBatch as its conv_op.
  • _WithSpaceToBatch gets _NonAtrousConvolution as its build_op.
  • _NonAtrousConvoluton will (in the 1D case) use conv1d as its conv_op (to be precise it uses self._conv1d which calls conv1d). This is the tf.nn.conv1d which is of course very different from tf.layers.conv1d we called in the beginning.
  • As noted, tf.nn.conv1d produces the deprecation warning.

I strongly suspect that somewhere along this chain, the conversion from the "user friendly" channels_first/last (used by the tf.layers interface) to the more generic format such as NCHW/NHWC (used by the lower-level ops) wasn't updated properly to using NCW/NWC for 1D convolutions.

The short and boring answer: See this github issue. Apparently this will not yet be fixed in TF 1.7.

Upvotes: 4

Related Questions