用我自己的输入编写图像识别程序

时间:2018-10-11 19:47:14

标签: python tensorflow machine-learning image-recognition

我正在尝试创建一个将数据集作为自己的图像的图像识别程序。我只有506张图片(此程序基本上是概念证明)。我正在使用tensorflow,在送入图像和标签时会卡住。

Tensorflow具有此功能

batch_xs, batch_ys = mnist.train.next_batch(100)

但是我不能将其用于自己的输入。我尝试了train_test_split,但是在运行时,出现了一个值错误,指出

  

“无法为Tensor馈入形状值(379,50,50,1)   '占位符:0',其形状为'(?,2500)'“。

我不确定379的来源。有什么建议么?这是我的代码:

x = tf.placeholder(tf.float32, [None, 2500])

W = tf.Variable(tf.zeros([2500, 3]))

b = tf.Variable(tf.zeros([3]))

y = tf.nn.softmax(tf.matmul(x, W) + b)

y_ = tf.placeholder(tf.float32, [None, 3])

cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))

train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)

sess = tf.InteractiveSession()

tf.global_variables_initializer().run()

batch_xs, test_x, batch_ys, test__y = train_test_split(img, index, test_size = .25, random_state = 0)
sess.run(train_step, feed_dict= {x: batch_xs, y_: batch_ys})

correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

#figure out how to get xs and ys into this statement
print(sess.run(accuracy, feed_dict= {x: batch_xs, y_: batch_ys}))

0 个答案:

没有答案