python - 使用 Pytorch Mask RCNN 时的零除错误
问题描述
我在包含多个视频的数据集上使用预训练的 torchvision MaskRCNN 模型,将视频逐帧传递给模型。然而,在 MaskRCNN 模型的前向传递中,我得到以下错误语句:
RuntimeError Traceback (most recent call last)
----> 1 output = model(images,targets)
4 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
548 result = self._slow_forward(*input, **kwargs)
549 else:
--> 550 result = self.forward(*input, **kwargs)
551 for hook in self._forward_hooks.values():
552 hook_result = hook(self, input, result)
/usr/local/lib/python3.6/dist-packages/torchvision/models/detection/generalized_rcnn.py in forward(self, images, targets)
64 original_image_sizes.append((val[0], val[1]))
65
---> 66 images, targets = self.transform(images, targets)
67 features = self.backbone(images.tensors)
68 if isinstance(features, torch.Tensor):
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
548 result = self._slow_forward(*input, **kwargs)
549 else:
--> 550 result = self.forward(*input, **kwargs)
551 for hook in self._forward_hooks.values():
552 hook_result = hook(self, input, result)
/usr/local/lib/python3.6/dist-packages/torchvision/models/detection/transform.py in forward(self, images, targets)
42 raise ValueError("images is expected to be a list of 3d tensors "
43 "of shape [C, H, W], got {}".format(image.shape))
---> 44 image = self.normalize(image)
45 image, target_index = self.resize(image, target_index)
46 images[i] = image
/usr/local/lib/python3.6/dist-packages/torchvision/models/detection/transform.py in normalize(self, image)
62 mean = torch.as_tensor(self.image_mean, dtype=dtype, device=device)
63 std = torch.as_tensor(self.image_std, dtype=dtype, device=device)
---> 64 return (image - mean[:, None, None]) / std[:, None, None]
65
66 def torch_choice(self, l):
RuntimeError: ZeroDivisionError
我images
在这段代码中是一个大小为 431 的列表,表示视频中的帧数,列表中的每个项目都是形状为 3 x 256 x 320 的火炬张量,分别表示通道 x 高度 x 宽度。Targets
这里包含列表字典形式的标签、掩码和边界框坐标。列表的长度targets
也是 431,每个项目都包含有关每个单独帧的信息。
我使用的代码与本教程中的代码相似,除了该教程处理静态图像,而且我正在处理视频,因此我只对该代码进行了一些小的更改。
解决方案
推荐阅读
- jquery - 从 DOM 中删除重复元素
- sql - 创建一个函数来计算订单 SQL Server 的成本
- c# - 如何在 Visual Studio Code 的 C# 函数声明括号中设置自动前导/尾随空格?
- gradle - 在 gradle 中添加本地文件依赖和存储库之间的区别
- javascript - 我可以从 jquery 文档中获取对象吗
- angular - 如何在 angular.json 中导入外部脚本 src?
- android - 无法从资产“index.android.bundle”加载脚本,请确保您的捆绑包已打包
- sql - 动态生成视图名称的拖放视图语法
- php - 在 codeigniter 中使用 $this 时不在对象上下文中
- java - 比较 url 字符串的路径。忽略域名