从python 2移动时,python 3中的Tensor Feed dict形状不匹配

时间:2019-01-26 19:36:30

标签: python python-3.x python-2.7 tensorflow machine-learning

我是Tensorflow的新手。我试图在python 3中运行用python 2编写的代码。

这是张量馈送字典:

{<tf.Tensor 'simple_lstm/at:0' shape=(64, ?, ?) dtype=int32>:

这是回溯:

Traceback (most recent call last):
  File "main.py", line 530, in <module>
    train(config)
  File "main.py", line 337, in train
    loss,train_op = trainer.step(sess,batch)
  File "trainer.py", line 32, in step
    loss, train_op = sess.run([self.loss,self.train_op],feed_dict=feed_dict)
  File "lib/python3.6/site-packages/tensorflow/python/client/session.py", line 905, in run
    run_metadata_ptr)
  File "lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1116, in _run
    str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (0,) for Tensor 'simple_lstm/pre_emb_mat:0', which has shape '(?, 100)'

trainer.py中的相关代码:

def step(self,sess,batch):
                assert isinstance(sess,tf.Session)

                batchIdx,batch_data = batch
                feed_dict = self.model.get_feed_dict(batch_data,is_train=True)
                print(feed_dict)
                loss, train_op = sess.run([self.loss,self.train_op],feed_dict=feed_dict)
                return loss, train_op

如何解决该错误?是否有任何针对TF迁移到python3的准则?

0 个答案:

没有答案