from detectron2.data.datasets import register_coco_instances
for d in ["train", "test"]:
register_coco_instances(f"dataset_{d}", {}, f"/content/{d}.json", f"/content/{d}")
class Trainer(DefaultTrainer):
@classmethod
def build_train_loader(cls, cfg):
mapper = DummyAlbuMapper(cfg, is_train=True)
return build_detection_train_loader(cfg, mapper=mapper)
trainer = Trainer(cfg)
trainer.train()
[06/29 23:04:24 d2.engine.train_loop]: Starting training from iteration 0
ERROR [06/29 23:04:25 d2.engine.train_loop]: Exception during training:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/detectron2/engine/train_loop.py", line 132, in train
self.run_step()
File "/usr/local/lib/python3.6/dist-packages/detectron2/engine/train_loop.py", line 215, in run_step
loss_dict = self.model(data)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/detectron2/modeling/meta_arch/rcnn.py", line 130, in forward
_, detector_losses = self.roi_heads(images, features, proposals, gt_instances)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/detectron2/modeling/roi_heads/roi_heads.py", line 669, in forward
losses.update(self._forward_mask(features, proposals))
File "/usr/local/lib/python3.6/dist-packages/detectron2/modeling/roi_heads/roi_heads.py", line 773, in _forward_mask
return self.mask_head(mask_features, proposals)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/detectron2/modeling/roi_heads/mask_head.py", line 182, in forward
return {"loss_mask": mask_rcnn_loss(x, instances, self.vis_period)}
File "/usr/local/lib/python3.6/dist-packages/detectron2/modeling/roi_heads/mask_head.py", line 55, in mask_rcnn_loss
gt_masks_per_image = instances_per_image.gt_masks.crop_and_resize(
File "/usr/local/lib/python3.6/dist-packages/detectron2/structures/instances.py", line 60, in __getattr__
raise AttributeError("Cannot find field '{}' in the given Instances!".format(name))
AttributeError: Cannot find field 'gt_masks' in the given Instances!
[06/29 23:04:25 d2.engine.hooks]: Total training time: 0:00:01 (0:00:00 on hooks)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-33-3435b262f1ae> in <module>()
----> 1 trainer.train()
11 frames
/usr/local/lib/python3.6/dist-packages/detectron2/structures/instances.py in __getattr__(self, name)
58 def __getattr__(self, name: str) -> Any:
59 if name == "_fields" or name not in self._fields:
---> 60 raise AttributeError("Cannot find field '{}' in the given Instances!".format(name))
61 return self._fields[name]
62
AttributeError: Cannot find field 'gt_masks' in the given Instances!