tensorflow简单的手写数字识别矩阵相乘时出现问题 5C

``````#载入数据集
mnist=input_data.read_data_sets("MNIST_data/",one_hot=True)

#每个批次大小
batch_size=100
#计算一共有多少批次
n_batch=mnist.train.num_examples//batch_size

#定义有两个placeholder
x=tf.placeholder(tf.float32,[None,784])
y=tf.placeholder(tf.float32,[None,10])

#创建一个简单的神经网络
W=tf.Variable(tf.zeros([784.10]))
b=tf.Variable(tf.zeros([10]))
prediction=tf.nn.softmax(tf.matmul(x,W)+b)

#二次代价函数
loss=tf.reduce_mean(tf.square(y-perdiction))
#梯度下降法
train_step=tf.train.GradientOptimizer(0.2).minimize(loss)

#初始化变量
init=tf.global_variable_initializer()

#结果存放在一个布尔型列表中
correct_prediction=tf.equal(tf.argmax(y,1),tf.argmax(prediction,1))#返回一维张量中最大值的位置
#求准确率
accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32))

with tf.Sessio() as sess:
sess.run(init)
for epoch in range(21):
for batch in range(n_batch):
batch_xs,batchys=mnist.train.next_batch(batch_size)
sess.run(train_step,feed_dict={x:batch_xs,y:batch_ys})

acc=sess.run(accury,feed_dict={x:mnis.test.images,y:mnist.test.labels})
print("Iter"+str(epoch)+",Testing Accuracy"+str(acc))
``````

``````Extracting MNIST_data/train-images-idx3-ubyte.gz
Extracting MNIST_data/train-labels-idx1-ubyte.gz
Extracting MNIST_data/t10k-images-idx3-ubyte.gz
Extracting MNIST_data/t10k-labels-idx1-ubyte.gz
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py in _create_c_op(graph, node_def, inputs, control_inputs)
1658   try:
-> 1659     c_op = c_api.TF_FinishOperation(op_desc)
1660   except errors.InvalidArgumentError as e:

InvalidArgumentError: Shape must be rank 2 but is rank 1 for 'MatMul_1' (op: 'MatMul') with input shapes: [?,784], [784].

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-5-5e22f4dd85e3> in <module>()
14 W=tf.Variable(tf.zeros([784.10]))
15 b=tf.Variable(tf.zeros([10]))
---> 16 prediction=tf.nn.softmax(tf.matmul(x,W)+b)
17
18 #二次代价函数

C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\ops\math_ops.py in matmul(a, b, transpose_a, transpose_b, adjoint_a, adjoint_b, a_is_sparse, b_is_sparse, name)
2453     else:
2454       return gen_math_ops.mat_mul(
-> 2455           a, b, transpose_a=transpose_a, transpose_b=transpose_b, name=name)
2456
2457

C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\ops\gen_math_ops.py in mat_mul(a, b, transpose_a, transpose_b, name)
5627   _, _, _op = _op_def_lib._apply_op_helper(
5628         "MatMul", a=a, b=b, transpose_a=transpose_a, transpose_b=transpose_b,
-> 5629                   name=name)
5630   _result = _op.outputs[:]
5631   _inputs_flat = _op.inputs

C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py in _apply_op_helper(self, op_type_name, name, **keywords)
786         op = g.create_op(op_type_name, inputs, output_types, name=scope,
787                          input_types=input_types, attrs=attr_protos,
--> 788                          op_def=op_def)
789       return output_structure, op_def.is_stateful, op
790

C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\util\deprecation.py in new_func(*args, **kwargs)
505                 'in a future version' if date is None else ('after %s' % date),
506                 instructions)
--> 507       return func(*args, **kwargs)
508
509     doc = _add_deprecated_arg_notice_to_docstring(

C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py in create_op(***failed resolving arguments***)
3298           input_types=input_types,
3299           original_op=self._default_original_op,
-> 3300           op_def=op_def)
3301       self._create_op_helper(ret, compute_device=compute_device)
3302     return ret

C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py in __init__(self, node_def, g, inputs, output_types, control_inputs, input_types, original_op, op_def)
1821           op_def, inputs, node_def.attr)
1822       self._c_op = _create_c_op(self._graph, node_def, grouped_inputs,
-> 1823                                 control_input_ops)
1824
1825     # Initialize self._outputs.

C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py in _create_c_op(graph, node_def, inputs, control_inputs)
1660   except errors.InvalidArgumentError as e:
1661     # Convert to ValueError for backwards compatibility.
-> 1662     raise ValueError(str(e))
1663
1664   return c_op

ValueError: Shape must be rank 2 but is rank 1 for 'MatMul_1' (op: 'MatMul') with input shapes: [?,784], [784].
``````

1个回答

![图片说明](https://img-ask.csdn.net/upload/201708/15/1502787619_872656.jpg) ![图片说明](https://img-ask.csdn.net/upload/201708/15/1502787634_794201.jpg) 网上下载的程序，不知道怎么回事，总是报这个错？ mnist数据具体是怎么加载的，是提前下载好放到某个目录下，还是可以在线下载？

Tensorflow实现手写数字识别，使用训练模型进行预测时，为什么精确度远不如训练精确度？？

tensorflow2.0 CNN识别手写数字测试结果出现问题

![图片说明](https://img-ask.csdn.net/upload/201903/02/1551537658_316059.png)

[源链接](http://download.csdn.net/download/xuyanjie0903/3380852 "") ![图片说明](https://img-ask.csdn.net/upload/201605/17/1463468200_662313.png) 求详细调试方法

mnist手写数字测试过程中出现的问题

mnist手写数字测试过程中，用自己的手写数字图片测试时出现问题，运行以下python代码： ![python代码](https://img-ask.csdn.net/upload/201710/27/1509074867_80775.png) 出现问题：.local/lib/python2.7/site-packages/skimage/transform/_warps.py:84: UserWarning: The default mode, 'constant', will be changed to 'reflect' in skimage 0.15. ![运行结果](https://img-ask.csdn.net/upload/201710/27/1509074829_731290.png) 图片格式： ![图片格式](https://img-ask.csdn.net/upload/201710/27/1509074941_15898.png)

Android端的手写文字识别sdk，大家有推荐的么？要求识别率高一点

Android端的手写文字识别sdk，大家有推荐的么？要求识别率高一点

tensorflow CNN训练mnist数据集后识别自己写的数字效果不好

MySQL数据库面试题（2020最新版）

2020阿里全球数学大赛：3万名高手、4道题、2天2夜未交卷

HashMap底层实现原理，红黑树，B+树，B树的结构原理 Spring的AOP和IOC是什么？它们常见的使用场景有哪些？Spring事务，事务的属性，传播行为，数据库隔离级别 Spring和SpringMVC，MyBatis以及SpringBoot的注解分别有哪些？SpringMVC的工作原理，SpringBoot框架的优点，MyBatis框架的优点 SpringCould组件有哪些，他们...

《Oracle Java SE编程自学与面试指南》最佳学习路线图2020年最新版（进大厂必备）

《Oracle Java SE编程自学与面试指南》最佳学习路线图（2020最新版）