Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: implemented trainer #7

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# EurobotVision
Vision repo for Eurobot


Create train and val folder where you need to put the dataset
255 changes: 255 additions & 0 deletions Trainer.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Defaulting to user installation because normal site-packages is not writeable\n",
"Requirement already satisfied: torch in /home/defenge/.local/lib/python3.10/site-packages (2.2.2)\n",
"Requirement already satisfied: torchvision in /home/defenge/.local/lib/python3.10/site-packages (0.17.2)\n",
"Requirement already satisfied: torchaudio in /home/defenge/.local/lib/python3.10/site-packages (2.2.2)\n",
"Requirement already satisfied: nvidia-cudnn-cu12==8.9.2.26 in /home/defenge/.local/lib/python3.10/site-packages (from torch) (8.9.2.26)\n",
"Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /home/defenge/.local/lib/python3.10/site-packages (from torch) (12.1.3.1)\n",
"Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /home/defenge/.local/lib/python3.10/site-packages (from torch) (11.0.2.54)\n",
"Requirement already satisfied: jinja2 in /home/defenge/.local/lib/python3.10/site-packages (from torch) (3.1.3)\n",
"Requirement already satisfied: filelock in /home/defenge/.local/lib/python3.10/site-packages (from torch) (3.13.3)\n",
"Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /home/defenge/.local/lib/python3.10/site-packages (from torch) (12.1.105)\n",
"Requirement already satisfied: typing-extensions>=4.8.0 in /home/defenge/.local/lib/python3.10/site-packages (from torch) (4.10.0)\n",
"Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /home/defenge/.local/lib/python3.10/site-packages (from torch) (11.4.5.107)\n",
"Requirement already satisfied: triton==2.2.0 in /home/defenge/.local/lib/python3.10/site-packages (from torch) (2.2.0)\n",
"Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /home/defenge/.local/lib/python3.10/site-packages (from torch) (12.1.0.106)\n",
"Requirement already satisfied: networkx in /home/defenge/.local/lib/python3.10/site-packages (from torch) (3.2.1)\n",
"Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /home/defenge/.local/lib/python3.10/site-packages (from torch) (10.3.2.106)\n",
"Requirement already satisfied: nvidia-nccl-cu12==2.19.3 in /home/defenge/.local/lib/python3.10/site-packages (from torch) (2.19.3)\n",
"Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /home/defenge/.local/lib/python3.10/site-packages (from torch) (12.1.105)\n",
"Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /home/defenge/.local/lib/python3.10/site-packages (from torch) (12.1.105)\n",
"Requirement already satisfied: sympy in /home/defenge/.local/lib/python3.10/site-packages (from torch) (1.12)\n",
"Requirement already satisfied: fsspec in /home/defenge/.local/lib/python3.10/site-packages (from torch) (2024.3.1)\n",
"Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /home/defenge/.local/lib/python3.10/site-packages (from torch) (12.1.105)\n",
"Requirement already satisfied: nvidia-nvjitlink-cu12 in /home/defenge/.local/lib/python3.10/site-packages (from nvidia-cusolver-cu12==11.4.5.107->torch) (12.4.99)\n",
"Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /home/defenge/.local/lib/python3.10/site-packages (from torchvision) (10.2.0)\n",
"Requirement already satisfied: numpy in /home/defenge/.local/lib/python3.10/site-packages (from torchvision) (1.23.5)\n",
"Requirement already satisfied: MarkupSafe>=2.0 in /home/defenge/.local/lib/python3.10/site-packages (from jinja2->torch) (2.1.5)\n",
"Requirement already satisfied: mpmath>=0.19 in /home/defenge/.local/lib/python3.10/site-packages (from sympy->torch) (1.3.0)\n"
]
}
],
"source": [
"!pip install torch torchvision torchaudio"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"fatal: destination path 'yolov7' already exists and is not an empty directory.\n",
" % Total % Received % Xferd Average Speed Time Time Time Current\n",
" Dload Upload Total Spent Left Speed\n",
" 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n",
"mv: cannot stat '/yolov7-e6e.pt': No such file or directory\n",
"mv: cannot stat '/train': No such file or directory\n",
"mv: cannot stat '/val': No such file or directory\n",
"cp: cannot stat '/custom-data.yaml.dist': No such file or directory\n",
"cp: cannot stat '/yolov7-e6e-custom.yaml.dist': No such file or directory\n"
]
}
],
"source": [
"cwd = 'pwd'\n",
"!git clone [email protected]:WongKinYiu/yolov7.git\n",
"!curl -o yolov7-e6e.pt https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-e6e.pt\n",
"!mv \"${cwd}/yolov7-e6e.pt\" \"${cwd}/yolov7\"\n",
"!mv \"${cwd}/train\" \"${cwd}/yolov7/data\"\n",
"!mv \"${cwd}/val\" \"${cwd}/yolov7/data\"\n",
"!cp \"${cwd}/custom-data.yaml.dist\" \"${cwd}/yolov7/data/custom-data.yaml\"\n",
"!cp \"${cwd}/yolov7-e6e-custom.yaml.dist\" \"${cwd}/yolov7/cfg/training/yolov7-e6e-custom.yaml\"\n",
"#non funzionano i mv e cp"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/home/defenge/dev/EurobotVision/yolov7\n"
]
}
],
"source": [
"%cd yolov7\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"pip install -qr requirements.txt"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import torch \n",
"from matplotlib import pyplot as plt\n",
"import numpy as np\n",
"import cv2\n",
"from pathlib import Path\n",
"\n",
"from models.yolo import Model\n",
"from utils.general import check_requirements, set_logging\n",
"from utils.google_utils import attempt_download\n",
"from utils.torch_utils import select_device"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"\n",
"check_requirements(Path(\"\").parent / 'requirements.txt', exclude=('pycocotools', 'thop'))\n",
"set_logging()\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"YOLOR 🚀 v0.1-128-ga207844 torch 2.2.2+cu121 CUDA:0 (NVIDIA GeForce GTX 1080, 8191.875MB)\n",
"\n",
"Namespace(weights='yolov7-e6e.pt', cfg='cfg/training/yolov7-e6e-custom.yaml', data='data/custom-data.yaml', hyp='data/hyp.scratch.custom.yaml', epochs=100, batch_size=4, img_size=[1280, 960], rect=False, resume=False, nosave=False, notest=False, noautoanchor=False, evolve=False, bucket='', cache_images=False, image_weights=False, device='0', multi_scale=False, single_cls=False, adam=False, sync_bn=False, local_rank=-1, workers=1, project='runs/train', entity=None, name='test-custom', exist_ok=False, quad=False, linear_lr=False, label_smoothing=0.0, upload_dataset=False, bbox_interval=-1, save_period=-1, artifact_alias='latest', freeze=[0], v5_metric=False, world_size=1, global_rank=-1, save_dir='runs/train/test-custom4', total_batch_size=4)\n",
"\u001b[34m\u001b[1mtensorboard: \u001b[0mStart with 'tensorboard --logdir runs/train', view at http://localhost:6006/\n",
"\u001b[34m\u001b[1mhyperparameters: \u001b[0mlr0=0.01, lrf=0.1, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=0.05, cls=0.3, cls_pw=1.0, obj=0.7, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.2, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0, paste_in=0.0, loss_ota=1\n",
"Traceback (most recent call last):\n",
" File \"/home/defenge/dev/EurobotVision/yolov7/train.py\", line 616, in <module>\n",
" train(hyp, opt, device, tb_writer)\n",
" File \"/home/defenge/dev/EurobotVision/yolov7/train.py\", line 71, in train\n",
" run_id = torch.load(weights, map_location=device).get('wandb_id') if weights.endswith('.pt') and os.path.isfile(weights) else None\n",
" File \"/home/defenge/.local/lib/python3.10/site-packages/torch/serialization.py\", line 1040, in load\n",
" return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)\n",
" File \"/home/defenge/.local/lib/python3.10/site-packages/torch/serialization.py\", line 1258, in _legacy_load\n",
" magic_number = pickle_module.load(f, **pickle_load_args)\n",
"EOFError: Ran out of input\n"
]
}
],
"source": [
"!python3 train.py --workers 1 --device 0 --batch-size 4 --epochs 100 --img 1280 960 --data data/custom-data.yaml --hyp data/hyp.scratch.custom.yaml --cfg cfg/training/yolov7-e6e-custom.yaml --name test-custom --weights yolov7-e6e.pt"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Defaulting to user installation because normal site-packages is not writeable\n",
"Requirement already satisfied: ipywidgets in /home/defenge/.local/lib/python3.10/site-packages (8.1.2)\n",
"Requirement already satisfied: jupyterlab-widgets~=3.0.10 in /home/defenge/.local/lib/python3.10/site-packages (from ipywidgets) (3.0.10)\n",
"Requirement already satisfied: widgetsnbextension~=4.0.10 in /home/defenge/.local/lib/python3.10/site-packages (from ipywidgets) (4.0.10)\n",
"Requirement already satisfied: ipython>=6.1.0 in /home/defenge/.local/lib/python3.10/site-packages (from ipywidgets) (8.22.2)\n",
"Requirement already satisfied: traitlets>=4.3.1 in /home/defenge/.local/lib/python3.10/site-packages (from ipywidgets) (5.14.2)\n",
"Requirement already satisfied: comm>=0.1.3 in /home/defenge/.local/lib/python3.10/site-packages (from ipywidgets) (0.2.2)\n",
"Requirement already satisfied: decorator in /home/defenge/.local/lib/python3.10/site-packages (from ipython>=6.1.0->ipywidgets) (5.1.1)\n",
"Requirement already satisfied: stack-data in /home/defenge/.local/lib/python3.10/site-packages (from ipython>=6.1.0->ipywidgets) (0.6.3)\n",
"Requirement already satisfied: jedi>=0.16 in /home/defenge/.local/lib/python3.10/site-packages (from ipython>=6.1.0->ipywidgets) (0.19.1)\n",
"Requirement already satisfied: pexpect>4.3 in /home/defenge/.local/lib/python3.10/site-packages (from ipython>=6.1.0->ipywidgets) (4.9.0)\n",
"Requirement already satisfied: pygments>=2.4.0 in /home/defenge/.local/lib/python3.10/site-packages (from ipython>=6.1.0->ipywidgets) (2.17.2)\n",
"Requirement already satisfied: prompt-toolkit<3.1.0,>=3.0.41 in /home/defenge/.local/lib/python3.10/site-packages (from ipython>=6.1.0->ipywidgets) (3.0.43)\n",
"Requirement already satisfied: exceptiongroup in /home/defenge/.local/lib/python3.10/site-packages (from ipython>=6.1.0->ipywidgets) (1.2.0)\n",
"Requirement already satisfied: matplotlib-inline in /home/defenge/.local/lib/python3.10/site-packages (from ipython>=6.1.0->ipywidgets) (0.1.6)\n",
"Requirement already satisfied: parso<0.9.0,>=0.8.3 in /home/defenge/.local/lib/python3.10/site-packages (from jedi>=0.16->ipython>=6.1.0->ipywidgets) (0.8.3)\n",
"Requirement already satisfied: ptyprocess>=0.5 in /home/defenge/.local/lib/python3.10/site-packages (from pexpect>4.3->ipython>=6.1.0->ipywidgets) (0.7.0)\n",
"Requirement already satisfied: wcwidth in /home/defenge/.local/lib/python3.10/site-packages (from prompt-toolkit<3.1.0,>=3.0.41->ipython>=6.1.0->ipywidgets) (0.2.13)\n",
"Requirement already satisfied: pure-eval in /home/defenge/.local/lib/python3.10/site-packages (from stack-data->ipython>=6.1.0->ipywidgets) (0.2.2)\n",
"Requirement already satisfied: executing>=1.2.0 in /home/defenge/.local/lib/python3.10/site-packages (from stack-data->ipython>=6.1.0->ipywidgets) (2.0.1)\n",
"Requirement already satisfied: asttokens>=2.1.0 in /home/defenge/.local/lib/python3.10/site-packages (from stack-data->ipython>=6.1.0->ipywidgets) (2.4.1)\n",
"Requirement already satisfied: six>=1.12.0 in /usr/lib/python3/dist-packages (from asttokens>=2.1.0->stack-data->ipython>=6.1.0->ipywidgets) (1.16.0)\n"
]
}
],
"source": [
"!pip install ipywidgets "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"#model = torch.load('load_the_model_here_to_test')"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"#img = ''\n",
"#results = model(img)\n",
"#results.print()\n",
"#%matplotlib inline\n",
"#plt.imshow(np.squeeze(results.render()))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
8 changes: 8 additions & 0 deletions custom-data.yaml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train: ./data/train
val: ./data/val
# number of classes
nc: 2

# class names
names: [ 'plants', 'void' ]
Loading