votes up 1

Argument `strides` must not be None.

Package:
keras
github stars 52268
Exception Class:
ValueError

Raise code

""" 
    name: A string, the name of the layer.
  """

  def __init__(self, pool_size, strides,
               padding='valid', data_format='channels_last',
               name=None, **kwargs):
    if strides is None:
      raise ValueError('Argument `strides` must not be None.')
    super(AveragePooling1D, self).__init__(
        pool_size=pool_size,
        strides=strides,
        padding=padding,
        data_format=data_format,
        name=name,
        **kwargs)
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

Ways to fix

votes up 2 votes down

The argument stride of the function tf.compat.v1.layers.average_pooling1d shouldn't be given a None.

Reproducing the error:

pipenv install tensorflow

import tensorflow as tf
x = tf.constant([1., 2., 3., 4., 5.])
x = tf.reshape(x, [1, 5, 1])
result = tf.compat.v1.layers.average_pooling1d(x, pool_size=2, strides=None)
print(result)

/usr/local/lib/python3.7/dist-packages/keras/legacy_tf_layers/pooling.py:150: UserWarning: `tf.layers.average_pooling1d` is deprecated and will be removed in a future version. Please use `tf.keras.layers.AveragePooling1D` instead.
  warnings.warn('`tf.layers.average_pooling1d` is deprecated and '
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-8893334bc772> in <module>()
----> 1 result = tf.compat.v1.layers.average_pooling1d(x, pool_size=2, strides=None)
      2 
      3 print(result)

/usr/local/lib/python3.7/dist-packages/keras/legacy_tf_layers/pooling.py in average_pooling1d(inputs, pool_size, strides, padding, data_format, name)
    155                            padding=padding,
    156                            data_format=data_format,
--> 157                            name=name)
    158   return layer.apply(inputs)
    159 

/usr/local/lib/python3.7/dist-packages/keras/legacy_tf_layers/pooling.py in __init__(self, pool_size, strides, padding, data_format, name, **kwargs)
     78                name=None, **kwargs):
     79     if strides is None:
---> 80       raise ValueError('Argument `strides` must not be None.')
     81     super(AveragePooling1D, self).__init__(
     82         pool_size=pool_size,

ValueError: Argument `strides` must not be None.

Fixed:

import tensorflow as tf
x = tf.constant([1., 2., 3., 4., 5.])
x = tf.reshape(x, [1, 5, 1])
result = tf.compat.v1.layers.average_pooling1d(x, pool_size=2, strides=2)
print(result)

tf.Tensor(
[[[1.5]
  [3.5]]], shape=(1, 2, 1), dtype=float32)

N.B

  • This API was designed for TensorFlow v1. Continue reading for details on how to migrate from this API to a native TensorFlow v2 equivalent. See the TensorFlow v1 to TensorFlow v2 migration guide for instructions on how to migrate the rest of your code

For more information, check the official documentation on this function.

Aug 18, 2021 kellemnegasi answer
kellemnegasi 31.6k

Add a possible fix

Please authorize to post fix