Skip to main content
 首页 » 编程设计

python之tensorflow 中的 classifier.predict 错误(shape_and_slice 规范中的形状不匹配)

2025年05月04日22lovecherry

我是 tensorflow 的新手,为了了解基础知识,我正在学习教程。复制此代码 ( https://github.com/random-forests/tutorials/blob/master/ep7.ipynb ) 并尝试执行它时出现错误。

W tensorflow/core/framework/op_kernel.cc:993] Invalid argument: Shape in shape_and_slice spec [1,10] does not match the shape stored in checkpoint: [784,10] Traceback (most recent call last):...

似乎负责的命令如下:

 classifier.predict(test_data[0]) 

你能告诉我问题吗?

请您参考如下方法:

请试试

classifier.predict(np.array([test_data[0]], dtype=float), as_iterable=False) 

这对我有用