我正在尝试在基于Pascal VOC格式的另一个数据集上运行faster_rcnn。但训练结果如下所示:
在出现以下警告后,所有损失值都变成了nan:
proposal_layer_tf.py:150: RuntimeWarning: 在greater_equal中遇到了无效值 keep =np.where((ws >= min_size) & (hs >= min_size))[0]
这是proposal_layer_tf.py的第146-151行:
def _filter_boxes(boxes, min_size): """移除所有边长小于min_size的盒子。""" ws = boxes[:, 2] - boxes[:, 0] + 1 hs = boxes[:, 3] - boxes[:, 1] + 1 keep = np.where((ws >= min_size) & (hs >= min_size))[0]return keep
如你所见,总损失值以一种奇怪的方式变化,并且在警告后变成了nan。我该怎么做才能解决这个问题呢?
(gpu: Geforce 940m)
回答:
这个问题很可能是由你的注释引起的。在Faster-RCNN的实现中,当他们将边界框加载到数据框时,会将坐标x1,y1,x2,y2
减去1
以使其为0基。在我的情况下,我创建了自己的xml注释,它们已经是0基的。因此,如果我运行默认的Faster-RCNN实现,从0
中减去1
会导致下溢错误。所以移除那个减法解决了我的问题。
你可以在pascal_voc.py
中移除减法,或者编辑你的注释使它们变为1基。如果你选择编辑pascal_voc.py
文件,请查看这里:
def _load_pascal_annotation(self, index): # ... # ... # ... # 将对象边界框加载到数据框中。 for ix, obj in enumerate(objs): bbox = obj.find('bndbox') # 使像素索引为0基 x1 = float(bbox.find('xmin').text) #- 1 <- 注释掉这些行 y1 = float(bbox.find('ymin').text) #- 1 x2 = float(bbox.find('xmax').text) #- 1 y2 = float(bbox.find('ymax').text) #- 1 # ... # ... # ...