mirror of https://github.com/WongKinYiu/yolov7.git
random seed, hyp for random perspective
parent
5639572615
commit
e16bd3ffad
|
@ -0,0 +1,36 @@
|
||||||
|
lr0: 0.001 #0.001 # initial learning rate (SGD=1E-2, Adam=1E-3)
|
||||||
|
lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf)
|
||||||
|
momentum: 0.937 # SGD momentum/Adam beta1
|
||||||
|
weight_decay: 0.005 # optimizer weight decay 5e-4 It resolve mAP of overfitting test
|
||||||
|
warmup_epochs: 3.0 # warmup epochs (fractions ok)
|
||||||
|
warmup_momentum: 0.8 # warmup initial momentum
|
||||||
|
warmup_bias_lr: 0.001 #0.001 # warmup initial bias lr
|
||||||
|
box: 0.05 # box loss gain
|
||||||
|
cls: 0.5 # cls loss gain
|
||||||
|
cls_pw: 1.0 # cls BCELoss positive_weight
|
||||||
|
obj: 1.0 # obj loss gain (scale with pixels)
|
||||||
|
obj_pw: 1.0 # obj BCELoss positive_weight
|
||||||
|
iou_t: 0.60 # like the default in the code was 0.2 IoU training threshold
|
||||||
|
anchor_t: 4.0 # anchor-multiple threshold
|
||||||
|
anchors: 3 # anchors per output layer (0 to ignore) @@HK was 3
|
||||||
|
fl_gamma: 1.5 #1.5 # focal loss gamma (efficientDet default gamma=1.5)
|
||||||
|
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 # image rotation (+/- deg)
|
||||||
|
translate: 0 # image translation (+/- fraction)
|
||||||
|
scale: 0 # image scale (+/- gain)
|
||||||
|
shear: 0.0 # image shear (+/- deg)
|
||||||
|
perspective: 0.0 # image perspective (+/- fraction), range 0-0.001
|
||||||
|
flipud: 0.3 # image flip up-down (probability)
|
||||||
|
fliplr: 0.5 # image flip left-right (probability)
|
||||||
|
mosaic: 0.5 # image mosaic (probability)
|
||||||
|
mixup: 0.15 # image mixup (probability)
|
||||||
|
copy_paste: 0.0 # image copy paste (probability)
|
||||||
|
paste_in: 0.0 # image copy paste (probability), use 0 for faster training : cutout
|
||||||
|
loss_ota: 0 #1 # use ComputeLossOTA, use 0 for faster training
|
||||||
|
inversion: 0.5 #opposite temperature
|
||||||
|
img_percentile_removal: 0.3
|
||||||
|
beta : 0.3
|
||||||
|
random_perspective : 0
|
||||||
|
gamma : 80 # percent
|
|
@ -0,0 +1,36 @@
|
||||||
|
lr0: 0.005 #0.001 # initial learning rate (SGD=1E-2, Adam=1E-3)
|
||||||
|
lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf)
|
||||||
|
momentum: 0.937 # SGD momentum/Adam beta1
|
||||||
|
weight_decay: 0.005 # optimizer weight decay 5e-4 It resolve mAP of overfitting test
|
||||||
|
warmup_epochs: 3.0 # warmup epochs (fractions ok)
|
||||||
|
warmup_momentum: 0.8 # warmup initial momentum
|
||||||
|
warmup_bias_lr: 0.001 #0.001 # warmup initial bias lr
|
||||||
|
box: 0.05 # box loss gain
|
||||||
|
cls: 0.5 # cls loss gain
|
||||||
|
cls_pw: 1.0 # cls BCELoss positive_weight
|
||||||
|
obj: 1.0 # obj loss gain (scale with pixels)
|
||||||
|
obj_pw: 1.0 # obj BCELoss positive_weight
|
||||||
|
iou_t: 0.60 # like the default in the code was 0.2 IoU training threshold
|
||||||
|
anchor_t: 4.0 # anchor-multiple threshold
|
||||||
|
anchors: 2 # anchors per output layer (0 to ignore) @@HK was 3
|
||||||
|
fl_gamma: 1.5 #1.5 # focal loss gamma (efficientDet default gamma=1.5)
|
||||||
|
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 # image rotation (+/- deg)
|
||||||
|
translate: 0 # image translation (+/- fraction)
|
||||||
|
scale: 0 # image scale (+/- gain)
|
||||||
|
shear: 0.0 # image shear (+/- deg)
|
||||||
|
perspective: 0.0 # image perspective (+/- fraction), range 0-0.001
|
||||||
|
flipud: 0.3 # image flip up-down (probability)
|
||||||
|
fliplr: 0.5 # image flip left-right (probability)
|
||||||
|
mosaic: 0.5 # image mosaic (probability)
|
||||||
|
mixup: 0.15 # image mixup (probability)
|
||||||
|
copy_paste: 0.0 # image copy paste (probability)
|
||||||
|
paste_in: 0.0 # image copy paste (probability), use 0 for faster training : cutout
|
||||||
|
loss_ota: 0 #1 # use ComputeLossOTA, use 0 for faster training
|
||||||
|
inversion: 0.5 #opposite temperature
|
||||||
|
img_percentile_removal: 0.3
|
||||||
|
beta : 0.3
|
||||||
|
random_perspective : 0
|
||||||
|
gamma : 80 # percent
|
|
@ -0,0 +1,36 @@
|
||||||
|
lr0: 0.001 #0.001 # initial learning rate (SGD=1E-2, Adam=1E-3)
|
||||||
|
lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf)
|
||||||
|
momentum: 0.937 # SGD momentum/Adam beta1
|
||||||
|
weight_decay: 0.005 # optimizer weight decay 5e-4 It resolve mAP of overfitting test
|
||||||
|
warmup_epochs: 3.0 # warmup epochs (fractions ok)
|
||||||
|
warmup_momentum: 0.8 # warmup initial momentum
|
||||||
|
warmup_bias_lr: 0.001 #0.001 # warmup initial bias lr
|
||||||
|
box: 0.05 # box loss gain
|
||||||
|
cls: 0.5 # cls loss gain
|
||||||
|
cls_pw: 1.0 # cls BCELoss positive_weight
|
||||||
|
obj: 1.0 # obj loss gain (scale with pixels)
|
||||||
|
obj_pw: 1.0 # obj BCELoss positive_weight
|
||||||
|
iou_t: 0.60 # like the default in the code was 0.2 IoU training threshold
|
||||||
|
anchor_t: 4.0 # anchor-multiple threshold
|
||||||
|
anchors: 2 # anchors per output layer (0 to ignore) @@HK was 3
|
||||||
|
fl_gamma: 1.5 #1.5 # focal loss gamma (efficientDet default gamma=1.5)
|
||||||
|
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.2 # image translation (+/- fraction)
|
||||||
|
scale: 0.9 # image scale (+/- gain)
|
||||||
|
shear: 0.0 # image shear (+/- deg)
|
||||||
|
perspective: 0.001 # image perspective (+/- fraction), range 0-0.001
|
||||||
|
flipud: 0.3 # image flip up-down (probability)
|
||||||
|
fliplr: 0.5 # image flip left-right (probability)
|
||||||
|
mosaic: 0.5 # image mosaic (probability)
|
||||||
|
mixup: 0.15 # image mixup (probability)
|
||||||
|
copy_paste: 0.0 # image copy paste (probability)
|
||||||
|
paste_in: 0.0 # image copy paste (probability), use 0 for faster training : cutout
|
||||||
|
loss_ota: 0 #1 # use ComputeLossOTA, use 0 for faster training
|
||||||
|
inversion: 0.5 #opposite temperature
|
||||||
|
img_percentile_removal: 0.3
|
||||||
|
beta : 0.3
|
||||||
|
random_perspective : 0
|
||||||
|
gamma : 80 # percent
|
|
@ -0,0 +1,37 @@
|
||||||
|
lr0: 0.005 #0.001 # initial learning rate (SGD=1E-2, Adam=1E-3)
|
||||||
|
lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf)
|
||||||
|
momentum: 0.937 # SGD momentum/Adam beta1
|
||||||
|
weight_decay: 0.005 # optimizer weight decay 5e-4 It resolve mAP of overfitting test
|
||||||
|
warmup_epochs: 3.0 # warmup epochs (fractions ok)
|
||||||
|
warmup_momentum: 0.8 # warmup initial momentum
|
||||||
|
warmup_bias_lr: 0.001 #0.001 # warmup initial bias lr
|
||||||
|
box: 0.05 # box loss gain
|
||||||
|
cls: 0.5 # cls loss gain
|
||||||
|
cls_pw: 1.0 # cls BCELoss positive_weight
|
||||||
|
obj: 1.0 # obj loss gain (scale with pixels)
|
||||||
|
obj_pw: 1.0 # obj BCELoss positive_weight
|
||||||
|
iou_t: 0.20 # IoU training threshold
|
||||||
|
anchor_t: 4.0 # anchor-multiple threshold
|
||||||
|
anchors: 2 # anchors per output layer (0 to ignore) @@HK was 3
|
||||||
|
fl_gamma: 1.5 #1.5 # focal loss gamma (efficientDet default gamma=1.5)
|
||||||
|
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 # image rotation (+/- deg)
|
||||||
|
translate: 0 # image translation (+/- fraction)
|
||||||
|
scale: 0 # image scale (+/- gain)
|
||||||
|
shear: 0.0 # image shear (+/- deg)
|
||||||
|
perspective: 0.0 # image perspective (+/- fraction), range 0-0.001
|
||||||
|
flipud: 0.3 # image flip up-down (probability)
|
||||||
|
fliplr: 0.5 # image flip left-right (probability)
|
||||||
|
mosaic: 0.5 # image mosaic (probability)
|
||||||
|
mixup: 0.15 # image mixup (probability)
|
||||||
|
copy_paste: 0.0 # image copy paste (probability)
|
||||||
|
paste_in: 0.3 # image copy paste (probability), use 0 for faster training : cutout
|
||||||
|
loss_ota: 0 #1 # use ComputeLossOTA, use 0 for faster training
|
||||||
|
inversion: 0.5 #opposite temperature
|
||||||
|
img_percentile_removal: 0.3
|
||||||
|
beta : 0.3
|
||||||
|
random_perspective : 0
|
||||||
|
gamma : 80 # percent
|
||||||
|
gamma_liklihood: 0.25
|
2
test.py
2
test.py
|
@ -448,4 +448,6 @@ test based on RGB coco model
|
||||||
|
|
||||||
|
|
||||||
--weights /mnt/Data/hanoch/runs/train/yolov7575/weights/best.pt --device 0 --batch-size 16 --data data/tir_od_test_set.yaml --img-size 640 --conf 0.001 --verbose --norm-type single_image_percentile_0_1 --input-channels 1 --project test --task test --iou-thres 0.6
|
--weights /mnt/Data/hanoch/runs/train/yolov7575/weights/best.pt --device 0 --batch-size 16 --data data/tir_od_test_set.yaml --img-size 640 --conf 0.001 --verbose --norm-type single_image_percentile_0_1 --input-channels 1 --project test --task test --iou-thres 0.6
|
||||||
|
--weights /home/hanoch/projects/tir_od/runs/gpu02/yolov74/weights --device 0 --batch-size 16 --data data/tir_od_test_set.yaml --img-size 640 --conf 0.001 --verbose --norm-type single_image_percentile_0_1 --input-channels 1 --project test --task test --iou-thres 0.6
|
||||||
|
|
||||||
"""
|
"""
|
40
train.py
40
train.py
|
@ -52,12 +52,16 @@ logger = logging.getLogger(__name__)
|
||||||
clear_ml = True
|
clear_ml = True
|
||||||
|
|
||||||
from clearml import Task, Logger
|
from clearml import Task, Logger
|
||||||
task = Task.init(
|
|
||||||
project_name="TIR_OD",
|
if clear_ml: # clearml support
|
||||||
task_name="train yolov7 with dummy test"
|
|
||||||
)
|
task = Task.init(
|
||||||
# Task.execute_remotely() will invoke the job immidiately over the remote and not DeV
|
project_name="TIR_OD",
|
||||||
task.set_base_docker(docker_image="nvcr.io/nvidia/pytorch:24.09-py3", docker_arguments="--shm-size 8G")
|
task_name="train yolov7 with dummy test"
|
||||||
|
)
|
||||||
|
# Task.execute_remotely() will invoke the job immidiately over the remote and not DeV
|
||||||
|
task.set_base_docker(docker_image="nvcr.io/nvidia/pytorch:24.09-py3", docker_arguments="--shm-size 8G")
|
||||||
|
|
||||||
gradient_clip_value = 100.0
|
gradient_clip_value = 100.0
|
||||||
opt_gradient_clipping = True
|
opt_gradient_clipping = True
|
||||||
|
|
||||||
|
@ -121,9 +125,6 @@ def train(hyp, opt, device, tb_writer=None):
|
||||||
best = wdir / 'best.pt'
|
best = wdir / 'best.pt'
|
||||||
results_file = save_dir / 'results.txt'
|
results_file = save_dir / 'results.txt'
|
||||||
|
|
||||||
# Save run settings
|
|
||||||
with open(save_dir / 'hyp.yaml', 'w') as f:
|
|
||||||
yaml.dump(hyp, f, sort_keys=False)
|
|
||||||
with open(save_dir / 'opt.yaml', 'w') as f:
|
with open(save_dir / 'opt.yaml', 'w') as f:
|
||||||
yaml.dump(vars(opt), f, sort_keys=False)
|
yaml.dump(vars(opt), f, sort_keys=False)
|
||||||
|
|
||||||
|
@ -132,7 +133,17 @@ def train(hyp, opt, device, tb_writer=None):
|
||||||
# Configure
|
# Configure
|
||||||
plots = not opt.evolve # create plots
|
plots = not opt.evolve # create plots
|
||||||
cuda = device.type != 'cpu'
|
cuda = device.type != 'cpu'
|
||||||
init_seeds(2 + rank)
|
if opt.predefined_seed:
|
||||||
|
hyp['seed'] = 2 + rank
|
||||||
|
init_seeds(2 + rank)
|
||||||
|
else:
|
||||||
|
rand_seed = int(time.time())
|
||||||
|
hyp['seed'] = rand_seed
|
||||||
|
init_seeds(rand_seed)
|
||||||
|
|
||||||
|
# Save run settings
|
||||||
|
with open(save_dir / 'hyp.yaml', 'w') as f:
|
||||||
|
yaml.dump(hyp, f, sort_keys=False)
|
||||||
|
|
||||||
if clear_ml: #clearml support
|
if clear_ml: #clearml support
|
||||||
config_file = task.connect_configuration(opt.data)
|
config_file = task.connect_configuration(opt.data)
|
||||||
|
@ -374,7 +385,9 @@ def train(hyp, opt, device, tb_writer=None):
|
||||||
check_anchors(dataset, model=model, thr=hyp['anchor_t'], imgsz=imgsz)
|
check_anchors(dataset, model=model, thr=hyp['anchor_t'], imgsz=imgsz)
|
||||||
if opt.amp or 1:
|
if opt.amp or 1:
|
||||||
model.half().float() # pre-reduce anchor precision TODO HK Why ? >???!!!!
|
model.half().float() # pre-reduce anchor precision TODO HK Why ? >???!!!!
|
||||||
|
if 1:
|
||||||
|
print("opt.local_rank", opt.local_rank)
|
||||||
|
print("opt.local_rank", opt.local_rank)
|
||||||
# DDP mode
|
# DDP mode
|
||||||
if cuda and rank != -1:
|
if cuda and rank != -1:
|
||||||
model = DDP(model, device_ids=[opt.local_rank], output_device=opt.local_rank,
|
model = DDP(model, device_ids=[opt.local_rank], output_device=opt.local_rank,
|
||||||
|
@ -694,7 +707,7 @@ if __name__ == '__main__':
|
||||||
parser.add_argument('--single-cls', action='store_true', help='train multi-class data as single-class')
|
parser.add_argument('--single-cls', action='store_true', help='train multi-class data as single-class')
|
||||||
parser.add_argument('--adam', action='store_true', help='use torch.optim.Adam() optimizer')
|
parser.add_argument('--adam', action='store_true', help='use torch.optim.Adam() optimizer')
|
||||||
parser.add_argument('--sync-bn', action='store_true', help='use SyncBatchNorm, only available in DDP mode')
|
parser.add_argument('--sync-bn', action='store_true', help='use SyncBatchNorm, only available in DDP mode')
|
||||||
parser.add_argument('--local_rank', type=int, default=-1, help='DDP parameter, do not modify')
|
parser.add_argument('--local-rank', type=int, default=-1, help='DDP parameter, do not modify') #Changed in version 2.0.0: The launcher will passes the --local-rank=<rank> argument to your script. From PyTorch 2.0.0 onwards, the dashed --local-rank is preferred over the previously used underscored --local_rank.
|
||||||
parser.add_argument('--workers', type=int, default=8, help='maximum number of dataloader workers')
|
parser.add_argument('--workers', type=int, default=8, help='maximum number of dataloader workers')
|
||||||
parser.add_argument('--project', default='runs/train', help='save to project/name')
|
parser.add_argument('--project', default='runs/train', help='save to project/name')
|
||||||
parser.add_argument('--entity', default=None, help='W&B entity')
|
parser.add_argument('--entity', default=None, help='W&B entity')
|
||||||
|
@ -725,6 +738,9 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
parser.add_argument('--amp', action='store_true', help='Remove torch AMP')
|
parser.add_argument('--amp', action='store_true', help='Remove torch AMP')
|
||||||
|
|
||||||
|
parser.add_argument('--predefined-seed', action='store_true', help='predefined_seed only set it to constant otherwise add args that load the random one ')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
opt = parser.parse_args()
|
opt = parser.parse_args()
|
||||||
|
|
|
@ -912,11 +912,6 @@ def load_mosaic(self, index):
|
||||||
for i, index in enumerate(indices):
|
for i, index in enumerate(indices):
|
||||||
# Load image
|
# Load image
|
||||||
img, _, (h, w) = load_image(self, index)
|
img, _, (h, w) = load_image(self, index)
|
||||||
# if 1:
|
|
||||||
# img = np.repeat(img[:, :, np.newaxis], 3, axis=2)
|
|
||||||
# if img.ndim <3 : #TIR =>unsqueeze ro RGB 1-channel
|
|
||||||
# tir_signal = True
|
|
||||||
# img = img[:, :, np.newaxis] #np.repeat(img[:, :, np.newaxis], 3, axis=2) #img[:, :, np.newaxis]
|
|
||||||
# place img in img4
|
# place img in img4
|
||||||
if i == 0: # top left
|
if i == 0: # top left
|
||||||
if self.is_tir_signal:
|
if self.is_tir_signal:
|
||||||
|
@ -1436,7 +1431,7 @@ class Albumentations_gamma_contrast:
|
||||||
|
|
||||||
self.transform = A.Compose([
|
self.transform = A.Compose([
|
||||||
# A.CLAHE(p=0.01),
|
# A.CLAHE(p=0.01),
|
||||||
A.RandomBrightnessContrast(brightness_limit=0.2, contrast_limit=0.2, p=alb_prob),
|
A.RandomBrightnessContrast(brightness_limit=0.2, contrast_limit=0.2, p=alb_prob), #Contrast adjustment: x' = clip((x - mean) * (1 + a) + mean) ; x'' = clip(x' * (1 + β))
|
||||||
A.RandomGamma(gamma_limit=gamma_limit, p=alb_prob)])
|
A.RandomGamma(gamma_limit=gamma_limit, p=alb_prob)])
|
||||||
# A.Blur(p=0.01),
|
# A.Blur(p=0.01),
|
||||||
# A.MedianBlur(p=0.01),
|
# A.MedianBlur(p=0.01),
|
||||||
|
|
Loading…
Reference in New Issue