spiglerg / RNN_Text_Generation_Tensorflow

DEPRECATED CODE : Text generation using RNN (LSTM) implemented using Tensorflow
Apache License 2.0
111 stars 49 forks source link

Mismatching Tensor Shapes #15

Open anonezumi opened 6 years ago

anonezumi commented 6 years ago

I know my last issue was my fault, but I don't think this one is. I got an argument error about a minute after starting the program. Here's the full error:

Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1350, in _do_call
    return fn(*args)
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1329, in _run_fn
    status, run_metadata)
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 473, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [256,67] rhs shape= [256,39]
         [[Node: save/Assign = Assign[T=DT_FLOAT, _class=["loc:@char_rnn_network/Variable"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](char_rnn_network/Variable, save/RestoreV2)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "rnn_tf.py", line 309, in <module>
    main()
  File "rnn_tf.py", line 261, in main
    check_restore_parameters(sess, saver)
  File "rnn_tf.py", line 191, in check_restore_parameters
    saver.restore(sess, ckpt.model_checkpoint_path)
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 1686, in restore
    {self.saver_def.filename_tensor_name: save_path})
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\client\session.py", line 895, in run
    run_metadata_ptr)
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1128, in _run
    feed_dict_tensor, options, run_metadata)
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1344, in _do_run
    options, run_metadata)
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1363, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [256,67] rhs shape= [256,39]
         [[Node: save/Assign = Assign[T=DT_FLOAT, _class=["loc:@char_rnn_network/Variable"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](char_rnn_network/Variable, save/RestoreV2)]]

Caused by op 'save/Assign', defined at:
  File "rnn_tf.py", line 309, in <module>
    main()
  File "rnn_tf.py", line 257, in main
    saver = tf.train.Saver(tf.global_variables())
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 1239, in __init__
    self.build()
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 1248, in build
    self._build(self._filename, build_save=True, build_restore=True)
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 1284, in _build
    build_save=build_save, build_restore=build_restore)
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 765, in _build_internal
    restore_sequentially, reshape)
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 440, in _AddRestoreOps
    assign_ops.append(saveable.restore(tensors, shapes))
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 160, in restore
    self.op.get_shape().is_fully_defined())
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\ops\state_ops.py", line 276, in assign
    validate_shape=validate_shape)
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\ops\gen_state_ops.py", line 62, in assign
    use_locking=use_locking, name=name)
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 3160, in create_op
    op_def=op_def)
  File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1625, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [256,67] rhs shape= [256,39]
         [[Node: save/Assign = Assign[T=DT_FLOAT, _class=["loc:@char_rnn_network/Variable"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](char_rnn_network/Variable, save/RestoreV2)]]
WocMaker commented 3 years ago

You need also change the input file path to match with the one you have used to train the model