Comments (2)
Here is my conversion script, based on the previous question, I tried to enter the parameters needed for the forward channel during the conversion:
import torch
from torch2trt import torch2trt
from torch2trt import TRTModule
device = torch.device("cuda")
print("CUDA visible devices: " + str(torch.cuda.device_count()))
print("CUDA Device Name: " + str(torch.cuda.get_device_name(device)))
model_path = "/home/jetson/Workspace/aicam/ircamera/vit_b_slim_step2_.pth"
SlimSAM_model = torch.load(model_path)
SlimSAM_model.image_encoder = SlimSAM_model.image_encoder.module
SlimSAM_model.to(device)
SlimSAM_model.eval()
print("model_path:",model_path)
SlimSAM_model.eval().cuda()
image = torch.zeros((3, 1024, 1024)).cuda()
original_size = (1024, 1024)
point_coords = torch.zeros((1, 5, 2)).cuda()
point_labels = torch.zeros((1, 5)).cuda()
boxes = torch.zeros((1, 4)).cuda()
mask_inputs = torch.zeros((1, 1, 1024, 1024)).cuda()
batched_input = [{
'image': image,
'original_size': original_size,
'point_coords': point_coords,
'point_labels': point_labels,
'boxes': boxes,
'mask_inputs': mask_inputs
}]
multimask_output = False
model_trt = torch2trt(SlimSAM_model, [batched_input, multimask_output], fp16_mode=True)
torch.save(model_trt.state_dict(), "./vit_b_slim_step2_trt.pth")
model_trt_engine = TRTModule()
model_trt_engine.load_state_dict(model_trt.state_dict())
torch.save(model_trt_engine.state_dict(), "vit_b_slim_step2_trt.engine")
But the following error was reported:
CUDA visible devices: 1
CUDA Device Name: Orin
model_path: /home/jetson/Workspace/aicam/ircamera/vit_b_slim_step2_.pth
Traceback (most recent call last):
File "convert-sam-trt_copy3.py", line 54, in <module>
model_trt = torch2trt(SlimSAM_model, [batched_input, multimask_output], fp16_mode=True)
File "/home/jetson/miniconda3/envs/sam0/lib/python3.8/site-packages/torch2trt-0.5.0-py3.8.egg/torch2trt/torch2trt.py", line 558, in torch2trt
outputs = module(*inputs)
File "/home/jetson/miniconda3/envs/sam0/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1111, in _call_impl
return forward_call(*input, **kwargs)
File "/home/jetson/miniconda3/envs/sam0/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/home/jetson/Workspace/aicam/ircamera/segment_anything_kd/modeling/sam.py", line 98, in forward
image_embeddings = self.image_encoder(input_images)
File "/home/jetson/miniconda3/envs/sam0/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1111, in _call_impl
return forward_call(*input, **kwargs)
File "/home/jetson/Workspace/aicam/ircamera/segment_anything_kd/modeling/image_encoder.py", line 136, in forward
qkv_emb1 = torch.cat([qkv_emb1,qkv_outputs[num]],dim=0)
RuntimeError: Sizes of tensors must match except in dimension 0. Expected size 300 but got size 396 for tensor number 1 in the list.
from torch2trt.
Hi @huangshilong911 ,
Thanks for reaching out again.
It looks like the error occurs during the execution of the PyTorch model.
Do you experience this error simply by calling the following?
output = SlimSAM_model(*[batched_input, multimask_output])
Best,
John
from torch2trt.
Related Issues (20)
- Inconsistent inference results between PyTorch and converted TensorRT model with Selu operator
- Inconsistent inference results between PyTorch and converted TensorRT model with MaxPool2d operator
- Inconsistent inference results between PyTorch and converted TensorRT model with BatchNorm or InstanceNorm operator
- Inconsistent inference results between PyTorch and converted TensorRT model with Interpolate operator
- Inconsistent inference results between PyTorch and converted TensorRT model with ConvTranspose2d operator
- 'tensorrt.tensorrt.Builder' object has no attribute 'build_cuda_engine'
- python model successfully tested on polygraphy tensorrt, but failed, when loading on torch2trt
- torch2trt shows error when converting a model, even though regular pytorch -> onnx -> tensorrt and inference is successful
- [Question & FeatureRequest] Is that possible to convert a torch.nn.Module to TRTMoudle? HOT 1
- Error in converting hybridnets model using torch2trt
- Package is not PEP 517 compliant, making it incompatible with package managing tools
- AttributeError: 'tensorrt_bindings.tensorrt.INetworkDefinition' object has no attribute 'add_convolution'. Did you mean: 'add_convolution_nd'? HOT 2
- Segmentation fault on nn.Linear HOT 1
- AttributeError: 'DataParallel' object has no attribute 'img_size' HOT 2
- _trt.shape overflow when converting from pytorch to TRT HOT 5
- How to save a model to TRT file? Not covered in the docs HOT 1
- OSS-Fuzz Integration
- SyntaxWarning of dataset.py:61 HOT 1
- Unable to convert SigLIP text transformer due to missing model input when exporting model to onnx
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from torch2trt.