Mask R-CNN, Multi-Class



我遵循Mask R-CNN的经典气球示例。我训练了两个班的模型,车辆和瓶子。现在,该模型完美地检测到了这两个物体,但它对所有物体都表示车辆(class_id=1(,即所有瓶子都是车辆。我可能在配置代码时犯了一些错误。有人知道这个问题吗?

更改了config.py中的类数(1+nb类(在自定义数据集类中的load_中添加了这些类

但我想我还需要做一件事,就在这里:

for a in annotations:
# print(a)
# Get the x, y coordinates of points of the polygons that make up
# the outline of each object instance. There are stores in the
# shape_attributes (see json format above)
polygons = [r['shape_attributes'] for r in a['regions'].values()]
# load_mask() needs the image size to convert polygons to masks.
# Unfortunately, VIA doesn't include it in JSON, so we must read
# the image. This is only managable since the dataset is tiny.
image_path = os.path.join(dataset_dir, a['filename'])
image = skimage.io.imread(image_path)
height, width = image.shape[:2]
self.add_image(
"vehicle",  ## for a single class just add the name here
image_id=a['filename'],  # use file name as a unique image id
path=image_path,
width=width, height=height,
polygons=polygons)

我不知道这里该换什么。谢谢你抽出时间。

每次调用for loop中的函数self.add_image(....)时,都应该检查图像属于哪个类。如果它属于vehicle,则调用:

self.add_image("vehicle", ...)

如果它属于bottle,您应该调用:

self.add_image("bottle", ...)

此外,在config文件中,除了将NUM_CLASSES设置为1+nb_classes之外,您还必须为您的配置指定一个名称,例如"vehicle_and_bottle"。然后,在load函数中,您应该添加以下内容:

self.add_class("vehicle_and_bottle", 1, "bottle") # first class
self.add_class("vehicle_and_bottle", 2, "vehicle") # second class

最新更新