WongKinYiu / yolov7

Implementation of paper - YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors
GNU General Public License v3.0
13.33k stars 4.2k forks source link

test.py not working for large dataset #507

Closed WennPaper closed 2 years ago

WennPaper commented 2 years ago

I tried to run test.py in Colab and got the following error:

Namespace(augment=False, batch_size=32, conf_thres=0.001, data='apple100/data.yaml', device='0', exist_ok=False, img_size=640, iou_thres=0.5, name='yolov7_640_val', no_trace=False, project='runs/test', save_conf=False, save_hybrid=False, save_json=False, save_txt=False, single_cls=False, task='val', verbose=False, weights=['yolov7.pt'])
YOLOR 🚀 v0.1-104-g941b94c torch 1.12.1+cu113 CUDA:0 (Tesla P100-PCIE-16GB, 16280.875MB)

Fusing layers... 
RepConv.fuse_repvgg_block
RepConv.fuse_repvgg_block
RepConv.fuse_repvgg_block
Model Summary: 306 layers, 36905341 parameters, 36905341 gradients
 Convert model to Traced-model... 
/usr/local/lib/python3.7/dist-packages/torch/_tensor.py:1083: UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won't be populated during autograd.backward(). If you indeed want the .grad field to be populated for a non-leaf Tensor, use .retain_grad() on the non-leaf Tensor. If you access the non-leaf Tensor by mistake, make sure you access the leaf Tensor instead. See github.com/pytorch/pytorch/pull/30531 for more informations. (Triggered internally at  aten/src/ATen/core/TensorBody.h:477.)
  return self._grad
 traced_script_module saved! 
 model is traced! 

/usr/local/lib/python3.7/dist-packages/torch/functional.py:478: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  ../aten/src/ATen/native/TensorShape.cpp:2894.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
val: Scanning 'apple100/Validation.cache' images and labels... 360 found, 0 missing, 0 empty, 0 corrupted: 100% 360/360 [00:00<?, ?it/s]
               Class      Images      Labels           P           R      mAP@.5  mAP@.5:.95:   0% 0/12 [00:02<?, ?it/s]
Traceback (most recent call last):
  File "test.py", line 327, in <module>
    trace=not opt.no_trace,
  File "test.py", line 184, in test
    confusion_matrix.process_batch(predn, torch.cat((labels[:, 0:1], tbox), 1))
  File "/content/gdrive/MyDrive/yolov7/utils/metrics.py", line 148, in process_batch
    self.matrix[gc, detection_classes[m1[j]]] += 1  # correct
IndexError: index 47 is out of bounds for axis 1 with size 5

Any help is greatly appreciated!

WennPaper commented 2 years ago

When the validation dataset only contains a few images there would be no error. I have double checked the image labels and they are all fine.

FrancescoMandru commented 2 years ago

@WenTheProgrammer I got the same error at some point