Closed YaoJiawei329 closed 1 year ago
System information
import torch import onnxruntime as ort import cv2 import torchvision.transforms as transforms import numpy as np import onnx
onnx_model = onnx.load("mask_rcnn_47.onnx") onnx.checker.check_model(onnx_model) providers = ort.get_available_providers() sess = ort.InferenceSession("./mask_rcnn_47.onnx", providers=ort.get_available_providers())
image = cv2.imread("./data/metal_bar/train2017/32022-8-25-metal-16.jpg", 1) cv2.imshow("image", image) cv2.waitKey(1000) img = image[:, :, ::-1].transpose((2, 0, 1)).copy() tensor = torch.Tensor(img_) tensor2 = torch.unsqueeze(tensor, dim=0) print(tensor2.size()) tensor = torch.tensor(tensor2, dtype=torch.float32) img = tensor.numpy()
output = ["boxes", "class", "confidence", "result"] result = sess.run(output, {"images": img})
print("len of output = {}".format(len(result)))
Describe the current behavior maskrcnn导出onnx,onnxruntime输出第一个维度为0. backbone改为inceptionV2,训练出来的pt模型可以正常推理,转完onnx之后推理输出维度为0.
Error info / logs result = {list: 4} [array([], shape=(0, 4), dtype=float32), array([], dtype=int64), array([], dtype=float32), array([], shape=(0, 1, 1624, 920), dtype=float32)]
抱歉,这个问题我不清楚,可能是你自己导出的ONNX有问题。
System information
import torch import onnxruntime as ort import cv2 import torchvision.transforms as transforms import numpy as np import onnx
onnx_model = onnx.load("mask_rcnn_47.onnx") onnx.checker.check_model(onnx_model) providers = ort.get_available_providers() sess = ort.InferenceSession("./mask_rcnn_47.onnx", providers=ort.get_available_providers())
image = cv2.imread("./data/metal_bar/train2017/32022-8-25-metal-16.jpg", 1) cv2.imshow("image", image) cv2.waitKey(1000) img = image[:, :, ::-1].transpose((2, 0, 1)).copy() tensor = torch.Tensor(img_) tensor2 = torch.unsqueeze(tensor, dim=0) print(tensor2.size()) tensor = torch.tensor(tensor2, dtype=torch.float32) img = tensor.numpy()
output = ["boxes", "class", "confidence", "result"] result = sess.run(output, {"images": img})
print("len of output = {}".format(len(result)))
Describe the current behavior maskrcnn导出onnx,onnxruntime输出第一个维度为0. backbone改为inceptionV2,训练出来的pt模型可以正常推理,转完onnx之后推理输出维度为0.
Error info / logs result = {list: 4} [array([], shape=(0, 4), dtype=float32), array([], dtype=int64), array([], dtype=float32), array([], shape=(0, 1, 1624, 920), dtype=float32)]