Tianxiaomo / pytorch-YOLOv4

PyTorch ,ONNX and TensorRT implementation of YOLOv4
Apache License 2.0
4.47k stars 1.49k forks source link

Type error in __get_items__ (AttributeError: 'list' object has no attribute 'shape') #457

Open stackSmasher294 opened 3 years ago

stackSmasher294 commented 3 years ago

Hi,

I am getting the following error after a few minutes of starting the training:

Epoch 1/300: 1%| | 180/31569 [02:11<6:21:00, 1. Traceback (most recent call last): File "train.py", line 625, in <module> train(model=model, File "train.py", line 371, in train for i, batch in enumerate(train_loader): File "/home/shubham/anaconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 517, in __next__ data = self._next_data() File "/home/shubham/anaconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1199, in _next_data return self._process_data(data) File "/home/shubham/anaconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1225, in _process_data data.reraise() File "/home/shubham/anaconda3/lib/python3.8/site-packages/torch/_utils.py", line 429, in reraise raise self.exc_type(msg) AttributeError: Caught AttributeError in DataLoader worker process 4. Original Traceback (most recent call last): File "/home/shubham/anaconda3/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 202, in _worker_loop data = fetcher.fetch(index) File "/home/shubham/anaconda3/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/shubham/anaconda3/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/shubham/opensource/pytorch-YOLOv4/dataset.py", line 396, in __getitem__ = out_bboxes[:min(out_bboxes.shape[0], self.cfg.boxes)] AttributeError: 'list' object has no attribute 'shape'

lixinghe1999 commented 3 years ago

Same problem

lixinghe1999 commented 3 years ago

Solved Reason: The problem comes from the fact that your image and label fail/ get filtered out by the image augmentation process. How: if out_bboxes == []: go to get_val_item which will skip all the image processing, in other words, you will have at leaset one box.