Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用fasterrcnn\u resnet50\u fpn在Pytorch中进行迁移学习_Pytorch_Object Detection_Transfer Learning_Faster Rcnn - Fatal编程技术网

使用fasterrcnn\u resnet50\u fpn在Pytorch中进行迁移学习

使用fasterrcnn\u resnet50\u fpn在Pytorch中进行迁移学习,pytorch,object-detection,transfer-learning,faster-rcnn,Pytorch,Object Detection,Transfer Learning,Faster Rcnn,我正在寻找PyTorch中自定义数据集的对象检测 本教程提供了一个片段,用于将预先训练的模型用于自定义对象分类 我尝试使用类似的方法,使用更快的rcnn模型进行目标检测 # load a model pre-trained pre-trained on COCO model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True) model.eval() for param in model.paramete

我正在寻找PyTorch中自定义数据集的对象检测

本教程提供了一个片段,用于将预先训练的模型用于自定义对象分类

我尝试使用类似的方法,使用更快的rcnn模型进行目标检测

# load a model pre-trained pre-trained on COCO
model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True)
model.eval()
for param in model.parameters():
    param.requires_grad = False
# replace the classifier with a new one, that has
# num_classes which is user-defined
num_classes = 1  # 1 class (person) + background
print(model)
model = model.to(device)
criterion = nn.CrossEntropyLoss()
# Observe that all parameters are being optimized
optimizer_ft = optim.SGD(model.parameters(), lr=0.001, momentum=0.9)
# Decay LR by a factor of 0.1 every 7 epochs
exp_lr_scheduler = lr_scheduler.StepLR(optimizer_ft, step_size=7, gamma=0.1)
model = train_model(model, criterion, optimizer_ft, exp_lr_scheduler,num_epochs=25)
PyTorch抛出这些错误。首先,这种方法正确吗

Epoch 0/24
----------
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-69-527ca4db8e5d> in <module>()
----> 1 model = train_model(model, criterion, optimizer_ft, exp_lr_scheduler,num_epochs=25)

2 frames
/usr/local/lib/python3.6/dist-packages/torchvision/models/detection/generalized_rcnn.py in forward(self, images, targets)
     43         """
     44         if self.training and targets is None:
---> 45             raise ValueError("In training mode, targets should be passed")
     46         original_image_sizes = [img.shape[-2:] for img in images]
     47         images, targets = self.transform(images, targets)

ValueError: In training mode, targets should be passed
0/24纪元
----------
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在()
---->1个模型=列车模型(模型、标准、优化器、exp\u lr\u调度器、num\u epochs=25)
2帧
/usr/local/lib/python3.6/dist-packages/torchvision/models/detection/generalized_rcnn.py in forward(自我、图像、目标)
43         """
44如果自我培训和目标为无:
--->45提升值错误(“在培训模式下,应通过目标”)
46原始图像大小=[img.shape[-2:]用于图像中的img]
47图像,目标=self.transform(图像,目标)
ValueError:在训练模式下,应通过目标
是否有办法修改此示例以进行自定义对象检测?
错误消息说明了一切。您需要传入一对
图像,target
来训练您的模型,其中
target
是一个包含边界框、标签和遮罩信息的字典

有关更多信息和全面教程,请参阅

Epoch 0/24
----------
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-69-527ca4db8e5d> in <module>()
----> 1 model = train_model(model, criterion, optimizer_ft, exp_lr_scheduler,num_epochs=25)

2 frames
/usr/local/lib/python3.6/dist-packages/torchvision/models/detection/generalized_rcnn.py in forward(self, images, targets)
     43         """
     44         if self.training and targets is None:
---> 45             raise ValueError("In training mode, targets should be passed")
     46         original_image_sizes = [img.shape[-2:] for img in images]
     47         images, targets = self.transform(images, targets)

ValueError: In training mode, targets should be passed