目标:我想使用预训练的更快的RCNN模型从图像中提取特征
我尝试的内容:我使用以下代码构建模型:
import torchvision.models as models
from PIL import Image
import torchvision.transforms as T
import torch
# download the pretrained fasterrcnn model
model = models.detection.fasterrcnn_resnet50_fpn(pretrained=True)
model.eval()
model.cuda()
# remove [2:] layers
modules = list(model.children())[:2]
model_t=torch.nn.Sequential(*modules)
# load image and extract features
img = Image.open('data/person.jpg')
transform = T.Compose([T.ToTensor()])
img_t = transform(img)
batch_t = torch.unsqueeze(img_t, 0).cuda()
ft = model_t(batch_t)
错误:但我得到了以下错误:TypeError: conv2d(): argument 'input' (position 1) must be Tensor, not tuple
请帮忙!谢谢大家!
print(model.modules)
以获取图层名称。然后使用以下命令删除图层:相关问题 更多 >
编程相关推荐