notebooks
notebooks copied to clipboard
Detectron2 Cannot find field 'gt_masks' in the given Instances!
Search before asking
- [X] I have searched the Roboflow Notebooks issues and found no similar bug report.
Notebook name
Train Detectron2 Segmentation on Custom Data
Bug
I have created a COCO json data using Roboflow and using that dataset in colab. In my roboflow, it clearly states that y dataset has exactly 2 classes.
But when run the below Detectron2 code to train m object detection model,
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.DATASETS.TRAIN = ("my_dataset_train",)
cfg.DATASETS.TEST = ()
cfg.DATALOADER.NUM_WORKERS = 2
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml") # Let training initialize from model zoo
cfg.SOLVER.IMS_PER_BATCH = 2 # This is the real "batch size" commonly known to deep learning people
cfg.SOLVER.BASE_LR = 0.00025 # pick a good LR
cfg.SOLVER.MAX_ITER = 300
cfg.SOLVER.STEPS = [] # do not decay learning rate
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 128 # The "RoIHead batch size"
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 2 # has two classes(crop & weed).
os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
trainer = DefaultTrainer(cfg)
trainer.resume_or_load(resume=False)
trainer.train()
While running the code, it shows my dataset has 3 categories which is wrong.
This eventually leads the training code to get the below error;
AttributeError: Cannot find field 'gt_masks' in the given Instances!
Please, I need help as I have been stuck on this for the past 48 hours.
Environment
- Google Colab
Minimal Reproducible Example
No response
Additional
No response
Are you willing to submit a PR?
- [ ] Yes I'd like to help by submitting a PR!