mirror of
https://github.com/NohamR/Stage-2024.git
synced 2025-05-24 00:49:06 +00:00
5.5 KiB
5.5 KiB
References
https://theses.hal.science/tel-01784521/file/TH2017ChapelMarieNeige.pdf
calcul de distance camera - objet
Yolov7-tracker
git clone https://github.com/JackWoo0831/Yolov7-tracker.git
mv Yolov7-tracker yolov7-tracker
cd yolov7-tracker
git checkout v2 # change to v2 branch !!
Change np.int to np.int64 in : utils/datasets.py utils/general.py
Fix for GPU in utils/loss.py:
from_which_layer.append((torch.ones(size=(len(b),)) * i).to('cuda')) ### SF #### (lines 686)
fg_mask_inboxes = fg_mask_inboxes.to(torch.device('cuda')) ### SF #### (lines 758 & 5164 & 1568)
Set up env :
conda create -n yolov7 python=3.9 pytorch=1.12
conda activate yolov7
pip3 install numpy scipy matplotlib cython pandas cuda-python
conda env : /home/noham.rivoirard/.conda/envs/yolov7
pip3 install -r requirements.txt
pip3 install ultralytics==8.0.94
Setup cluster
ssh sas ssh cinaps ssh node20
nvidia-smi => cuda 11.4 sur node20
cf notes d'installation de pytorch pour trouver les bonnes versions : https://pytorch.org/get-started/previous-versions/
pip3 install torch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 --index-url https://download.pytorch.org/whl/cu118
pip3 install filterpy
>>> import torch
>>> torch.cuda.is_available()
True
Setup macos
conda install pytorch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 -c pytorch
Config train
- Create DATASETNAME.yaml in tracker/config_files (config file of the dataset):
DATASET_ROOT: '/data/DATASETNAME'
SPLIT: train
CATEGORY_NAMES:
- 'runner'
CATEGORY_DICT:
0: 'runner'
CERTAIN_SEQS:
-
IGNORE_SEQS: # Seqs you want to ignore
-
- Export from VoTT as json
- Convert to Yolov using vott2yolov.py
- Edit dataset.yaml in data/DATASETNAME:
train: data/DATASETNAME/liste_images.txt
val: data/DATASETNAME/liste_images.txt
nc: 1
names: ['runner']
- Get box sizes from the dataset using compute_yolov3_anchors.py, result as follow:
Your custom anchor boxes are [[ 13. 34.]
[ 17. 46.]
[ 18. 59.]
[ 21. 79.]
[ 26. 102.]
[ 33. 111.]
[ 34. 135.]
[ 40. 155.]
[ 76. 161.]]
Anchors box for yaml file:
anchors:
- [13,34, 17,46, 18,59] # P3/8
- [21,79, 26,102, 33,111] # P4/16
- [34,135, 40,155, 76,161] # P5/32
- Replace anchors box in cfg/training/yolov7x_DATASETNAME.yaml, ex: yolov7x_dataset2fps.yaml
Launch train
GPU:
python3 train.py --dataset dataset1_2024_06_19__ --workers 1 --device 0 --batch-size 4 --data data/dataset1_2024_06_19/datasetyaml --img 1280 720 --cfg cfg/training/yolov7x_dataset1_2024_06_19.yaml --weights '' --name yolov7x-dataset1_2024_06_19 --hyp data/hyp.scratch.custom.yaml
CPU:
python3 train.py --dataset dataset2fps_20240718_ --epochs 20 --workers 1 --device cpu --batch-size 4 --data data/dataset2fps/dataset.yaml --img 1280 720 --cfg cfg/training/yolov7x_dataset2fps.yaml --weights '' --name yolov7x-dataset2fps_20240718 --hyp data/hyp.scratch.custom.yaml
Note:
Si erreur : _pickle.UnpicklingError: STACK_GLOBAL requires str
Effacer les fichiers .cache : liste_images.cache par exemple...
Si erreur np.int => remplacer par des np.int64
Si erreur cuda/cpu dans loss.py :
you have to replace the line in the file yolo7/utils/loss.py
"from_which_layer.append((torch.ones(size=(len(b),)) * i)"
to "from_which_layer.append((torch.ones(size=(len(b),)) * i).to('cuda'))",
and add new line "fg_mask_inboxes = fg_mask_inboxes.to(torch.device('cuda'))"
after "fg_mask_inboxes = matching_matrix.sum(0) > 0.0"
so you need to do it 3 times in the file
Result :
10 iterations on MBP M2 : logs
On wandb : https://wandb.ai/noham-/YOLOR/runs/
PDF : pdf
Weights : best.pt