AttributeError: module 'tensorflow' has no attribute 'resize_nearest_neighbor'

AttributeError: module 'tensorflow' has no attribute 'resize_nearest_neighbor'

我在 TS 2.0 中遇到这个错误。

AttributeError: module 'tensorflow' has no attribute 'resize_nearest_neighbor'

 tf.resize_nearest_neighbor(conv3, (tf.shape(conv2)[1], tf.shape(conv2)[2]))

有没有我可以使用的替代方案?

可以在tf.image.resize中指定插值方式:

The method argument expects an item from the image.ResizeMethod enum, or the string equivalent. The options are:

  • nearest: Nearest neighbor interpolation. antialias has no effect when used with nearest neighbor interpolation. tering),

所以等价的是

tf.image.resize(conv3, (tf.shape(conv2)[1], tf.shape(conv2)[2]), method='nearest')

请注意,只有当 conv3 是形状为 [batch, height, width, channels] 的 4-D Tensor 或形状为 [height, width, channels] 的 3-D Tensor 时它才有效。