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

.predict() doesn't work after loading a model #9

Closed
morus12 opened this issue Apr 5, 2016 · 2 comments
Closed

.predict() doesn't work after loading a model #9

morus12 opened this issue Apr 5, 2016 · 2 comments

Comments

@morus12
Copy link

morus12 commented Apr 5, 2016

Hi,
I was playing with lstm.py example and noticed that it's crashing when it tries to predict from restored model. Mayby i'm doing something wrong, but you can reproduce this using this gist:
https://gist.github.com/morus12/846eedb8c90423ecd8b28c2440be6d6d

Output:

Run id: 2I82V8
Log directory: /tmp/tflearn_logs/
---------------------------------
Training samples: 10373
Validation samples: 25000
--
Training Step: 82  | total loss: 0.48628
| Adam | epoch: 001 | loss: 0.48628 - acc: 0.7767 | val_loss: 0.48750 - val_acc: 0.7694 -- iter: 00000/10373
--
[[0.06058039888739586, 0.9394195675849915]]
WARNING:tensorflow:Error encountered when serializing layer_variables/LSTM/.
Type is unsupported, or the types of the items don't match field type in CollectionDef.
'NoneType' object has no attribute 'name'
W tensorflow/core/common_runtime/executor.cc:1102] 0x7fc637a34520 Compute status: Failed precondition: Attempting to use uninitialized value Dense/W
     [[Node: Dense/W/read = Identity[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](Dense/W)]]
     [[Node: _recv_InputData/X_0 = _Recv[client_terminated=true, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=-9003797786948543025, tensor_name="InputData/X:0", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Traceback (most recent call last):
  File "lstm.py", line 60, in <module>
    print(model.predict(pad_sequences([[1,2,3]], maxlen=50, value=0.)))
  File "/usr/local/lib/python2.7/site-packages/tflearn/models/dnn.py", line 177, in predict
    return self.predictor.predict(feed_dict)
  File "/usr/local/lib/python2.7/site-packages/tflearn/helpers/evaluator.py", line 53, in predict
    o_pred = self.session.run(output, feed_dict=feed_dict).tolist()
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 315, in run
    return self._run(None, fetches, feed_dict)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 511, in _run
    feed_dict_string)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 564, in _do_run
    target_list)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 586, in _do_call
    e.code)
tensorflow.python.framework.errors.FailedPreconditionError: Attempting to use uninitialized value Dense/W
     [[Node: Dense/W/read = Identity[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](Dense/W)]]
Caused by op u'Dense/W/read', defined at:
  File "lstm.py", line 46, in <module>
    net = tflearn.fully_connected(net, 2, activation='softmax')
  File "/usr/local/lib/python2.7/site-packages/tflearn/layers/core.py", line 116, in fully_connected
    trainable=trainable, restore=restore)
  File "/usr/local/lib/python2.7/site-packages/tflearn/variables.py", line 54, in variable
    collections=collections)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 256, in get_variable
    trainable, collections)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 188, in get_variable
    self.reuse, trainable, collections)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 132, in get_variable
    collections=collections)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/variables.py", line 195, in __init__
    name=name)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/variables.py", line 242, in _init_from_args
    self._snapshot = array_ops.identity(self._variable, name="read")
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 436, in identity
    return _op_def_lib.apply_op("Identity", input=input, name=name)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/op_def_library.py", line 655, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2040, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1087, in __init__
    self._traceback = _extract_stack()

@aymericdamien
Copy link
Member

Thanks for reporting the issue, there was a problem with layer_variables collection. I just fixed it.

You can reinstall TFLearn:

pip uninstall tflearn
pip install git+https://github.com/tflearn/tflearn.git

And it should works :)

@morus12
Copy link
Author

morus12 commented Apr 6, 2016

Work like a charm. Thank you!

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

2 participants