Commit a64e88ac authored by Carsten Eie Frigaard's avatar Carsten Eie Frigaard
Browse files

yolov5_update

parent 92576009
%% 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
%% 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
```
%% 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/
```
%% 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/` folder.
%% 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" 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()}")
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")
```