Reputation: 492
I am re-implementing the example in Deep MNIST for Experts, which constructs a simple CNN and runs on the MNIST dataset. But an error raised on this line of code: h_conv1 = tf.nn.leaky_relu(conv2d(x_image, W_conv1) + b_conv1, alpha=1/3)
. The whole code script is:
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
def bias_variable(shape):
initial = tf.constant(0.1, shape=shape)
return tf.Variable(initial)
# Real data
x = tf.placeholder(tf.float32, shape=[None, 784])
y_ = tf.placeholder(tf.float32, shape=[None, 10])
# First layer pair
W_conv1 = weight_variable([3, 3, 1, 60])
b_conv1 = bias_variable([60])
x_image = tf.reshape(x, [-1, 28, 28, 1])
h_conv1 = tf.nn.leaky_relu(conv2d(x_image, W_conv1) + b_conv1, alpha=1/3)
h_pool1 = max_pool_2x2(h_conv1)
The error traceback is:
Traceback (most recent call last):
File "scn_mnist.py", line 118, in <module>
h_conv1 = tf.nn.leaky_relu(conv2d(x_image, W_conv1) + b_conv1, alpha=1/3)
File "/root/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/nn_ops.py", line 1543, in leaky_relu
return math_ops.maximum(alpha * features, features)
File "/root/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/math_ops.py", line 885, in binary_op_wrapper
y = ops.convert_to_tensor(y, dtype=x.dtype.base_dtype, name="y")
File "/root/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 836, in convert_to_tensor
as_ref=False)
File "/root/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 926, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/root/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 774, in _TensorTensorConversionFunction
(dtype.name, t.dtype.name, str(t)))
ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("add:0", shape=(?, 28, 28, 60), dtype=float32)'
I have checked the data types of x_image
(which is tf.float32), W_conv1
(tf.float32_ref) and b_conv1
(tf.float32_ref). There seems to have no problem with the data types, so I really can't figure out the crux.
Upvotes: 1
Views: 321
Reputation: 53768
The problem is with alpha
, which tensorflow interprets as an int. Change it to alpha=0.3
to avoid conversion.
Upvotes: 3