本文简要介绍python语言中 torchvision.models.detection.fasterrcnn_resnet50_fpn 的用法。
- 用法:- torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=False, progress=True, num_classes=91, pretrained_backbone=True, trainable_backbone_layers=None, **kwargs)
- 使用 ResNet-50-FPN 主干构建 Faster R-CNN 模型。 - 参考:“更快的R-CNN:通过区域提议网络实现实时目标检测”. - 模型的输入应该是一个张量列表,每个形状为 - [C, H, W],每个图像一个,并且应该在- 0-1范围内。不同的图像可以有不同的尺寸。- 模型的行为取决于它是处于训练模式还是评估模式。 - 在训练期间,模型需要输入张量以及目标(字典列表),其中包含: - 框 ( - FloatTensor[N, 4]):- [x1, y1, x2, y2]格式的 ground-truth 框,包含- 0 <= x1 < x2 <= W和- 0 <= y1 < y2 <= H。
- labels ( - Int64Tensor[N]):每个ground-truth框的类标签
 - 该模型在训练期间返回 - Dict[Tensor],其中包含 RPN 和 R-CNN 的分类和回归损失。- 在推理过程中,模型只需要输入张量,并将后处理的预测作为 - List[Dict[Tensor]]返回,每个输入图像一个。- Dict的字段如下,其中- N为检测次数:- 框 ( - FloatTensor[N, 4]):- [x1, y1, x2, y2]格式的预测框,包含- 0 <= x1 < x2 <= W和- 0 <= y1 < y2 <= H。
- labels ( - Int64Tensor[N]):每次检测的预测标签
- 分数( - Tensor[N]):每次检测的分数
 - 有关输出的更多详细信息,您可以参考实例分割模型。 - Faster R-CNN 可导出到 ONNX 以用于固定批量大小,输入图像大小固定。 - 例子: - >>> model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True) >>> # For training >>> images, boxes = torch.rand(4, 3, 600, 1200), torch.rand(4, 11, 4) >>> labels = torch.randint(1, 91, (4, 11)) >>> images = list(image for image in images) >>> targets = [] >>> for i in range(len(images)): >>> d = {} >>> d['boxes'] = boxes[i] >>> d['labels'] = labels[i] >>> targets.append(d) >>> output = model(images, targets) >>> # For inference >>> model.eval() >>> x = [torch.rand(3, 300, 400), torch.rand(3, 500, 400)] >>> predictions = model(x) >>> >>> # optionally, if you want to export the model to ONNX: >>> torch.onnx.export(model, x, "faster_rcnn.onnx", opset_version = 11)- 使用 - fasterrcnn_resnet50_fpn的示例:
参数:
相关用法
- Python PyTorch fasterrcnn_mobilenet_v3_large_320_fpn用法及代码示例
- Python PyTorch fasterrcnn_mobilenet_v3_large_fpn用法及代码示例
- Python PyTorch fake_quantize_per_channel_affine用法及代码示例
- Python PyTorch fake_quantize_per_tensor_affine用法及代码示例
- Python PyTorch frexp用法及代码示例
- Python PyTorch fft2用法及代码示例
- Python PyTorch fftn用法及代码示例
- Python PyTorch flip用法及代码示例
- Python PyTorch frombuffer用法及代码示例
- Python PyTorch float_power用法及代码示例
- Python PyTorch floor_divide用法及代码示例
- Python PyTorch fractional_max_pool3d用法及代码示例
- Python PyTorch frac用法及代码示例
- Python PyTorch freeze用法及代码示例
- Python PyTorch fp16_compress_hook用法及代码示例
- Python PyTorch fftshift用法及代码示例
- Python PyTorch flipud用法及代码示例
- Python PyTorch fliplr用法及代码示例
- Python PyTorch fp16_compress_wrapper用法及代码示例
- Python PyTorch fractional_max_pool2d用法及代码示例
- Python PyTorch fftfreq用法及代码示例
- Python PyTorch from_numpy用法及代码示例
- Python PyTorch filter_wikipedia_xml用法及代码示例
- Python PyTorch fuse_modules用法及代码示例
- Python PyTorch fmax用法及代码示例
注:本文由纯净天空筛选整理自pytorch.org大神的英文原创作品 torchvision.models.detection.fasterrcnn_resnet50_fpn。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。

 
