I attempted to train a mask-rcnn model with a custom dataset. I ran the following code.
import os
from detectron2.data.datasets import register_coco_instances
from detectron2.data import DatasetCatalog, MetadataCatalog
from detectron2 import model_zoo
from detectron2.config import get_cfg
from detectron2.engine import DefaultTrainer
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
register_coco_instances("train", {}, "./data/annotations/train.json", "./data/train")
register_coco_instances("test", {}, "./data/annotations/test.json", "./data/test")
train_metadata = MetadataCatalog.get("train")
print(train_metadata)
cfg.DATASETS.TRAIN = ("train",)
cfg.DATASETS.TRAIN = ("test",)
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
cfg.MODEL.WEIGHTS = "detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl"
cfg.SOLVER.IMS_PER_BATCH = 1
cfg.DATALOADER.NUM_WORKERS = 1
cfg.SOLVER.BASE_LR = 0.02
cfg.SOLVER.MAX_ITER = (300)
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = (128) # faster, and good enough for this toy dataset
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 3 # 3 classes (data, fig, hazelnut)
os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
trainer = DefaultTrainer(cfg)
trainer.resume_or_load(resume=False)
trainer.train()
To annotate my data I used Justin Brook's COCO annotator (https://github.com/jsbroks/coco-annotator).
I annotated 4 pictures with 3 classes (lane left, lane right, obstacle).
Instructions To Reproduce the Issue:
I attempted to train a mask-rcnn model with a custom dataset. I ran the following code.
To annotate my data I used Justin Brook's COCO annotator (https://github.com/jsbroks/coco-annotator). I annotated 4 pictures with 3 classes (lane left, lane right, obstacle).
Output
Expected behavior:
Start the training
Environment:
After cloning the detectron2-repo locally: pip install e . pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 pip install opencv-python