MNIST识别,数据集已经手动放入,代码已贴,报错为y_i值未知
tensorflow吧
全部回复
仅看楼主
level 3
先贴报错信息(部分,y_i调用的部分都报错了,选了一处贴上):
Caused by op 'y_input', defined at:
File "D:/Anaconda3/envs/tensorflow/untitled1/Mnist.py", line 87, in <module>
tf.app.run()
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\platform\app.py", line 124, in run
_sys.exit(main(argv))
File "D:/Anaconda3/envs/tensorflow/untitled1/Mnist.py", line 83, in main
train(mnist)
File "D:/Anaconda3/envs/tensorflow/untitled1/Mnist.py", line 32, in train
y_i = tf.placeholder(tf.float32, shape=[None, OUTPUT_NODE], name="y_input")
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1680, in placeholder
return gen_array_ops._placeholder(dtype=dtype, shape=shape, name=name)
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 4105, in _placeholder
"Placeholder", dtype=dtype, shape=shape, name=name)
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 3160, in create_op
op_def=op_def)
File "D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 1625, in __init__
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'y_input' with dtype float and shape [?,10]
[[Node: y_input = Placeholder[dtype=DT_FLOAT, shape=[?,10], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
源代码:
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import mnist_inference
import os
import requests
from requests.adapters import HTTPAdapter
BATCH_SIZE = 100
LEARNING_RATE_BASE = 0.8
LEARNING_RATE_DECAY = 0.99
REGULARIZATION_RATE = 0.0001
TRAINING_STEPS = 30000
MOVING_AVERAGE_DECAY = 0.99
MODEL_SAVE_PATH="MNIST_model/"
MODEL_NAME="mnist_model"
def train(mnist):
x = tf.placeholder(tf.float32, [None, mnist_inference.INPUT_NODE], name='x-input')
y_ = tf.placeholder(tf.float32, [None, mnist_inference.OUTPUT_NODE], name='y-input')
regularizer = tf.contrib.layers.l2_regularizer(REGULARIZATION_RATE)
y = mnist_inference.inference(x, regularizer)
global_step = tf.Variable(0, trainable=False)
variable_averages = tf.train.ExponentialMovingAverage(MOVING_AVERAGE_DECAY, global_step)
variables_averages_op = variable_averages.apply(tf.trainable_variables())
cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=tf.argmax(y_, 1), logits=y)
cross_entropy_mean = tf.reduce_mean(cross_entropy)
loss = cross_entropy_mean + tf.add_n(tf.get_collection('losses'))
learning_rate = tf.train.exponential_decay(
LEARNING_RATE_BASE,
global_step,
mnist.train.num_examples / BATCH_SIZE, LEARNING_RATE_DECAY,
staircase=True)
train_step = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss, global_step=global_step)
with tf.control_dependencies([train_step, variables_averages_op]):
train_op = tf.no_op(name='train')
saver = tf.train.Saver()
with tf.Session() as sess:
tf.global_variables_initializer().run()
for i in range(TRAINING_STEPS):
xs, ys = mnist.train.next_batch(BATCH_SIZE)
_, loss_value, step = sess.run([train_op, loss, global_step], feed_dict={x: xs, y_: ys})
if i % 1000 == 0:
print("After %d training step(s), loss on training batch is %g." % (step, loss_value))
saver.save(sess, os.path.join(MODEL_SAVE_PATH, MODEL_NAME), global_step=global_step)
def main(argv=None):
mnist = input_data.read_data_sets("../../../datasets/MNIST_data", one_hot=True)
train(mnist)
if __name__ == '__main__':
tf.app.run()
2018年03月12日 13点03分 1
level 6
# 迭代优化模型#
#可以帮忙解释一下,下面代码的功能含义吗
for i in range(20000):
# 每次取50个样本进行训练
batch = mnist.train.next_batch(50)
if i%200 == 0:
train_accuracy = accuracy.eval(feed_dict={
x: batch[0], y_: batch[1], keep_prob: 1.0}) # 模型中间不使用dropout
print("step %d, training accuracy %g" % (i, train_accuracy))
train_step.run(feed_dict={x:batch[0], y_:batch[1], keep_prob: 0.5})
print("test accuracy %g" % accuracy.eval(feed_dict={
x: mnist.test.images, y_: mnist.test.labels, keep_prob: 1.0}))
可以帮忙解释下吗谢谢大佬们了
2018年04月19日 07点04分 6
训练20000次,每200次算一次正确率。你这个工程里面写了一个accuracy文件,里面有一个自己写的eval函数,把batch数据传过去,可以计算正确率。其中keep_prob是一个用来优化过拟合现象的参数,训练的时候可以用(下面那个0.5就是)。 train_step.run就是跑网络了。
2018年04月20日 11点04分
谢谢大佬
2018年04月21日 03点04分
@莫名其妙zoz exec(compile(f.read(), filename, 'exec'), namespace) File "C:/Users/laohe/untitled0.py", line 114, in <module> im =reversePic(im)NameError: name 'reversePic' is not defined 这个错误怎么处理
2018年04月22日 02点04分
回复
������B�ĸ���
:reversePic应该你的程序里面自己写的一个函数,如果没有找到,就说明你函数名写错了或者没有写(拷贝过来)这个函数
2018年04月23日 04点04分
level 8
我同样遇到了这样的问题,
2018年04月24日 14点04分 7
你好 这个问题解决了吗?
2020年02月29日 03点02分
level 8
你的问题解决了吗?
2018年04月24日 14点04分 8
level 1
同求 应该是placeholder的问题
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder_1' with dtype int32 and shape [64]
[[Node: Placeholder_1 = Placeholder[dtype=DT_INT32, shape=[64], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
2018年06月06日 15点06分 9
level 1
楼主,给我也发一份,我也遇到这个问题了,不知道怎么解决??
2018年06月14日 13点06分 10
level 1
楼主,请问这个问题解决了吗?被这个问题困扰了好多天,还没解决,求解决方法,谢谢
2019年08月01日 01点08分 11
你好 这个问题解决了吗?
2020年02月29日 03点02分
1