yjh0410 / RT-ODLab

YOLO Tutorial
MIT License
156 stars 32 forks source link

AttributeError in yolov5_augment.py #5

Open huihui308 opened 1 year ago

huihui308 commented 1 year ago

I had a AttributeError when I trained rtcdet_p on my own dataset.

Traceback (most recent call last):
  File "train.py", line 189, in <module>
    train()
  File "train.py", line 180, in train
    trainer.train(model)
  File "/home/david/code/paper/PyTorch_YOLO_Tutorial/engine.py", line 857, in train
    self.train_one_epoch(model)
  File "/home/david/code/paper/PyTorch_YOLO_Tutorial/engine.py", line 937, in train_one_epoch
    for iter_i, (images, targets) in enumerate(self.train_loader):
  File "/home/david/.local/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 633, in __next__
    data = self._next_data()
  File "/home/david/.local/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1345, in _next_data
    return self._process_data(data)
  File "/home/david/.local/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1371, in _process_data
    data.reraise()
  File "/home/david/.local/lib/python3.8/site-packages/torch/_utils.py", line 644, in reraise
    raise exception
AttributeError: Caught AttributeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/home/david/.local/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/david/.local/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/david/.local/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 51, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/david/code/paper/PyTorch_YOLO_Tutorial/dataset/plate.py", line 86, in __getitem__
    return self.pull_item(index)
  File "/home/david/code/paper/PyTorch_YOLO_Tutorial/dataset/plate.py", line 187, in pull_item
    image, target = self.load_mosaic(index)
  File "/home/david/code/paper/PyTorch_YOLO_Tutorial/dataset/plate.py", line 160, in load_mosaic
    image, target = yolov5_mosaic_augment(
  File "/home/david/code/paper/PyTorch_YOLO_Tutorial/dataset/data_augment/yolov5_augment.py", line 143, in yolov5_mosaic_augment
    bboxes_i_ = bboxes_i.copy()
AttributeError: 'Tensor' object has no attribute 'copy'

bboxes_i's type sometime is tensor, not <class 'numpy.ndarray'>. So, I add a code in order to judge bboxes_i's type, as following.

        # labels
        if torch.is_tensor(bboxes_i):
            bboxes_i = bboxes_i.numpy()
        bboxes_i_ = bboxes_i.copy()