How I trained the model for seal detection and segmentation

Hello habr! Today I want to share my case. Detecting seals would automate many routine tasks, making human work easier. For my task, I use the Mask R-CNN model .





Mask R-CNN is a two-stage structure: in the first stage, an image is scanned and sentences  (areas that may contain an object) are generated  . In the second step, the proposals are classified and bounding boxes and masks are created.





What is segmentation?

Segmentation is the task of defining the contours of an object at the pixel level. Compared to similar tasks of computer vision, this is one of the most difficult tasks of vision.Please note the following questions:





Classification: There is a cat in this image.





Object Detection:  In this image, there are two cats, one dog and a duck in these locations. We're starting to consider overlapping objects.





Segmentation: There are 4 popups at these locations and these are the pixels that each one owns.





Preparing a dataset for training

, ( ), . . 2 .  .  - .





, , 2 ? , . . , , COCO ( Mask R-CNN ).  COCO   , (~ 120 ), , , .





 VIA (VGG Image Annotator). HTML-, .  , , 20 .





.  PNG, - .  , , .





VIA JSON, .  , , JSON.  , , .





: -  coco.py  .  .  seal.py





SealDataset



:





class SealDataset(utils.Dataset):
    def load_balloons(self, dataset_dir, subset):
        ...
    def load_mask(self, image_id):
        ...
    def image_reference(self, image_id):
        ...
      
      



load_balloons



JSON,  add_class



 add_image



.





load_mask



  .





image_reference



, .  .





, .   load_image



 Dataset



.  .





, ,   Jupyter .  , , , , .  , :





: ,   inspect_data.ipynb , COCO, , Seal.





, COCO, 3 .   Dataset



,  Config



:





class BalloonConfig(Config):
    # Give the configuration a recognizable name
    NAME = "seal"
    # Number of classes (including background)
    NUM_CLASSES = 1 + 1  # Background + seal
    # Number of training steps per epoch
    STEPS_PER_EPOCH = 100
      
      



1024x1024 .  .  , .





R-CNN - . . Quadro M2000 c 4 . 3-4 .





,  seal



.  , COCO.  :





python seal.py train --dataset=/// --model=coco
      
      



, :





python seal.py train --dataset=/// --model=last
      
      



   inspect_seal_model  , .  , .





You can download the pretrained scales for detection and segmentation here . To use, add the project to the samples folder in Mask R-CNN. If there is a need for a dataset, write to me in the mail: galym55010@gmail.com








All Articles