-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
convert pytorch model into onnx version [Detection part] #24
Comments
I encountered the same problem。EdgeNets/nn_layers/efficient_pyramid_pool.py |
The problem that you are encountering is because PyTorch supports fractional pooling i.e. you can pool the tensors to sizes like 0.1 of the actual size. However, ONNX does not support such cases. We modified the code a bit while we converted our models to ONNX.
|
and this is the corresponding segmentation code:
|
and edited
|
I just modified the efficient_pyramid_pool.py and dont modify nothing file else. import torch
|
Hi @sacmehta, tried convert to onnx for segmentation model. |
Please use below efficient pyramid pool method
|
got another error: look like efficient_pt also need to modify |
|
|
Hi I am getting this warning ..while executing above code |
Use this version of Adaptive pooling
|
Hi sacmehta..while using this version of code ..I am getting like |
You need to use the code that is copied in this thread and not in the repo. |
I copied in this tread only.. import torch class Identity(nn.Module): class Interpolate(nn.Module):
class EfficientPyrPool(nn.Module):
class AdaptivePool(nn.Module):
|
Are you passing out_size to You need to make changes to segmentation model so that you can pass these arguments. Something like below code:
|
See the arguments of EfficientPyramid module:
|
Thank you for sharing this great code.
Right row, I want to deploy your model in to tvm platform, which may need conversion between pytorch and onnx, the code I used is like below.
weights = 'model/detection/model_zoo/espnetv2/espnetv2_s_2.0_pascal_300x300.pth'
model = ssd(args, cfg)
pretrained_dict = torch.load(weights, map_location=torch.device('cpu'))
model.load_state_dict(pretrained_dict)
PATH_ONNX='deploy.onnx'
dummy_input = torch.randn(1, 3, 300, 300, device='cpu')
torch.onnx.export(model, dummy_input, PATH_ONNX,
input_names = ['image'],
output_names= ['output'], verbose=True,opset_version=11)
but during the conversion, an error occurs,the info is below:
~/software/EdgeNets/nn_layers/eesp.py:139: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
if w2 == w1:
~/software/EdgeNets/nn_layers/eesp.py:89: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
if expanded.size() == input.size():
~/software/EdgeNets/nn_layers/efficient_pyramid_pool.py:44: TracerWarning: Converting a tensor to a Python float might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
h_s = int(math.ceil(height * self.scales[i]))
~/software/EdgeNets/nn_layers/efficient_pyramid_pool.py:45: TracerWarning: Converting a tensor to a Python float might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
w_s = int(math.ceil(width * self.scales[i]))
raise RuntimeError("Failed to export an ONNX attribute, "
RuntimeError: Failed to export an ONNX attribute, since it's not constant, please try to make things (e.g., kernel size) static if possible
please give some tips, which I can figure out the problem.
thank you for your help!
The text was updated successfully, but these errors were encountered: