Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Running Error Using Tensorflow 1.8.0 #14

Open
LiChenyang-Github opened this issue Jun 2, 2018 · 1 comment
Open

A Running Error Using Tensorflow 1.8.0 #14

LiChenyang-Github opened this issue Jun 2, 2018 · 1 comment

Comments

@LiChenyang-Github
Copy link

LiChenyang-Github commented Jun 2, 2018

My tensorflow version is 1.8.0
I clone the code to my computer and download the mnist_cluttered_60x60_6distortions.npz dataset into ./data/.
When I run the main.py, I get the following ERROR:

Loading the data...
Building ConvNet...
Traceback (most recent call last):
  File "/home/xinlab/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 517, in make_tensor_proto
    str_values = [compat.as_bytes(x) for x in proto_values]
  File "/home/xinlab/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 517, in <listcomp>
    str_values = [compat.as_bytes(x) for x in proto_values]
  File "/home/xinlab/anaconda3/lib/python3.6/site-packages/tensorflow/python/util/compat.py", line 67, in as_bytes
    (bytes_or_text,))
TypeError: Expected binary or unicode string, got -1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 422, in <module>
    main()
  File "main.py", line 275, in main
    pool3_flat, pool3_size = Flatten(pool3)
  File "/home/LiChenyang/spatial-transformer-network/utils/layer_utils.py", line 85, in Flatten
    layer_flat = tf.reshape(layer, [-1, num_features])
  File "/home/xinlab/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 6113, in reshape
    "Reshape", tensor=tensor, shape=shape, name=name)
  File "/home/xinlab/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 513, in _apply_op_helper
    raise err
  File "/home/xinlab/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 510, in _apply_op_helper
    preferred_dtype=default_dtype)
  File "/home/xinlab/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1104, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/home/xinlab/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 235, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/home/xinlab/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 214, in constant
    value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/home/xinlab/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 521, in make_tensor_proto
    "supported type." % (type(values), values))
TypeError: Failed to convert object of type <class 'list'> to Tensor. Contents: [-1, None]. Consider casting elements to a supported type.
LiChenyang@ubuntu:~/spatial-transformer-network$

Any idea to fix this problem?

@LiChenyang-Github
Copy link
Author

I guess the error is due to the last dimension of the target shape is None(i.e. [-1, None]) when execute the code: layer_flat = tf.reshape(layer, [-1, num_features]).
I try to print the h_trans and pool3 in main(), and I get:

Tensor("AddN:0", shape=(?, ?, ?, 1), dtype=float32)
Tensor("Relu_5:0", shape=(?, ?, ?, 128), dtype=float32)

The second and third dimension of h_trans is '?', which makes num_features in Flatten() None.

To verify this idea, I add a new function in ./utils/layer_utils.py:

def Flatten_test(layer):
	"""
	Handy function for flattening the result of a conv2D or
	maxpool2D to be used for a fully-connected (affine) layer.
	"""
	# layer_shape = layer.get_shape()
	# # num_features = tf.reduce_prod(tf.shape(layer)[1:])
	# num_features = layer_shape[1:].num_elements()

	num_features = 8 * 8 * 128
	layer_flat = tf.reshape(layer, [-1, num_features])

	return layer_flat, num_features

Manually calculate the num_features and change:
pool3_flat, pool3_size = Flatten(pool3)
into
pool3_flat, pool3_size = Flatten_test(pool3)

Finally, I can successfully run the main.py.

However, I still puzzle about why the num_features is None in Flatten()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant