接上回,https://www.hiascend.com/forum/thread-0239124904620783059-1-1.html
结尾处即使换成python3.7推理也会报错,报的是图编译的错。
还是用mindspore的接口来进行mindir的推理
import numpy as np
import cv2 as cv
import time
import numpy as np
import mindspore as ms
import mindspore.nn as nn
from mindspore import Tensor
from mindspore import context
context.set_context(mode=context.GRAPH_MODE)
graph = ms.load("yolov5s.mindir")
net = nn.GraphCell(graph)
in_data = cv.imread("C:\\ai\\infer\\data\\images\\dog.jpg")
img = cv.resize(in_data, (640,640), interpolation=cv.INTER_LINEAR)
image_np_expanded = img.astype('float32') / 255.0
input_tensor = Tensor(image_np_expanded)
print(input_tensor.shape)
img_dim=in_data.shape[:2]
output = net(input_tensor)
print(output[0].shape)
print(output[1].shape)
print(output[2].shape)
复制
推理输出的shape分别为
(1, 20, 20, 3, 85)
(1, 40, 40, 3, 85)
(1, 80, 80, 3, 85)
这个就是对应下图的输出,略有差异是因为输入图像的shape不一致导致的。
对应mindspore
三个特征图中,最大的80, 80 负责检测小目标,而对应到640*640上,每格特征图的感受野是640/80=8*8大小。
40, 40 负责检测中等