问题描述
我希望只使用一个类,person(以及 BG,背景),用于 Mask RCNN 对象检测.我正在使用此链接:https://github.com/matterport/Mask_RCNN 来运行掩码 rcnn.有没有一种特定的方法来完成这个(编辑特定文件,创建一个额外的 python 文件,或者只是通过从 class_names 数组中过滤选择)?任何方向或解决方案将不胜感激.谢谢
I am looking to use only one class, person (along with BG, background), for the Mask RCNN object detection. I am using this link: https://github.com/matterport/Mask_RCNN to run the mask rcnn. Is there a specific way to complete this (editing specific files, creating an extra python file, or just by filtering selections from the class_names array)? Any direction or solution will be highly appreciated. Thank you
推荐答案
我已经为羊训练了相同的 repo.你必须做两件事:
I've trained the same repo for sheeps. You have to do 2 things:
将训练和推理类编号更改为 1 + 1( bg 和 person ):
Change the train and inference class numbers as 1 + 1 ( bg and person ):
class SheepsConfig(Config):
NAME = "sheeps"
NUM_CLASSES = 1 + 1 # background + sheep
config = SheepsConfig() # Don't forget to use this config while creating your model
config.display()
您需要创建数据集进行训练.您可以按如下方式使用 coco:
You need to create dataset to train on. You can use coco as follows:
import coco
from pycocotools.coco import COCO
ct = COCO("/YourPathToCocoDataset/annotations/instances_train2014.json")
ct.getCatIds(['sheep'])
# Sheep class' id is 20. You should run for person and use that id
COCO_DIR = "/YourPathToCocoDataset/"
# This path has train2014, annotations and val2014 files in it
# Training dataset
dataset_train = coco.CocoDataset()
dataset_train.load_coco(COCO_DIR, "train", class_ids=[20])
dataset_train.prepare()
# Validation dataset
dataset_val = coco.CocoDataset()
dataset_val.load_coco(COCO_DIR, "val", class_ids=[20])
dataset_val.prepare()
然后简单地将您的模型创建为:
And then simply create your model as:
# Create model in training mode
model = modellib.MaskRCNN(mode="training", config=config, model_dir=MODEL_DIR)
model.load_weights(COCO_MODEL_PATH, by_name=True, exclude=["mrcnn_class_logits", "mrcnn_bbox_fc", "mrcnn_bbox", "mrcnn_mask"])
# This COCO_MODEL_PATH is the path to the mask_rcnn_coco.h5 file in this repo
然后你可以用这个代码训练它:
Then you can train it with this code:
model.train(dataset_train, dataset_val,
learning_rate=config.LEARNING_RATE,
epochs=100,
layers='heads')#You can also use 'all' to train all network.
不要忘记使用 tensorflow 1.x 和 keras 2.1.0 :) 我可以使用这些版本进行训练.
Don't forget to use tensorflow 1.x and keras 2.1.0 :) I can train with these versions.
这篇关于仅掩码 RCNN 1 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!