I’m trying Yolo v7, it seems to be working, but the resulted image has no object detection mapping on it, while it should have.
I read the Github to how to setup Yolo v7 on Docker, here’s the full commands you should be able to reproduce my problem.
git clone https://github.com/WongKinYiu/yolov7
cd yolov7
nvidia-docker run --name yolov7 -it --rm -v "$CWD":/yolov7 --shm-size=64g nvcr.io/nvidia/pytorch:21.08-py3
// on the container
cd /yolov7
python -m pip install virtualenv
python -m virtualenv venv3
. venv3/bin/activate
pip install -r requirements.txt
apt update
apt install -y zip htop screen libgl1-mesa-glx
pip install seaborn thop
python detect.py --weights yolov7.pt --conf 0.25 --img-size 640 --source inference/images/horses.jpg
And this is the console output of the last command:
# python detect.py --weights yolov7.pt --conf 0.25 --img-size 640 --source inference/images/horses.jpg
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', exist_ok=False, img_size=640, iou_thres=0.45, name='exp', no_trace=False, nosave=False, project='runs/detect', save_conf=False, save_txt=False, source='inference/images/horses.jpg', update=False, view_img=False, weights=['yolov7.pt'])
YOLOR 🚀 v0.1-115-g072f76c torch 1.13.0+cu117 CUDA:0 (NVIDIA GeForce GTX 1650, 3903.875MB)
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!
/yolov7/venv3/lib/python3.8/site-packages/torch/functional.py:504: 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:3190.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
Done. (150.9ms) Inference, (0.3ms) NMS
The image with the result is saved in: runs/detect/exp6/horses.jpg
Done. (0.616s)
Now, I should be able to see the detections on the generated image runs/detect/exp6/horses.jpg
, from the original image inference/images/horses.jpg
, right? But I see the two images the same, no difference. What’s wrong with the setup?
Nvidia driver:
$ nvidia-smi
Tue Dec 6 09:47:03 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.60.11 Driver Version: 525.60.11 CUDA Version: 12.0 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... On | 00000000:01:00.0 Off | N/A |
| 45% 27C P8 N/A / 75W | 13MiB / 4096MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 1152 G /usr/lib/xorg/Xorg 9MiB |
| 0 N/A N/A 1256 G /usr/bin/gnome-shell 2MiB |
+-----------------------------------------------------------------------------+
Ubuntu version:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal
3
Answers
modify variable half on detect.py file to False
Line 31 : half = False
When we are using the Gpu . The program allows only to use half precision of the Model . This is what is written in Line 31 of detect.py(# half precision only supported on CUDA).
By changing it to False :
Line 31 : half = False
Does the magic for me .
I came across the same issue too. It is basically what others mentioned. Some explanation is added below.
The reason is in line 31
half = device.type != 'cpu' # half precision only supported on CUDA
.Not all GPUs nor all Nvidia GPUs with CUDA support half-precision (16 bit) floats, esp if your GPU is a bit older. In my case, I was using an AMD 5700XT (via ROCM) – this GPU also has no fp16 support!
To make it configurable, I added a command line argument which let the user to override the variable
half
mentioned in other answers;