Ich habe alle Beispiele auf der Seite Tensorflow
unter Verwendung der MNIST-Datenbank ausgeführt. Jetzt versuche ich mein eigenes Beispiel zu führen und ich verstehe es einfach nicht.Fehler - Wert der Form X für Tensor kann nicht eingegeben werden
sagen, dass ich diese csv-Tabelle haben:
Es ist wie 5000 Zeilen. und die letzte Spalte ist die Bezeichnung für jede Zeile, diese besteht aus mehreren Funktionen. Nun zu meinem ersten konkreten Beispiel. Ich möchte ein NN auf diese Daten trainieren, denn das ist hier, was ich getan habe:
import tensorflow as tf
import numpy as np
import csv
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
# read training data
Training_file = open('onetest.csv', 'r', newline='')
reader = csv.reader(Training_file)
row = next(reader)
number_of_rows = 2431
x = tf.placeholder('float',[None,len(row[:-1])])
w = tf.Variable(tf.zeros([len(row[:-1]),25]))
b = tf.Variable(tf.zeros([25]))
model = tf.add(tf.matmul(x,w),b)
y_ = tf.placeholder('float',[25,None])
y = tf.nn.softmax(model)
cross_entropy= -tf.reduce_sum(y_*tf.log(y))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
index =1
batch_xs =[]
batch_ys= []
for row in reader:
batch_xs.append(row[:-1])
batch_ys.append(row[-1])
print(len(batch_xs),len(batch_ys))
index +=1
if index%10==0:
sess.run(train_step,feed_dict={x:batch_xs, y_:batch_ys})
correct_prediction = tf.equal(tf.arg_max(y,1),tf.arg_max(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction,"float"))
batch_xs.clear();
batch_ys.clear();
Hier gibt es Fehler, die ich bekomme:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-11-4dbaa38c4d9c> in <module>()
29 index +=1
30 if index%10==0:
---> 31 sess.run(train_step,feed_dict={x:batch_xs, y_:batch_ys})
32 correct_prediction = tf.equal(tf.arg_max(y,1),tf.arg_max(y_,1))
33 accuracy = tf.reduce_mean(tf.cast(correct_prediction,"float"))
c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)
765 try:
766 result = self._run(None, fetches, feed_dict, options_ptr,
--> 767 run_metadata_ptr)
768 if run_metadata:
769 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
942 'Cannot feed value of shape %r for Tensor %r, '
943 'which has shape %r'
--> 944 % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
945 if not self.graph.is_feedable(subfeed_t):
946 raise ValueError('Tensor %s may not be fed.' % subfeed_t)
ValueError: Cannot feed value of shape (9,) for Tensor 'Placeholder_17:0', which has shape '(25, ?)'
Ich habe den Wert des Index ändern aber es hat es nicht gelöst, also denke ich, dass ich etwas falsch verstehe. Ich werde für jede Erklärung dankbar sein.
dank Mirian für die Beantwortung. Ich habe meine Antwort gepostet! Danke noch einmal! – Engine