google-deepmind / learning-to-learn

Learning to Learn in TensorFlow
https://arxiv.org/abs/1606.04474
Apache License 2.0
4.06k stars 599 forks source link

structures don't have the same sequence type #22

Closed ylfzr closed 5 years ago

ylfzr commented 6 years ago

I ran python train.py --problem=mnist --save_path=./mnist. And got the following error. I have no idea what is wrong with it, can anyboby help?

Traceback (most recent call last): File "/Users/ylfzr/Documents/Projects/learning-to-learn-master/train.py", line 117, in tf.app.run() File "/Users/ylfzr/anaconda/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "/Users/ylfzr/Documents/Projects/learning-to-learn-master/train.py", line 70, in main second_derivatives=FLAGS.second_derivatives) File "/Users/ylfzr/Documents/Projects/learning-to-learn-master/meta.py", line 401, in meta_minimize info = self.meta_loss(make_loss, len_unroll, **kwargs) File "/Users/ylfzr/Documents/Projects/learning-to-learn-master/meta.py", line 360, in meta_loss name="unroll") File "/Users/ylfzr/anaconda/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2775, in while_loop result = context.BuildLoop(cond, body, loop_vars, shape_invariants) File "/Users/ylfzr/anaconda/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2604, in BuildLoop pred, body, original_loop_vars, loop_vars, shape_invariants) File "/Users/ylfzr/anaconda/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2561, in _BuildLoop nest.assert_same_structure(list(packed_vars_for_body), list(body_result)) File "/Users/ylfzr/anaconda/lib/python2.7/site-packages/tensorflow/python/util/nest.py", line 200, in assert_same_structure _recursive_assert_same_structure(nest1, nest2, check_types) File "/Users/ylfzr/anaconda/lib/python2.7/site-packages/tensorflow/python/util/nest.py", line 173, in _recursive_assert_same_structure _recursive_assert_same_structure(n1, n2, check_types) File "/Users/ylfzr/anaconda/lib/python2.7/site-packages/tensorflow/python/util/nest.py", line 173, in _recursive_assert_same_structure _recursive_assert_same_structure(n1, n2, check_types) File "/Users/ylfzr/anaconda/lib/python2.7/site-packages/tensorflow/python/util/nest.py", line 173, in _recursive_assert_same_structure _recursive_assert_same_structure(n1, n2, check_types) File "/Users/ylfzr/anaconda/lib/python2.7/site-packages/tensorflow/python/util/nest.py", line 173, in _recursive_assert_same_structure _recursive_assert_same_structure(n1, n2, check_types) File "/Users/ylfzr/anaconda/lib/python2.7/site-packages/tensorflow/python/util/nest.py", line 159, in _recursive_assert_same_structure % (type_nest1, type_nest2)) TypeError: The two structures don't have the same sequence type. First structure has type <type 'tuple'>, while second structure has type <class 'sonnet.python.modules.gated_rnn.LSTMState'>.

Macos 10.12.6 tensorflow version used: 1.3.0

louisfaury commented 6 years ago

I had the same problem today, on MacOs 10.12.6 and Tensorflow 1.4.0. Will be interested if you find how to fix it!

chenaddsix commented 6 years ago

I had the same problem today, on ubuntu 16.04 and tensorflow 1.4.0

zjnqh commented 6 years ago

Encountering the same problem with Centos, kind of hoping for a solution.

federicohyo commented 6 years ago

I had the same problem. I solved it by using these versions of tensorflow and sonnet. dm-sonnet requires tensorflow 1.5 , see -> https://github.com/deepmind/sonnet .

pip uninstall tensorflow pip uninstall dm-sonnet

pip install tensorflow==1.5.0 pip install dm-sonnet==1.7

I hope this helps, Federico

johnsears commented 6 years ago

Would be helpful to check in a requirements.txt file.

xiaozhouxiao commented 6 years ago

same problem here - even though I have tensorflow 1.7. Does it have to be version 1.5? Has anyone tried/figured out a way around this? Thanks.

jli238 commented 6 years ago

having the same problem even change to tf 1.5.0. Did anyone figure out any possible solutions to this problem yet? Thank you.

mily33 commented 6 years ago

It is because the input and output of the LSTMcell don't have the same type in tf.while_loop. The problem can be solved by a slight change in meta.py. line 305 state.append(_nested_variable( [net.initial_state_for_inputs(x[j], dtype=tf.float32) for j in subset], name="state", trainable=False)) to state.append([net.initial_state_for_inputs(x[j], dtype=tf.float32) for j in subset])

line 368 variables = (nest.flatten(_nested_variable(state)) + x + constants)

line 377 update = (nest.flatten(_nested_assign(x, x_final)) + nest.flatten(_nested_assign(_nested_variable(state), s_final)))

Hope this help!

hitvoice commented 6 years ago

@mily33 's method works with tf1.4.1 on Mac and Ubuntu. Thanks!

minhnhat93 commented 6 years ago

had similar problems, @mily33 solved the issues. would it be possible to have a PR to fix this on the main repo?

hoangcuong2011 commented 6 years ago

It works like a charm! Thanks @mily33

BigWZhu commented 5 years ago

@mily33 Thanks a lot for solving the problem