在运行程序时遇到以下报错:
TypeError: Value passed to parameter 'paddings' has DataType float32 not in list of allowed values: int32, int64
这段代码在我的Linux系统下,python2环境中是没问题的。但在Windows环境下python3环境下就出现问题了。
了解了下,原因在于两个版本下对float的处理方法不同,python2环境下在运行 /
除法操作时产生的结果将直接忽略小数,直接取整数。而在python3环境下,运行 /
除法操作是会保留小数的。
所以检查代码,必然是这里的问题了:
对应到代码中:
def conv2d(x, input_filters, output_filters, kernel, strides, mode='REFLECT'):
with tf.variable_scope('conv'):
shape = [kernel, kernel, input_filters, output_filters]
weight = tf.Variable(tf.truncated_normal(shape, stddev=0.1), name='weight')
x_padded = tf.pad(x, [[0, 0], [kernel / 2, kernel / 2], [kernel / 2, kernel / 2], [0, 0]]