sess.run接收返回值得变量和sess.run函数內的tensor型变量命名注意不能一致,影响迭代,产生报错:Can not convert a ndarray into a Tensor
生活随笔
收集整理的這篇文章主要介紹了
sess.run接收返回值得变量和sess.run函数內的tensor型变量命名注意不能一致,影响迭代,产生报错:Can not convert a ndarray into a Tensor
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
這類問題是初次使用tensorflow常犯的錯誤,錯誤原因是sess.run之前的tensor list和函數(shù)內(nèi)的tensor list命名一致,導(dǎo)致在迭代運行時使得原有的tensor變量被賦值成float或其他類型,導(dǎo)致迭代運行出錯。
例:
result,acc1,cross_entropy,fcl_softmax=sess.run([optimizer,acc,cross_entropy,fcl_softmax],feed_dict = {images_input:train_batch,labels_input:test_batch})這裏sess.run之前的cross_entropy是float類型,但是sess.run中的cross_entropy是tensor,故出現(xiàn)上述報錯。同樣的fcl_softmax也是前後命名相同,有可能也會錯。
為方便起見,一律改成:
result_,acc1_,cross_entropy_,fcl_softmax_=sess.run([optimizer,acc,cross_entropy,fcl_softmax],feed_dict = {images_input:train_batch,labels_input:test_batch})?
總結(jié)
以上是生活随笔為你收集整理的sess.run接收返回值得变量和sess.run函数內的tensor型变量命名注意不能一致,影响迭代,产生报错:Can not convert a ndarray into a Tensor的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UnicodeDecodeError:
- 下一篇: Tensorflow详解保存模型(基础版