スタックオーバーフローやその他のフォーラムを閲覧しましたが、問題。しかし、それはthis questionに関連しているようです。Tensorflowは、テンソル 'x:0'の形状 '(?、128)'の形状(1、)の値を供給できません。
TensorflowのMNISTチュートリアルに従って、私は現在Tensorflowの訓練モデル(128入力と11出力)を保存しています。
これは成功したようで、3つのファイル(.meta、.ckpt.data、.index)でこのフォルダにモデルが作成されています。
ValueError: Cannot feed value of shape (1,) for Tensor 'x:0', which has shape '(?, 128)' Altough I print the shape of the 'unknowndata' and it matches the (1, 128). I also tried it with
sess.run(prediction, feed_dict={X: unknownData})) # with transposed etc. but nothing worked for me there I got the other error
TypeError: unhashable type: 'list'
は、私はこれだけ美しいのいくつかの予測をしたい...そこ
#encoding[0] => numpy ndarray (128,) # anyway a list with only one entry
#unknowndata = np.array(encoding[0])[None]
unknowndata = np.expand_dims(encoding[0], axis=0)
print(unknowndata.shape) # Output (1, 128)
# Restore pre-trained tf model
with tf.Session() as sess:
#saver.restore(sess, "models/model_1.ckpt")
saver = tf.train.import_meta_graph('models/model_1.ckpt.meta')
saver.restore(sess,tf.train.latest_checkpoint('models/./'))
y = tf.get_collection('final tensor') # tf.nn.softmax(tf.matmul(y2, W3) + b3)
X = tf.get_collection('input') # tf.placeholder(tf.float32, [None, 128])
# W1 = tf.get_collection('vars')[0]
# b1 = tf.get_collection('vars')[1]
# W2 = tf.get_collection('vars')[2]
# b2 = tf.get_collection('vars')[3]
# W3 = tf.get_collection('vars')[4]
# b3 = tf.get_collection('vars')[5]
# y1 = tf.nn.relu(tf.matmul(X, W1) + b1)
# y2 = tf.nn.relu(tf.matmul(y1, W2) + b2)
# yLog = tf.matmul(y2, W3) + b3
# y = tf.nn.softmax(yLog)
prediction = tf.argmax(y, 1)
print(sess.run(prediction, feed_dict={i: d for i,d in zip(X, unknowndata.T)}))
# also had sess.run(prediction, feed_dict={X: unknowndata.T}) and also not transposed, still errors
# Output: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # one should be 1 obviously with a specific percentage
私だけの問題で実行します。しかし、私はそれを復元したいとの予測のためにそれを使用しますTensorflow訓練モデル。
こんにちは、歓迎してStackOverflow!ここの人々はできるだけ多くの人を助けてくれるので忙しいので、誰もがコードの壁を読んでいるわけではありません。投稿を[編集する](https://stackoverflow.com/posts/46496213/edit)に[**最小限で完全で検証可能な例**]を含めることをお勧めします(https://stackoverflow.com/help/mcveあなたのコードの)。それはあなたが助ける返信を得るのを助けるでしょう。 – LW001
'sess.run(prediction、feed_dict = {X [0]:unknownData}))')についてはどうでしょうか? – lejlot
それは私が試したもので、うまくいきましたが、そこには128個のデータのうち1個だけが必要ですが、それらのすべてが正しいわけではありませんか?出力はまた、私に11回ゼロを与えます(少なくとも1つはそこにあるはずのものはありません) – lenlehm