Traceback (most recent call last): File "C:\Users\Lenovo\OneDrive\桌面\手写体数字识别代码及实验报告\code\code\test.py", line 14, in <module> model = tf.keras.models.load_model("models/mnist_conv") File "D:\新建文件夹\lib\site-packages\keras\saving\saving_api.py", line 212, in load_model return legacy_sm_saving_lib.load_model( File "D:\新建文件夹\lib\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler raise e.with_traceback(filtered_tb) from None File "D:\新建文件夹\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 703, in is_directory_v2 return _pywrap_file_io.IsDirectory(compat.path_to_bytes(path)) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x99 in position 33: invalid start byte
时间: 2023-06-30 15:16:21 浏览: 249
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
这个错误是因为在文件路径中含有非 UTF-8 编码的字符,可以尝试修改文件路径或者使用 Python 内置的 `os.path` 模块对文件路径进行处理。可以参考下面的代码进行修改:
```python
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import os
from tensorflow.keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_test = x_test / 255.0
def load_mnist_model(batch_size):
images, labels = x_test[:batch_size], y_test[:batch_size]
model_path = os.path.join("models", "mnist_conv")
model = tf.keras.models.load_model(model_path)
print("=" * 10)
predict = model.predict(images)
for i in range(batch_size):
predict_value = np.argmax(predict[i])
label = labels[i]
print("第%d张图片,预测值:%d,真实值:%d" % (i + 1, predict_value, label))
if __name__ == "__main__":
load_mnist_model(10000)
```
阅读全文