Giter VIP home page Giter VIP logo

Comments (2)

huangshilong911 avatar huangshilong911 commented on June 12, 2024

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.

jaybdub avatar jaybdub commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.