facebookresearch / unbiased-teacher

PyTorch code for ICLR 2021 paper Unbiased Teacher for Semi-Supervised Object Detection
https://arxiv.org/abs/2102.09480
MIT License
409 stars 84 forks source link

gt_instances is NoneType object #52

Open nawazia opened 2 years ago

nawazia commented 2 years ago

Hi!

I'm trying to get UBTeacher to work on a custom COCO dataset, but am having issues getting the training to begin. I've added the changes described in #8, as well as a few others (changing directory names, num_classes, etc.) but am still getting a TypeError:

[09/22 12:47:58 d2.engine.hooks]: Total training time: 0:00:01 (0:00:00 on hooks)
[09/22 12:47:58 d2.utils.events]:  iter: 0    lr: N/A  max_mem: 6617M
Traceback (most recent call last):
  File "train_net.py", line 78, in <module>
    args=(args,),
  File "/usr/local/lib/python3.7/dist-packages/detectron2/engine/launch.py", line 82, in launch
    main_func(*args)
  File "train_net.py", line 65, in main
    return trainer.train()
  File "/content/drive/My Drive/unbiased-teacher/ubteacher/engine/trainer.py", line 375, in train
    self.train_loop(self.start_iter, self.max_iter)
  File "/content/drive/My Drive/unbiased-teacher/ubteacher/engine/trainer.py", line 393, in train_loop
    self.run_step_full_semisup()
  File "/content/drive/My Drive/unbiased-teacher/ubteacher/engine/trainer.py", line 492, in run_step_full_semisup
    label_data_q, branch="supervised")
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/content/drive/My Drive/unbiased-teacher/ubteacher/modeling/meta_arch/rcnn.py", line 26, in forward
    images, features, gt_instances
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/content/drive/My Drive/unbiased-teacher/ubteacher/modeling/proposal_generator/rpn.py", line 44, in forward
    gt_labels, gt_boxes = self.label_and_sample_anchors(anchors, gt_instances)
  File "/usr/local/lib/python3.7/dist-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/detectron2/modeling/proposal_generator/rpn.py", line 327, in label_and_sample_anchors
    gt_boxes = [x.gt_boxes for x in gt_instances]
TypeError: 'NoneType' object is not iterable
nawazia commented 2 years ago

As far as I understand this error gets thrown because batched_inputs is not defined, and so = None. However, I still can't see where it should get defined. It first gets mentioned in the forward func. of the GeneralizedRCNN class def:

Args:
            batched_inputs: a list, batched outputs of :class:`DatasetMapper` .
                Each item in the list contains the inputs for one image.
                For now, each item in the list is a dict that contains:
                * image: Tensor, image in (C, H, W) format.
                * instances (optional): groundtruth :class:`Instances`
                * proposals (optional): :class:`Instances`, precomputed proposals.
                Other information that's included in the original dicts, such as:
                * "height", "width" (int): the output resolution of the model, used in inference.
                  See :meth:`postprocess` for details.
Lichengwei47 commented 9 months ago

I have the same problem as you, have you solved it?