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.15k stars 4.16k forks source link

Program "detect.py" won't produce visual output using a GPU without tensor cores [solved] #646

Closed evan-kolberg closed 1 year ago

evan-kolberg commented 1 year ago

Main issue ↓

The program is running without producing any visual representation (output) of what is happening. The input image is the same as the output and even after specifying to save txt and conf, nothing is stored in the labels directory.

Attempt 1 ↓

Command used: python detect.py --source city-people.jpg

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\Users\ekpro\VS Code Projects\CAPTCHA-slayer\yolov7> & c:/Users/ekpro/venvs✨/yolov7/Scripts/Activate.ps1
(yolov7) PS C:\Users\ekpro\VS Code Projects\CAPTCHA-slayer\yolov7> python detect.py --source city-people.jpg
Namespace(weights='yolov7.pt', source='city-people.jpg', img_size=640, conf_thres=0.25, iou_thres=0.45, device='', view_img=False, save_txt=False, save_conf=False, nosave=False, classes=None, agnostic_nms=False, augment=False, update=False, project='runs/detect', name='exp', exist_ok=False, no_trace=False)
YOLOR  2022-8-27 torch 1.12.1+cu116 CUDA:0 (NVIDIA GeForce GTX 1660 Ti, 6143.6875MB)

Fusing layers...
RepConv.fuse_repvgg_block
RepConv.fuse_repvgg_block
RepConv.fuse_repvgg_block
Model Summary: 306 layers, 36905341 parameters, 6652669 gradients
 Convert model to Traced-model...
 traced_script_module saved! 
 model is traced! 

C:\Users\ekpro\venvs✨\yolov7\lib\site-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:2895.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
Done. (89.0ms) Inference, (0.0ms) NMS
 The image with the result is saved in: runs\detect\exp\city-people.jpg
Done. (0.395s)

Input image ↓ city-people

Output image in runs\detect\exp ↓ city-people

As pictured above, no changes were saved onto the output image

Attempt 2 ↓

Command used: python detect.py --weights yolov7.pt --source city-people.jpg --view-img --save-txt --save-conf --conf-thres 0.10

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\Users\ekpro\VS Code Projects\CAPTCHA-slayer\yolov7> & c:/Users/ekpro/venvs✨/yolov7/Scripts/Activate.ps1
(yolov7) PS C:\Users\ekpro\VS Code Projects\CAPTCHA-slayer\yolov7> python detect.py --weights yolov7.pt --source city-people.jpg --view-img --save-txt --save-conf --conf-thres 0.10
Namespace(weights=['yolov7.pt'], source='city-people.jpg', img_size=640, conf_thres=0.1, iou_thres=0.45, device='', view_img=True, save_txt=True, save_conf=True, nosave=False, classes=None, agnostic_nms=False, augment=False, update=False, project='runs/detect', name='exp', exist_ok=False, no_trace=False)
YOLOR  2022-8-27 torch 1.12.1+cu116 CUDA:0 (NVIDIA GeForce GTX 1660 Ti, 6143.6875MB)

Fusing layers... 
RepConv.fuse_repvgg_block
RepConv.fuse_repvgg_block
RepConv.fuse_repvgg_block
Model Summary: 306 layers, 36905341 parameters, 6652669 gradients
 Convert model to Traced-model... 
 traced_script_module saved! 
 model is traced! 

C:\Users\ekpro\venvs✨\yolov7\lib\site-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:2895.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
Done. (88.0ms) Inference, (1.0ms) NMS
 The image with the result is saved in: runs\detect\exp2\city-people.jpg
Done. (0.416s)

image

Nothing was saved in labels and no changes were made to the city-people.jpg

Situation conditions ↓

Attempt 3 ↓

Command: python detect.py --weights yolov7.pt --conf 0.25 --img-size 640 --source inference/images/horses.jpg

Instead of running detect.py using my own image, I used the default image that came with the repo and still reproduced the same issue.

Output image ↓ image

vishnuvskvkl commented 1 year ago

I'm facing similar issue even if I downgrade the cuda version to 11.3. Even though it works fine when using the CPU version

evan-kolberg commented 1 year ago

city-people Command: python detect.py --source city-people.jpg --device cpu Same with me. I am able to get a visual by using the cpu, but it isn't exactly ideal since I have a perfectly fine CUDA gpu that can be used.

WongKinYiu commented 1 year ago

Please force set half to False if your GPU does not have tensor core.

evan-kolberg commented 1 year ago

image Setting the var half to False on line 31 worked! Thank you!