Reputation: 1
I was trying to run a code that creates some layers of a convolutional neural network and I get the following error:
Traceback (most recent call last): File "prova_error.py", line 39, in conv2_shape = tf.concat(0,[[-1],[tf.reduce_prod(tf.slice(tf.shape(h_conv2),[1],[3]),0)]]) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 336, in concat name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 180, in _concat name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 379, in apply_op assert dtype is not None, "Should not fail if dtype is None" AssertionError: Should not fail if dtype is None
I don't know what the error "Should not fail if dtype is None" means, there's no reference about it. I wanted to know what it means and how to solve it.
The code used is:
import tensorflow as tf
def weight_variable(shape,name=None):
initial=tf.truncated_normal(shape=shape,stddev=0.1)
return tf.Variable(initial,name=name)
def bias_variable(shape,name=None):
initial = tf.constant(value=0.0, shape=shape)
return tf.Variable(initial,name=name)
def conv2d(x, W, stride, pad = 'SAME'):
return tf.nn.conv2d(x, W, strides=[1, stride, stride, 1], padding=pad)
def max_pool(x, kernelSz, stride, pad = 'SAME'):
return tf.nn.max_pool(x, ksize=[1, kernelSz, kernelSz, 1], strides=[1, stride, stride, 1], padding=pad)
inputs=tf.placeholder("float")
targets=tf.placeholder("float",[None,1])
#conv layer 1
W_conv1=weight_variable([3,3,3,16],"w1")
b_conv1=bias_variable([16],"b1")
h_conv1=tf.nn.relu(conv2d(inputs,W_conv1,1)+b_conv1)
#pooling layer 1
h_pool1 = max_pool(h_conv1, 3, 2)
#fully conv layer 1
w_conv2 = weight_variable([6,6,16,16],"w2")
b_conv2 = bias_variable([16],"b2")
h_conv2 = tf.nn.relu(conv2d(h_pool1, w_conv2, 2, pad="VALID") + b_conv2)
#fully conv layer 2
w_conv3 = weight_variable([1,1,16,1],"w3")
b_conv3 = bias_variable([1],"b3")
h_conv3 = tf.nn.sigmoid(conv2d(h_conv2, w_conv3, 1) + b_conv3)
conv2_shape = tf.concat(0,[[-1],[tf.reduce_prod(tf.slice(tf.shape(h_conv2),[1],[3]),0)]])
h_conv2_reshaped = tf.reshape(h_conv2,conv2_shape)
conv3_shape = tf.concat(0,[[-1],[tf.reduce_prod(tf.slice(tf.shape(h_conv3),[1],[3]),0)]])
h_conv3_reshaped = tf.reshape(h_conv3,conv3_shape)
Thanks in advance
Upvotes: 0
Views: 167
Reputation: 1
Changing as you say I obtain:
Traceback (most recent call last): File "prova_error.py", line 39, in conv2_shape = tf.concat([[-1],[tf.reduce_prod(tf.slice(tf.shape(h_conv2),[1],[3]),0)]],0) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 331, in concat dtype=dtypes.int32).get_shape( File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 566, in convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/constant_op.py", line 179, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/constant_op.py", line 162, in constant tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape)) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 332, in make_tensor_proto _AssertCompatible(values, dtype) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 272, in _AssertCompatible (dtype.name, repr(mismatch), type(mismatch).name)) TypeError: Expected int32, got list containing Tensors of type '_Message' instead.
The version of Tensorflow installed is 0.8.0. I saw that for the new versions of tensorflow the position of parameters of tf.concat change, but in this case it was correct.
Upvotes: 0