You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
541 B
28 lines
541 B
3 years ago
|
import cv2
|
||
|
import torchvision.transforms as transforms
|
||
|
import numpy as np
|
||
|
net = cv2.dnn.readNetFromONNX("ministNet.onnx") # 加载训练好的识别模型
|
||
|
img = cv2.imread('./data/8.png')
|
||
|
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
|
||
|
img = img/255
|
||
|
|
||
|
transf = transforms.ToTensor()
|
||
|
imgTensor = transf(img).unsqueeze(0)
|
||
|
|
||
|
|
||
|
|
||
|
im = img[np.newaxis, np.newaxis,:, :]
|
||
|
im = im.astype(np.float32)
|
||
|
outNames = net.getUnconnectedOutLayersNames()
|
||
|
net.setInput(im)
|
||
|
out = net.forward(outNames)
|
||
|
|
||
|
|
||
|
ind = np.where(out[0][0]==np.max(out[0][0]))
|
||
|
print(ind[0])
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|