From 5bb345f11211f31b85eed8f0949c5083ebdd5c5b Mon Sep 17 00:00:00 2001 From: hanoch Date: Wed, 7 Aug 2024 18:03:48 +0300 Subject: [PATCH] fix annotation txtx file creation --- cfg/training/yolov7-tiny.yaml | 4 ++-- data/hyp.scratch.tiny.yaml | 10 +++++----- detect.py | 4 ++++ train.py | 5 +++++ train_aux.py | 9 +++++++++ utils/datasets.py | 17 +++++++++-------- 6 files changed, 34 insertions(+), 15 deletions(-) diff --git a/cfg/training/yolov7-tiny.yaml b/cfg/training/yolov7-tiny.yaml index 3679b0d..39e92a2 100644 --- a/cfg/training/yolov7-tiny.yaml +++ b/cfg/training/yolov7-tiny.yaml @@ -1,6 +1,6 @@ # parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple +nc: 2 # number of classes +depth_multiple: 1.0 # model depth multiple @@ HK TODO: width_multiple: 1.0 # layer channel multiple # anchors diff --git a/data/hyp.scratch.tiny.yaml b/data/hyp.scratch.tiny.yaml index b0dc14a..a90e004 100644 --- a/data/hyp.scratch.tiny.yaml +++ b/data/hyp.scratch.tiny.yaml @@ -14,12 +14,12 @@ iou_t: 0.20 # IoU training threshold anchor_t: 4.0 # anchor-multiple threshold # anchors: 3 # anchors per output layer (0 to ignore) fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) +hsv_h: 0.0 # image HSV-Hue augmentation (fraction) +hsv_s: 0.0 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.0 # image HSV-Value augmentation (fraction) degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.5 # image scale (+/- gain) +translate: 0.0 # image translation (+/- fraction) +scale: 0.0 # image scale (+/- gain) shear: 0.0 # image shear (+/- deg) perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 flipud: 0.0 # image flip up-down (probability) diff --git a/detect.py b/detect.py index 5e0c441..0cdb158 100644 --- a/detect.py +++ b/detect.py @@ -194,3 +194,7 @@ if __name__ == '__main__': strip_optimizer(opt.weights) else: detect() + +""" +python detect.py --weights yolov7.pt --conf 0.25 --img-size 640 --source inference/images/horses.jpg +""" \ No newline at end of file diff --git a/train.py b/train.py index 86c7e48..c8c601a 100644 --- a/train.py +++ b/train.py @@ -703,3 +703,8 @@ if __name__ == '__main__': plot_evolution(yaml_file) print(f'Hyperparameter evolution complete. Best results saved as: {yaml_file}\n' f'Command to train a new model with these hyperparameters: $ python train.py --hyp {yaml_file}') + + +""" +python train.py --workers 8 --device 'cpu' --batch-size 32 --data data/coco.yaml --img 640 640 --cfg cfg/training/yolov7.yaml --weights 'v7' --name yolov7 --hyp data/hyp.scratch.p5.yaml +""" \ No newline at end of file diff --git a/train_aux.py b/train_aux.py index 0e8053f..ed6d939 100644 --- a/train_aux.py +++ b/train_aux.py @@ -558,6 +558,8 @@ if __name__ == '__main__': parser.add_argument('--save_period', type=int, default=-1, help='Log model after every "save_period" epoch') parser.add_argument('--artifact_alias', type=str, default="latest", help='version of dataset artifact to be used') parser.add_argument('--v5-metric', action='store_true', help='assume maximum recall as 1.0 in AP calculation') + parser.add_argument('--tir-od', action='store_true', help='TIR Object Detection') + opt = parser.parse_args() # Set DDP variables @@ -697,3 +699,10 @@ if __name__ == '__main__': plot_evolution(yaml_file) print(f'Hyperparameter evolution complete. Best results saved as: {yaml_file}\n' f'Command to train a new model with these hyperparameters: $ python train.py --hyp {yaml_file}') + + +""" +python train.py --workers 8 --device 0 --batch-size 32 --data data/coco.yaml --img 640 640 --cfg cfg/training/yolov7.yaml --weights '' --name yolov7 --hyp data/hyp.scratch.p5.yaml + + +""" \ No newline at end of file diff --git a/utils/datasets.py b/utils/datasets.py index 5fe4f7b..579ba9c 100644 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -29,7 +29,7 @@ from torchvision.ops import roi_pool, roi_align, ps_roi_pool, ps_roi_align from utils.general import check_requirements, xyxy2xywh, xywh2xyxy, xywhn2xyxy, xyn2xy, segment2box, segments2boxes, \ resample_segments, clean_str from utils.torch_utils import torch_distributed_zero_first - +# @@HK : pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 resolve h\lib\fbgemm.dll" or one of its dependencies on Windows # Parameters help_url = 'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data' img_formats = ['bmp', 'jpg', 'jpeg', 'png', 'tif', 'tiff', 'dng', 'webp', 'mpo'] # acceptable image suffixes @@ -358,7 +358,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing self.hyp = hyp self.image_weights = image_weights self.rect = False if image_weights else rect - self.mosaic = self.augment and not self.rect # load 4 images at a time into a mosaic (only during training) + self.mosaic = self.augment and not self.rect # load 4 images at a time into a mosaic (only during training) @@ HK TODO: disable mosaic self.mosaic_border = [-img_size // 2, -img_size // 2] self.stride = stride self.path = path @@ -570,12 +570,13 @@ class LoadImagesAndLabels(Dataset): # for training/testing if self.augment: # Augment imagespace if not mosaic: - img, labels = random_perspective(img, labels, - degrees=hyp['degrees'], - translate=hyp['translate'], - scale=hyp['scale'], - shear=hyp['shear'], - perspective=hyp['perspective']) + if not hyp['tir_od']: + img, labels = random_perspective(img, labels, + degrees=hyp['degrees'], + translate=hyp['translate'], + scale=hyp['scale'], + shear=hyp['shear'], + perspective=hyp['perspective']) #img, labels = self.albumentations(img, labels)