Ich habe dies auf Reddit, Stack Overflow, Tech-Foren, Dokumentation, GitHub Probleme etc. etc und kann dieses Problem immer noch nicht lösen.Tensorflow ValueError: Zu viele Vaues zum Entpacken (erwartet 2)
Als Referenz verwende ich Python 3 TensorFlow
unter Windows 10, 64 Bit.
Ich versuche meinen eigenen Datensatz (300 Bilder von Katzen, 512x512, .png Format) in Tensorflow
zu verwenden, um es zu trainieren, um zu wissen, wie eine Katze aussieht. Wenn das klappt, werde ich es mit anderen Tieren und eventuell mit Objekten trainieren.
Ich kann nicht herausfinden, warum ich den Fehler ValueError: too many values to unpack (expected 2)
bekomme. Der Fehler erscheint in der Zeile images,labal = create_batches(10)
, die auf meine Funktion create_batches
zeigt (siehe unten). Ich weiß nicht, was das verursachen könnte, da ich relativ neu zu TensorFlow
bin. Ich versuche, mein eigenes Neuronales Netzwerk basierend auf dem MNIST-Datensatz zu erstellen. Code unten:
import tensorflow as tf
import numpy as np
import os
import sys
import cv2
content = []
labels_list = []
with open("data/cats/files.txt") as ff:
for line in ff:
line = line.rstrip()
content.append(line)
with open("data/cats/labels.txt") as fff:
for linee in fff:
linee = linee.rstrip()
labels_list.append(linee)
def create_batches(batch_size):
images = []
for img in content:
#f = open(img,'rb')
#thedata = f.read().decode('utf8')
thedata = cv2.imread(img)
thedata = tf.contrib.layers.flatten(thedata)
images.append(thedata)
images = np.asarray(images)
labels =tf.convert_to_tensor(labels_list,dtype=tf.string)
print(content)
#print(labels_list)
while(True):
for i in range(0,298,10):
yield images[i:i+batch_size],labels_list[i:i+batch_size]
imgs = tf.placeholder(dtype=tf.float32,shape=[None,262144])
lbls = tf.placeholder(dtype=tf.float32,shape=[None,10])
W = tf.Variable(tf.zeros([262144,10]))
b = tf.Variable(tf.zeros([10]))
y_ = tf.nn.softmax(tf.matmul(imgs,W) + b)
cross_entropy = tf.reduce_mean(-tf.reduce_sum(lbls * tf.log(y_),reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.05).minimize(cross_entropy)
sess = tf.InteractiveSession()
tf.global_variables_initializer().run()
for i in range(10000):
images,labal = create_batches(10)
sess.run(train_step, feed_dict={imgs:images, lbls: labal})
correct_prediction = tf.equal(tf.argmax(y_,1),tf.argmax(lbls,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction,tf.float32))
print(sess.run(accuracy, feed_dict={imgs:content, lbls:labels_list}))
Und der Fehler:
Traceback (most recent call last):
File "B:\Josh\Programming\Python\imgpredict\predict.py", line 54, in <module>
images,labal = create_batches(2)
ValueError: too many values to unpack (expected 2)
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
(A few hundred lines of this)
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
Mein GitHub link Link, wenn jemand sie braucht. Der Projektordner ist der "imgpredict".
Ich habe meinen Code geändert, aber habe den gleichen Fehler wie zuvor. –
könnten Sie hier die modifizierte Zeile hinzufügen oder die Frage bearbeiten? – DarkCygnus
'Ausbeute (Bilder [i: i + Stapelgröße], Etikettenliste [i: i + Stapelgröße])' und ich habe auch die Frage bearbeitet –