Processed_image()函数返回一个cv2.Umat类型值,该值将从
3维(h, ch, w)
到4维(h, ch, w, 1)
,因此i
需要将其转换
到numpy数组,或者如果可能的话还可以帮助我直接重塑cv2.umat
类型变量可以直接重塑并转换为pytorch张量,并且可以
分配给reshaped_image_tensor。
img_w=640
img_h=640
img_ch=3
umat_img = cv2.UMat(img)
display_one(umat_img, "RESPONSE") #function created by me to display image
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
with torch.no_grad():
processed_img = preprocess_image(umat_img, model_image_size = (img_h, img_ch, img_w))
#___________write YOUR CODE here________
reshaped_images_tensor = torch.from_numpy(processed_img.reshape(img_h, img_ch, img_w, 1)).float().to(device) #images_tensor.reshape(img_h, img_ch, img_w, 1)
outputs = model(reshaped_images_tensor)
_, predicted = torch.max(outputs, 1)
c = predicted.squeeze()
output_probability(predicted, processed_img, umat_img)
if ord('q')==cv2.waitKey(10):
exit(0)