2

有人可以帮我吗?

  File "C:\tensorflow1\models\research\slim\nets\mobilenet\mobilenet.py", line 397, in <module>
    def global_pool(input_tensor, pool_op=tf.compat.v1.nn.avg_pool2d):
AttributeError: module 'tensorflow._api.v1.compat.v1.nn' has no attribute 'avg_pool2d'

这是代码

def global_pool(input_tensor, pool_op=tf.nn.avg_pool2d):
  shape = input_tensor.get_shape().as_list()
  if shape[1] is None or shape[2] is None:
    kernel_size = tf.convert_to_tensor(
        [1, tf.shape(input_tensor)[1],
         tf.shape(input_tensor)[2], 1])
  else:
    kernel_size = [1, shape[1], shape[2], 1]
  output = pool_op(
      input_tensor, ksize=kernel_size, strides=[1, 1, 1, 1], padding='VALID')
  # Recover output shape, for unknown shape.
  output.set_shape([None, 1, 1, None])
  return output

它应该是 tf.nn.avg_pool2d(...) 是这样的吗?我确实在寻找解决方案。但我真的不明白。

4

1 回答 1

2

您是否尝试将其更改为tf.nn.avg_pool? 它似乎对我有用。

于 2020-02-12T11:01:45.553 回答