我在实现了MNIST图像识别的模型训练后,运行了测试例子,运行结果没有问题,但是我遇到了一个问题:我无法加载本地图片进行图片识别。
from datetime import date
from matplotlib import pyplot as plt
import jittor as jt
from numpy.core.fromnumeric import shape
from model import Model
from jittor.dataset.mnist import MNIST
import jittor.transform as trans
import numpy as np
import cv2
model_path = '/home/*****/Python_Demo/JittorMNISTImageClassification/mnist_model.pkl'
new_model = Model()
new_model.load_parameters(jt.load(model_path))
val_loader = MNIST(train=False, transform=trans.Resize(28)).set_attrs(batch_size=1, shuffle=False)
data_iter = iter(val_loader)
val_data, val_label = next(data_iter)
outputs = new_model(val_data)
prediction = np.argmax(outputs.data, axis=1)
print(val_label.data)
print(prediction)
程序运行结果如图
请大佬告知如何加载本地图片并利用模型进行图片识别。