ValueError: Cannot feed value of shape (420,) for Tensor u'Placeholder_1:0', which has shape (Dimension(None), Dimension(6))
というエラーが起きます。
TensorFlowのチュートリアルを少し変更して音楽データの分類をしてもらおうと思っています。下記のコードですが、チュートリアルから少し変えただけです。読み込むデータはcepsというもので13の次元を持つ配列です(表現間違ってたらごめんなさい)、600個のデータがあります。
-- coding: utf-8 --
from future import absolute_import, unicode_literals
import tensorflow as tf
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from utils import GENRE_LIST
from ceps import read_ceps
genre_list = GENRE_LIST
X, y = read_ceps(genre_list)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
print "Start Tutorial"
x = tf.placeholder("float", [None, 13]) #読み込みデータの格納
W = tf.Variable(tf.zeros([13, 6])) #重みの定義
b = tf.Variable(tf.zeros([6])) #バイアスの定義
y = tf.nn.softmax(tf.matmul(x, W) + b) #モデルの定義
y_ = tf.placeholder("float", [None, 6]) #正解データの格納
cross_entropy = -tf.reduce_sum(y_ * tf.log(y)) #クロスエントロピーの定義
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
print "init"
init = tf.initialize_all_variables() #変数の初期化
sess = tf.Session()
sess.run(init) #実行
print "1000回学習と結果表示"
for i in range(1000):
sess.run(train_step, feed_dict={x: X_train, y_: y_train}) #データをxとy_に格納した後train_stepを実行
correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1)) #ブール値に変換
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) #浮動小数点にキャストして平均を取り出す
print sess.run(accuracy, feed_dict={x: X_test, y_: y_test})
#次のような実行結果が出ます。
Start Tutorial
init
I tensorflow/core/common_runtime/local_device.cc:40] Local device intra op parallelism threads: 4
I tensorflow/core/common_runtime/direct_session.cc:58] Direct session inter op parallelism threads: 4
Traceback (most recent call last):
1000回学習と結果表示
File "/Users/yamayaryo/PycharmProjects/Iris/MNIST.py", line 37, in <module>
sess.run(train_step, feed_dict={x: X_train, y_: y_train}) #データをxとy_に格納した後train_stepを実行
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 364, in run
tuple(subfeed_t.get_shape().dims)))
ValueError: Cannot feed value of shape (420,) for Tensor u'Placeholder_1:0', which has shape (Dimension(None), Dimension(6))
このエラーはどのようにすれば消えるでしょうか?
よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。