J'ai regardé cela sur Reddit, Stack Overflow, les forums techniques, la documentation, les problèmes GitHub etc. etc et ne peut toujours pas résoudre ce problème.Tensorflow ValueError: Trop de vaues pour décompresser (attendu 2)
Pour référence, j'utilise Python 3 TensorFlow
sous Windows 10, 64 bits. J'essaie d'utiliser mon propre jeu de données (300 photos de chats, 512x512, format .png) en Tensorflow
pour l'entraîner à savoir à quoi ressemble un chat. Si cela fonctionne je vais l'entraîner avec d'autres animaux et éventuellement des objets. Je n'arrive pas à comprendre pourquoi je reçois l'erreur ValueError: too many values to unpack (expected 2)
. L'erreur apparaît dans la ligne images,labal = create_batches(10)
, qui pointe vers ma fonction create_batches
(voir ci-dessous). Je ne sais pas ce qui pourrait être la cause de ce que je suis assez nouveau à TensorFlow
. J'essaie de créer mon propre réseau de neurones basé sur le jeu de données MNIST. Code ci-dessous:
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}))
Et l'erreur:
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
Mon lien GitHub link si quelqu'un en a besoin. Le dossier du projet est le "imgpredict".
J'ai modifié mon code, mais j'ai eu la même erreur qu'avant. –
pourriez-vous ajouter la ligne modifiée ici ou modifier la question? – DarkCygnus
'rendement (images [i: i + taille_batch], liste_tiquettes [i: i + taille_batch])' et j'ai aussi édité la question –