Commit 24c26637 authored by Carsten Eie Frigaard's avatar Carsten Eie Frigaard
Browse files

fix_of_versions_in_yolovdemo

parent 7fef5d00
%% Cell type:markdown id:e255e646-1ecd-4039-9d7a-08ade6fdd477 tags:
# SWMAL
## Setup of Yolov5 on GPU Cluster
Most packages are ready on the GPU Cluster when you are running under an Anaconda 2021.11.
We can finalize your setup both first cloning the Yolov5 git-repository
%% Cell type:code id:8c5a2629-c4a8-4860-b904-5e40e6bd3cf6 tags:
``` python
! (test ! -d yolov5 && git clone https://github.com/ultralytics/yolov5) || echo "Git-repository already cloned.."
```
%% Output
Cloning into 'yolov5'...
remote: Enumerating objects: 12390, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 12390 (delta 1), reused 7 (delta 1), pack-reused 12383
Receiving objects: 100% (12390/12390), 11.56 MiB | 6.82 MiB/s, done.
Resolving deltas: 100% (8620/8620), done.
%% Cell type:markdown id:8dc588fa-ba32-4dc4-8a75-5b5564a2f12a tags:
and then `pip` installing the missing packages (that are incompatible with a `conda` install).
First we install a specific set of packages for the `torch` framework that will work with even the newest GPUs (3090 RTX), and let this run for about 2 to 15 min (its slow to install):
%% Cell type:code id:55858395-7d66-49db-9623-7ab13c802897 tags:
``` python
! pip install torch==1.10.1+cu111 torchvision==0.11.2+cu111 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html
```
%% Output
Defaulting to user installation because normal site-packages is not writeable
Looking in links: https://download.pytorch.org/whl/torch_stable.html
Collecting torch==1.10.1+cu111
Using cached https://download.pytorch.org/whl/cu111/torch-1.10.1%2Bcu111-cp39-cp39-linux_x86_64.whl (2137.7 MB)
Collecting torchvision==0.11.2+cu111
Using cached https://download.pytorch.org/whl/cu111/torchvision-0.11.2%2Bcu111-cp39-cp39-linux_x86_64.whl (24.5 MB)
Collecting torchaudio==0.10.1
Using cached https://download.pytorch.org/whl/rocm4.1/torchaudio-0.10.1%2Brocm4.1-cp39-cp39-linux_x86_64.whl (2.7 MB)
Requirement already satisfied: typing-extensions in /opt/anaconda-2021.11/lib/python3.9/site-packages (from torch==1.10.1+cu111) (3.10.0.2)
Requirement already satisfied: pillow!=8.3.0,>=5.3.0 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from torchvision==0.11.2+cu111) (8.4.0)
Requirement already satisfied: numpy in /opt/anaconda-2021.11/lib/python3.9/site-packages (from torchvision==0.11.2+cu111) (1.20.3)
Installing collected packages: torch, torchvision, torchaudio
 WARNING: The scripts convert-caffe2-to-onnx, convert-onnx-to-caffe2 and torchrun are installed in '/home/cef/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed torch-1.10.1+cu111 torchaudio-0.10.1+rocm4.1 torchvision-0.11.2+cu111
%% Cell type:markdown id:80c819bd-5b68-4f3c-b8e2-9c981e122a50 tags:
The we `pip` install whatever packages, that Yolov5 still needs (since they are still incompatible with a `conda` install):
%% Cell type:code id:16e7eab7-c847-4ff4-bc8c-ca34bb42df1b tags:
``` python
! pip install -r yolov5_swmal_requirements.txt
```
%% Output
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: matplotlib>=3.2.2 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from -r yolov5_swmal_requirements.txt (line 4)) (3.4.3)
Requirement already satisfied: numpy>=1.18.5 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from -r yolov5_swmal_requirements.txt (line 5)) (1.20.3)
Collecting opencv-python>=4.1.2
Using cached opencv_python-4.5.5.64-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (60.5 MB)
Requirement already satisfied: Pillow>=7.1.2 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from -r yolov5_swmal_requirements.txt (line 7)) (8.4.0)
Requirement already satisfied: PyYAML>=5.3.1 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from -r yolov5_swmal_requirements.txt (line 8)) (6.0)
Requirement already satisfied: requests>=2.23.0 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from -r yolov5_swmal_requirements.txt (line 9)) (2.26.0)
Requirement already satisfied: scipy>=1.4.1 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from -r yolov5_swmal_requirements.txt (line 10)) (1.7.1)
Requirement already satisfied: torch>=1.7.0 in /home/cef/.local/lib/python3.9/site-packages (from -r yolov5_swmal_requirements.txt (line 11)) (1.10.1+cu111)
Requirement already satisfied: torchvision>=0.8.1 in /home/cef/.local/lib/python3.9/site-packages (from -r yolov5_swmal_requirements.txt (line 12)) (0.11.2+cu111)
Requirement already satisfied: torchaudio>=0.10.1 in /home/cef/.local/lib/python3.9/site-packages (from -r yolov5_swmal_requirements.txt (line 15)) (0.10.1+rocm4.1)
Requirement already satisfied: tqdm>=4.41.0 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from -r yolov5_swmal_requirements.txt (line 18)) (4.62.3)
Collecting tensorboard>=2.4.1
Using cached tensorboard-2.8.0-py3-none-any.whl (5.8 MB)
Collecting thop
Using cached thop-0.0.31.post2005241907-py3-none-any.whl (8.7 kB)
Requirement already satisfied: python-dateutil>=2.7 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from matplotlib>=3.2.2->-r yolov5_swmal_requirements.txt (line 4)) (2.8.2)
Requirement already satisfied: pyparsing>=2.2.1 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from matplotlib>=3.2.2->-r yolov5_swmal_requirements.txt (line 4)) (3.0.4)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from matplotlib>=3.2.2->-r yolov5_swmal_requirements.txt (line 4)) (1.3.1)
Requirement already satisfied: cycler>=0.10 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from matplotlib>=3.2.2->-r yolov5_swmal_requirements.txt (line 4)) (0.10.0)
Requirement already satisfied: idna<4,>=2.5 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from requests>=2.23.0->-r yolov5_swmal_requirements.txt (line 9)) (3.2)
Requirement already satisfied: charset-normalizer~=2.0.0 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from requests>=2.23.0->-r yolov5_swmal_requirements.txt (line 9)) (2.0.4)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from requests>=2.23.0->-r yolov5_swmal_requirements.txt (line 9)) (1.26.7)
Requirement already satisfied: certifi>=2017.4.17 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from requests>=2.23.0->-r yolov5_swmal_requirements.txt (line 9)) (2021.10.8)
Requirement already satisfied: typing-extensions in /opt/anaconda-2021.11/lib/python3.9/site-packages (from torch>=1.7.0->-r yolov5_swmal_requirements.txt (line 11)) (3.10.0.2)
Requirement already satisfied: markdown>=2.6.8 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (3.3.4)
Collecting tensorboard-data-server<0.7.0,>=0.6.0
Using cached tensorboard_data_server-0.6.1-py3-none-manylinux2010_x86_64.whl (4.9 MB)
Requirement already satisfied: absl-py>=0.4 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (0.15.0)
Requirement already satisfied: grpcio>=1.24.3 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (1.42.0)
Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (0.4.4)
Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (1.6.0)
Requirement already satisfied: wheel>=0.26 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (0.37.0)
Requirement already satisfied: werkzeug>=0.11.15 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (2.0.2)
Requirement already satisfied: google-auth<3,>=1.6.3 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (2.6.0)
Requirement already satisfied: setuptools>=41.0.0 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (58.0.4)
Requirement already satisfied: protobuf>=3.6.0 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (3.19.1)
Requirement already satisfied: six in /opt/anaconda-2021.11/lib/python3.9/site-packages (from absl-py>=0.4->tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (1.16.0)
Requirement already satisfied: cachetools<6.0,>=2.0.0 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from google-auth<3,>=1.6.3->tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (4.2.2)
Requirement already satisfied: pyasn1-modules>=0.2.1 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from google-auth<3,>=1.6.3->tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (0.2.8)
Requirement already satisfied: rsa<5,>=3.1.4 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from google-auth<3,>=1.6.3->tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (4.7.2)
Requirement already satisfied: requests-oauthlib>=0.7.0 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (1.3.0)
Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (0.4.8)
Requirement already satisfied: oauthlib>=3.0.0 in /opt/anaconda-2021.11/lib/python3.9/site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard>=2.4.1->-r yolov5_swmal_requirements.txt (line 21)) (3.2.0)
Installing collected packages: tensorboard-data-server, thop, tensorboard, opencv-python
 WARNING: The script tensorboard is installed in '/home/cef/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tensorflow 2.4.1 requires flatbuffers~=1.12.0, but you have flatbuffers 2.0 which is incompatible.
tensorflow 2.4.1 requires gast==0.3.3, but you have gast 0.4.0 which is incompatible.
tensorflow 2.4.1 requires grpcio~=1.32.0, but you have grpcio 1.42.0 which is incompatible.
tensorflow 2.4.1 requires numpy~=1.19.2, but you have numpy 1.20.3 which is incompatible.
tensorflow 2.4.1 requires six~=1.15.0, but you have six 1.16.0 which is incompatible.
tensorflow 2.4.1 requires tensorflow-estimator<2.5.0,>=2.4.0, but you have tensorflow-estimator 2.6.0 which is incompatible.
tensorflow 2.4.1 requires typing-extensions~=3.7.4, but you have typing-extensions 3.10.0.2 which is incompatible.
Successfully installed opencv-python-4.5.5.64 tensorboard-2.8.0 tensorboard-data-server-0.6.1 thop-0.0.31.post2005241907
%% Cell type:markdown id:c242e453-49c0-4455-aab8-72297ed4e98e tags:
You should now have the reqired setup for Yolov5, and I took care of installing specific GPU libraries needed for running Yolov5 on even the newest GPUs (3090).
The user installed packages (found in you `~/.local/lib/python3.9/site-packages/` dir) now looks like:
%% Cell type:code id:75a7580f-b3f2-4942-8234-053120ad313b tags:
``` python
! pip list --user
! echo ; echo "DIR of local packages.." ; echo
! ls ~/.local/lib/python3.9/site-packages/
```
%% Output
Package Version
----------------------- ---------------------
opencv-python 4.5.5.64
tensorboard 2.8.0
tensorboard-data-server 0.6.1
thop 0.0.31.post2005241907
torch 1.10.1+cu111
torchaudio 0.10.1+rocm4.1
torchvision 0.11.2+cu111
DIR of local packages..
caffe2 thop-0.0.31.post2005241907.dist-info
cv2 torch
opencv_python-4.5.5.64.dist-info torch-1.10.1+cu111.dist-info
opencv_python.libs torchaudio
tensorboard torchaudio-0.10.1+rocm4.1.dist-info
tensorboard-2.8.0.dist-info torchvision
tensorboard_data_server torchvision-0.11.2+cu111.dist-info
tensorboard_data_server-0.6.1.dist-info torchvision.libs
thop
%% Cell type:markdown id:510d57eb-399c-4704-90f3-a4efd4bd3a3e tags:
An now you can test out a demo of Yolov5 -- one that predicts on the image `Figs/zidane.jpg`.
If succefull an output prediction image will be placed in the `temp.jpg/`:
An now you can test out a demo of Yolov5 -- one that predicts on the image `Figs/zidane.jpg`:
%% Cell type:code id:cac6ad2d-5e41-4131-94e5-476b8ba41d91 tags:
``` python
#!/usr/bin/env python3
import torch
import sys
def Versions():
print("VERSIONS:")
print(f" _sys.version = { sys.version}")
print(f" sys.version = {sys.version}")
print(f" torch.__version__ = {torch.__version__}")
print(f" torch.cuda.is_available() = {torch.cuda.is_available()}")
print(f" torch.backends.cudnn.enabled = {torch.backends.cudnn.enabled}")
device = torch.device("cuda")
print(f" torch.cuda.get_device_properties(device) = {torch.cuda.get_device_properties(device)}")
print(f" torch.tensor([1.0, 2.0]).cuda() = {torch.tensor([1.0, 2.0]).cuda()}")
hasCuda = torch.cuda.is_available()
print(f" torch.cuda.is_available() = {hasCuda}")
if hasCuda:
print(f" torch.backends.cudnn.enabled = {torch.backends.cudnn.enabled}")
device = torch.device("cuda")
print(f" torch.cuda.get_device_properties(device) = {torch.cuda.get_device_properties(device)}")
print(f" torch.tensor([1.0, 2.0]).cuda() = {torch.tensor([1.0, 2.0]).cuda()}")
def PredictDemo():
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # or yolov5m, yolov5l, yolov5x, custom
# Images
#img = 'https://ultralytics.com/images/zidane.jpg' # or file, Path, PIL, OpenCV, numpy, list
img = 'Figs/zidane.jpg'
# Inference
results = model(img)
# Results
results.print() # or .show(), .save(), .crop(), .pandas(), etc.
#results.show()
results.save('temp.jpg')
Versions()
PredictDemo()
print("OK")
```
%% Output
%% Cell type:markdown id:2211aee5 tags:
VERSIONS:
_sys.version = 3.9.7 (default, Sep 16 2021, 13:09:58)
[GCC 7.5.0]
torch.__version__ = 1.10.1+cu111
torch.cuda.is_available() = True
torch.backends.cudnn.enabled = True
torch.cuda.get_device_properties(device) = _CudaDeviceProperties(name='NVIDIA GeForce GTX 1080', major=6, minor=1, total_memory=8119MB, multi_processor_count=20)
torch.tensor([1.0, 2.0]).cuda() = tensor([1., 2.], device='cuda:0')
If succefull an output prediction image will be placed in the temp.jpg/ or in runs/detect/expNN so look for the output line from the cell, similar to
Using cache found in /home/cef/.cache/torch/hub/ultralytics_yolov5_master
YOLOv5 🚀 2022-1-11 torch 1.10.1+cu111 CUDA:0 (NVIDIA GeForce GTX 1080, 8119MiB)
Fusing layers...
Model Summary: 213 layers, 7225885 parameters, 0 gradients, 16.5 GFLOPs
Adding AutoShape...
image 1/1: 720x1280 2 persons, 2 ties
Speed: 132.4ms pre-process, 16.4ms inference, 28.6ms NMS per image at shape (1, 3, 384, 640)
Saved 1 image to temp.jpg
OK
```
VERSIONS:
sys.version = 3.9.7 ...
torch.__version__ = 1.11.0+cpu
torch.cuda.is_available() = False
Using cache found in C:\Users\au204573/.cache\torch\hub\ultralytics_yolov5_master
YOLOv5 2022-4-3 torch 1.11.0+cpu CPU
Fusing layers...
YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients
Adding AutoShape...
image 1/1: 720x1280 2 persons, 2 ties
Speed: 31.6ms pre-process, 298.2ms inference, 2.2ms NMS per image at shape (1, 3, 384, 640)
Saved 1 image to temp.jpg
```
%% Cell type:code id:80ba1888-371c-4b01-93e5-eec80f54e771 tags:
``` python
%matplotlib inline
from matplotlib import pyplot as plt
import cv2
def ShowImg(imgfilename):
img = cv2.imread(imgfilename, 1)
img2 = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) #Converts from one colour space to the other
plt.imshow(img2)
plt.xticks([]), plt.yticks([]) # Hides the graph ticks and x / y axis
plt.show()
#ShowImg('runs/detect/exp2/zidane.jpg')
ShowImg('temp.jpg/zidane.jpg')
```
%% Output
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment