-
Notifications
You must be signed in to change notification settings - Fork 54
Description
I convert the model to onnx using the model_to_onnx.py, with the args:--dataset nyuv2 --last_ckpt ./trained_models/nyuv2/r34_NBt1D.pth
the model can be converted to model.onnx,
the input shape is :
NodeArg(name='rgb', type='tensor(float)', shape=[1, 3, 480, 640]) NodeArg(name='depth', type='tensor(float)', shape=[1, 1, 480, 640])
but when I use the onnx to do inference, using device = "cpu", not using cuda
error occurred:
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Non-zero status code returned while running Conv node. Name:'' Status Message: Input channels C is not equal to kernel channels * group. C: 514 kernel channels: 1024 group: 1
I cannot understand why the channels does not match, can you give me a hint?
here is my inference code:
def to_numpy(tensor):
return tensor.detach().cpu().numpy() if tensor.requires_grad else tensor.cpu().numpy()
if __name__ == '__main__':
img_path = "~/dataset/nyuv2/test/rgb/0028.png"
depth_path = "~/dataset/nyuv2/test/depth_raw/0028.png"
img = cv2.imread(img_path, cv2.IMREAD_UNCHANGED)
depth = cv2.imread(depth_path, cv2.IMREAD_UNCHANGED)
if img.ndim == 3:
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
depth = depth.astype('float32') * 0.1
#preprocess
#not write for short
session = onnxruntime.InferenceSession("./onnx_models/model.onnx")
inputs = {session.get_inputs()[0].name: to_numpy(img), session.get_inputs()[1].name: to_numpy(depth)}
outs = session.run(None, inputs)[0]
inputs shape:
'rgb': ndarray:(1, 3, 480, 640)
'depth': ndarray: (1, 1, 480, 640)