根据Github Issues上的讨论,主要的原因是tensorflow1.1x版本中tf.image.resize(原代码中使用tf.image.resize_images,但已被弃用,因此改为tf.image.resize)对图片height与width的获取部分有问题,即在所处环境中找到:\lib\python3.7\site-packages\tensorflow_core\python\ops\image_ops_impl.py,其中
new_height_const = size_const_as_shape.dims[0].value
new_width_const = size_const_as_shape.dims[1].value
改为
new_height_const = tensor_shape.dimension_at_index(size_const_as_shape,
0).value
new_width_const = tensor_shape.dimension_at_index(size_const_as_shape,
1).value
即可修复此错误,此外将tensorflow降为1.12版本以下应该也能解决该问题,但笔者没有亲身尝试。这里的报错的具体原因还不是很清楚,可能是因为源代码把size_const_as_shape当做了constant类型处理,然而实际上size_const_as_shape应该是variable的类型,因此在获取数据维度大小时失败,得到了None,后续的对None索引就报错了
Giuhub issues:https://github.com/tensorflow/models/issues/8154
solutions:https://github.com/UofT-EcoSystem/tensorflow/commit/24c75ce5016efb4ab107f27b96aac07549d8617b