解決策を見つけようとする多くのフォーラムサイトを調べましたが、取得できませんでした。Tensorflow ValueError:画像を含む配列を持つ配列要素を設定する
Tensorflow(Python 3、Win 10 64ビット)を独自のイメージセットで使用しようとしています。私はそれを実行すると、私はValueErrorを取得します。具体的に:
Traceback (most recent call last):
File "B:\Josh\Programming\Python\imgpredict\predict.py", line 62, in <module>
sess.run(train_step, feed_dict={imgs:batchX, lbls: batchY})
File "C:\Users\Josh\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 789, in run
run_metadata_ptr)
File "C:\Users\Josh\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 968, in _run
np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
File "C:\Users\Josh\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\numeric.py", line 531, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.
私のコードは次のとおりです。
import tensorflow as tf
import numpy as np
import os
import sys
import cv2
content = [] # Where images are stored
labels_list = []
########## File opening function
with open("data/cats/files.txt") as ff:
for line in ff:
line = line.rstrip()
content.append(line)
#################################
########## Labels opening function
with open("data/cats/labels.txt") as fff:
for linee in fff:
linee = linee.rstrip()
labels_list.append(linee)
labels_list = np.array(labels_list)
###############################
def create_batches(batch_size):
images1 = []
for img1 in content:
thedata = cv2.imread(img1)
thedata = tf.contrib.layers.flatten(thedata)
images1.append(thedata)
images1 = np.asarray(images1)
images1 = np.array(images1)
while(True):
for i in range(0,298,10):
yield(images1[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):#########################################
for (batchX,batchY) in create_batches(10):
for inn, imgs in enumerate(batchX):
batchX[inn] = imgs.eval()
sess.run(train_step, feed_dict={imgs:batchX, lbls: batchY})
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}))
エラーが私のイメージ、または私のラベルからのものである場合、私は知りません。私は、他のSOの質問、Reddit、Google Plus、GitHub Issuesなどからたくさんの提案を試みましたが、役に立たないものです。プロジェクトのための私のGitHubのリンクは次のとおりです。https://github.com/supamonkey2000/jm-uofa
とプロジェクトフォルダは「imgpredict」
感謝すべてのヘルプです。事前に感謝します
提案に感謝、私は今日仕事に入るときにそれらを試してみるでしょう。私は何かが私の262144の価値に間違っていたことを知っていた.... –
完璧な、これは最初のエラーを排除!今次のエラーに...助けてくれてありがとう:) –