Closed lyzKF closed 1 year ago
Can you please provide me with your onnx model so that I can try to recreate the above.
@cyrusbehr yep, i download the onnx model through this scripts
#import onnx
import torch
import torchvision
#import netron
torch.set_default_tensor_type('torch.FloatTensor')
torch.set_default_tensor_type('torch.cuda.FloatTensor')
net = torchvision.models.resnet18(pretrained=True).cuda()
net.eval()
export_onnx_file = "./resnet50.onnx"
x=torch.onnx.export(net,
torch.randn(1, 3, 224, 224, device='cuda'),
export_onnx_file,
verbose=False,
input_names=["input"],
output_names=["output"],
opset_version=10,
do_constant_folding=True,
)
export_onnx_file = "./resnet50_dynamic.onnx"
x=torch.onnx.export(net,
torch.randn(1, 3, 224, 224, device='cuda'),
export_onnx_file,
verbose=False,
input_names=["input"],
output_names=["output"],
opset_version=10,
do_constant_folding=True,
dynamic_axes={"input":{0: "batch_size"}, "output":{0: "batch_size"},}
)
For me , just add a resize function to resize the image to you input shape fix the problem. cv::resize(image, image, cv::Size(image_size, image_size), cv::INTER_LINEAR);
Hi, sorry it's taken me so long to get back to you, but yes as @LeeYimingAI has mentioned, it seems the issue is that you are using a model which has an input size of (1, 3, 224, 224), while my code expect a model of size (1, 3, 112, 112). The test images I provide are of this size, so if you try to use it with a model expecting a different input size, it crashes. I have now both provided a sample model for you to try out, more robust code which will warn of any size mismatch errors, and have indicated where in the code you would resize your image if it is required.
@cyrusbehr Hi, i follow your codes and run the demo, "Segmentation fault (core dumped)" will occur sometimes. here is the demo:
i debug the program, codes in the file "engine.cpp" can cause this, but i don't know why
looking forward to your reply, thank you