我正在尝试通过Libtorch中的DeepLab模型运行图像以对其进行分割。使用pytorch,我正在像这样转换Deeplabv3模型:
{name:'Belmont Race', address:{ state:'TN' }}
现在,在带有LibTorch的c ++中,我正在尝试加载模型并通过它运行数据。但是,这失败了:
import torch
import torchvision
from torchvision import models
deeplap_model = models.segmentation.deeplabv3_resnet101(pretrained=True)
deeplap_model.eval()
class wrapper(torch.nn.Module):
def __init__(self, model):
super(wrapper, self).__init__()
self.model = model
def forward(self, input):
results = []
output = self.model(input)
for k, v in output.items():
results.append(v)
return tuple(results)
model = wrapper(deeplap_model)
example = torch.rand(1, 3, 224, 224)
# Use torch.jit.trace to generate a torch.jit.ScriptModule via tracing.
traced_script_module = torch.jit.trace(model, example)
traced_script_module.save("model.pt")
我在哪里错了?