问题描述
在使用Tensorflow会有如下报错
ValueError: Argument must be a dense tensor: range(0, 12) - got shape [12], but wanted [].
此问题的原因是因为Tensorflow版的本兼容的问题,导致range()函数返回值不是列表,解决方法发有两种:
方法一:
.通过list函数将range()结果强制转化为列表
例子:
原代码
import tensorflow as tf
x = tf.constant(range(12))
print(x.shape)
使用list()改进后
import tensorflow as tf
x = tf.constant(list(range(12)))
print(x.shape)
方法二:
把research/object_detection/utils/learning_schedules.py文件的 第167-169行由
# # 修改167-169
rate_index = tf.reduce_max(tf.where(tf.greater_equal(global_step, boundaries),
range(num_boundaries),
[0] * num_boundaries))
# # 成
rate_index = tf.reduce_max(tf.where(tf.greater_equal(global_step, boundaries),
list(range(num_boundaries)),
[0] * num_boundaries))
此方法详情请参考原文链接:原文链接https://blog.csdn.net/lovebyz/article/details/80668881