WongKinYiu / yolov9

Implementation of paper - YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information
GNU General Public License v3.0
8.97k stars 1.42k forks source link

AttributeError: 'list' object has no attribute 'view' #413

Open Teameviral opened 6 months ago

Teameviral commented 6 months ago

Traceback (most recent call last): File "/content/yolov9/train.py", line 634, in main(opt) File "/content/yolov9/train.py", line 528, in main train(opt.hyp, opt, device, callbacks) File "/content/yolov9/train.py", line 304, in train loss, loss_items = compute_loss(pred, targets.to(device)) # loss scaled by batch_size File "/content/yolov9/utils/loss_tal.py", line 168, in call pred_distri, pred_scores = torch.cat([xi.view(feats[0].shape[0], self.no, -1) for xi in feats], 2).split( File "/content/yolov9/utils/loss_tal.py", line 168, in pred_distri, pred_scores = torch.cat([xi.view(feats[0].shape[0], self.no, -1) for xi in feats], 2).split( AttributeError: 'list' object has no attribute 'view'

Mecanight commented 6 months ago

I had a similar problem But in my case it was:

Traceback (most recent call last):
  File "yolov9/segment/train.py", line 646, in <module>
    main(opt)
  File "yolov9/segment/train.py", line 542, in main
    train(opt.hyp, opt, device, callbacks)
  File "yolov9/segment/train.py", line 297, in train
    loss, loss_items = compute_loss(pred, targets.to(device), masks=masks.to(device).float())
  File "yolov9/utils/segment/loss_tal.py", line 173, in __call__
    batch_size, _, mask_h, mask_w = proto.shape
AttributeError: 'list' object has no attribute 'shape'

To fix this, I started using the models/segment/gelan-c-seg.yaml file instead of models/segment/yolov9-c-dseg.yaml

I don't think this is the solution for your case But, I hope this helps

KoniHD commented 6 months ago

Doing the work of @Youho99 here :) Your issue looks the same as #315 or #302. Probably you used a Yolov9 model with train.py. However, you need to use train_dual.py with a yolov9 model as train.py is only for Gelan models. Meaning you can either use a Gelan model with train.py as @Mecanight mentioned or use train_dual.py with the yolov9 model. (See #1)

Techydeveloper12 commented 2 months ago

Traceback (most recent call last): File "/content/yolov9/train.py", line 634, in main(opt) File "/content/yolov9/train.py", line 528, in main train(opt.hyp, opt, device, callbacks) File "/content/yolov9/train.py", line 277, in train for i, (imgs, targets, paths, _) in pbar: # batch ------------------------------------------------------------- File "/usr/local/lib/python3.10/dist-packages/tqdm/std.py", line 1181, in iter for obj in iterable: File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py", line 631, in next data = self._next_data() File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py", line 1346, in _next_data return self._process_data(data) File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py", line 1372, in _process_data data.reraise() File "/usr/local/lib/python3.10/dist-packages/torch/_utils.py", line 705, in reraise raise exception IndexError: Caught IndexError in DataLoader worker process 0. Original Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop data = fetcher.fetch(index) # type: ignore[possibly-undefined] File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 51, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/content/yolov9/utils/dataloaders.py", line 656, in getitem img, labels = self.load_mosaic(index) File "/content/yolov9/utils/dataloaders.py", line 791, in load_mosaic img4, labels4, segments4 = copy_paste(img4, labels4, segments4, p=self.hyp['copy_paste']) File "/content/yolov9/utils/augmentations.py", line 248, in copy_paste l, box, s = labels[j], boxes[j], segments[j] IndexError: list index out of range