|
9#
楼主 |
发表于 2020-12-30 09:47:28
|
只看该作者
device = torch.device("cpu")
weights = 'plate.pt'
model = torch.load(weights, map_location=device)['model'].float().eval()
# torch.save(model.state_dict(), 'model.pth')
# model = Model(opt.cfg, nc=80).to(device)
img_size = 640
img = cv2.imread('00085.jpg')
w, h, _ = img.shape
h_ratio = h / img_size
w_ratio = w / img_size
img1 = cv2.resize(img, (640, 640))
img1 = img1[:, :, ::-1].transpose(2, 0, 1)
img1 = np.ascontiguousarray(img1)
img1 = np.asarray(img1, 'f')
img1.flags.writeable = True
img1 /= 255.0
x = np.expand_dims(img1, 0)
x = torch.from_numpy(x).to(device)
start = time.time()
pred = model(x)[0]
print(time.time() - start)
pred = non_max_suppression(pred, conf_thres=0.5, iou_thres=0.5, agnostic=False)[0]
print(pred) |
|