matterport / Mask_RCNN

Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
Other
24.69k stars 11.7k forks source link

How to add custom classes while preserving the classes in original COCO after re-training? #828

Open ztcuthbertlo opened 6 years ago

ztcuthbertlo commented 6 years ago

I would like to add custom classes (like the sample adding Ballon) while retain the original 80 classes COCO already has. For example, after re-training with Ballon dataset with pre-trained COCO model, how can I do object detection on classes like Balloon, Person, Cat, Car?

LackesLab commented 6 years ago

You can just adapt your custom config class and write NUM_CLASSES = (in your case I think 82). But you need to pay attention, that your dataset has samples for all classes, this means the coco and the balloon classes) After that, you can train the heads.

class CustomConfig(Config):
"""Configuration for training on MS COCO.
    Derives from the base Config class and overrides values specific
    to the COCO dataset.
    """
    # Give the configuration a recognizable name
    NAME = "custom"

    # Number of classes (including background)
    NUM_CLASSES =1 + 80 +1  # Background + Coco + Balloon
ztcuthbertlo commented 6 years ago

Thank you for the reply.

Does the size of the samples of all classes matter? The Coco original dataset has tenths of thousand images for each class, is it necessary to have the same size or only a small portion, like 100 images each class, will be good enough?

LackesLab commented 6 years ago

For only training the heads, 100 to 1000 samples for each class clould be enough. Just try it out.

parul19 commented 5 years ago

Do we need to get the whole coco dataset (images of all the 80 class)+ images of balloon/new class and then start to train ...or can we use the pretrained weight+ images of balloon/new class and then train.Is this method will work? Please let me know how to use transfer learning in this..

nyck33 commented 5 years ago

@parul19 I think once the final layer is modified, you can use the pretrained weights from all other layers and train the modified layers. This explains it well except the repo link is broken: transfer learning

alechagonzalo commented 5 years ago

@parul19 how did you do it? I want to add a new class without losing the 80 COCO classes, but I don't know how to do it. Thank you.

Syirrus commented 4 years ago

I've been wondering how to do the same thing. I would like to add a few classes to the existing COCO class. I'm using just basic object detection, no Mask_RCNN. How do you do that?

ManjuAlchemy commented 4 years ago

need help steps or any documents to achive these,

1.How can I retrain the existing ssd_inception_v2_coco_2018_01_28 model with addition class. my question is 'How to add custom classes while preserving the classes in original'. and otherone question is, 2.How can I train a new model only with my own dataset which has only two classes.

skabbit commented 4 years ago

@ManjuAlchemy I know the answer for second question is described by authors in the article: https://engineering.matterport.com/splash-of-color-instance-segmentation-with-mask-r-cnn-and-tensorflow-7c761e238b46 This quite comprehensive guide to train a model (from scratch or transfer learn the trained) to mask your own classes.