votes up 7

pooling_ratio should be >= 1.0.

Package:
Exception Class:
ValueError

Raise code

""" 
  """
  if (isinstance(pooling_ratio, (list, tuple))):
    if (pooling_ratio[0] != 1.0 or pooling_ratio[-1] != 1.0):
      raise ValueError(
          "The first and last elements of pooling ratio must be 1.0.")
    for element in pooling_ratio:
      if element < 1.0:
        raise ValueError("pooling_ratio should be >= 1.0.")
  elif (isinstance(pooling_ratio, (int, float))):
    if pooling_ratio < 1.0:
      raise ValueError("pooling_ratio should be >= 1.0.")
  else:
    raise ValueError("pooling_ratio should be an int or a list of ints.")

  pooling_ratio = _get_sequence(pooling_ratio, 2, 3, "pooling_ratio")
😲 Agile task management is now easier than calling a taxi. #Tracklify

Ways to fix

votes up 2 votes down

tf.nn.fractional_max_pool is a function that performs fractional max pooling on the input.

Usage:

result = tf.nn.fractional_max_pool(value, 
                                   pooling_ratio, 
                                   pseudo_random=False, 
                                   overlapping=False, 
                                   seed=0, 
                                   name=None)

The parameter pooling_ratio should be greater than 1.0

Reproducing the error:

pipenv install tensorflow

import tensorflow as tf
from tensorflow.nn import fractional_max_pool
input = tf.random.uniform((3,28,28,3))
output = fractional_max_pool(input,0.9)
print(output[0].shape,"\n\n",output[1].shape,"\n\n",output[2].shape)

The output error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-20-dc399d610cc8> in <module>()
      2 from tensorflow.nn import fractional_max_pool
      3 input = tf.random.uniform((3,28,28,3))
----> 4 output = fractional_max_pool(input,0.9)
      5 print(output[0].shape,"\n\n",output[1].shape,"\n\n",output[2].shape)

/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
    204     """Call target, and fall back on dispatchers if there is a TypeError."""
    205     try:
--> 206       return target(*args, **kwargs)
    207     except (TypeError, ValueError):
    208       # Note: convert_to_eager_tensor currently raises a ValueError, not a

/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/nn_ops.py in fractional_max_pool_v2(value, pooling_ratio, pseudo_random, overlapping, seed, name)
   5497   elif (isinstance(pooling_ratio, (int, float))):
   5498     if pooling_ratio < 1.0:
-> 5499       raise ValueError("pooling_ratio should be >= 1.0.")
   5500   else:
   5501     raise ValueError("pooling_ratio should be an int or a list of ints.")

ValueError: pooling_ratio should be >= 1.0.


Fixed version of the code:

import tensorflow as tf
from tensorflow.nn import fractional_max_pool
input = tf.random.uniform((3,28,28,3))
output = fractional_max_pool(input,1.9)
print(output[0].shape,"\n\n",output[1].shape,"\n\n",output[2].shape)

Output:

(3, 14, 14, 3) 

 (15,) 

 (15,)

Jul 14, 2021 kellemnegasi answer
kellemnegasi 22.6k

Add a possible fix

Please authorize to post fix