mirror of https://github.com/WongKinYiu/yolov7.git
Fix rnd perspective fillng the padded pixels by TIR mean value to reduce edges artifacts.
mAP per med/large exclusivelypull/2109/head
parent
b2bc3773a1
commit
5e5dfde1f1
|
@ -18,10 +18,10 @@ 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)
|
||||
translate: 0 # image translation (+/- fraction)
|
||||
scale: 0.6 # image scale (+/- gain)
|
||||
shear: 0.0 # image shear (+/- deg)
|
||||
perspective: 0.001 # image perspective (+/- fraction), range 0-0.001
|
||||
perspective: 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)
|
||||
|
|
|
@ -19,19 +19,19 @@ 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)
|
||||
scale: 0.6 # 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)
|
||||
mixup: 0.0 # 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
|
||||
random_perspective : 1
|
||||
scaling_before_mosaic : 1
|
||||
gamma : 80 # percent
|
||||
|
|
|
@ -10,7 +10,7 @@ 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
|
||||
iou_t: 0.6 # 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)
|
||||
|
@ -19,19 +19,19 @@ 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)
|
||||
scale: 0.6 # 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)
|
||||
mixup: 0.0 # 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
|
||||
random_perspective : 1
|
||||
scaling_before_mosaic : 1
|
||||
gamma : 80 # percent
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
# COCO 2017 dataset http://cocodataset.org
|
||||
|
||||
# download command/URL (optional)
|
||||
|
||||
path: /home/hanoch/projects/tir_frames_rois/tir_tiff_tiff_files #/home/hanoch/projects/tir_frames_rois/tir_car_44person_31 #/home/hanochk/tir_frames_rois/yolo7_tir_data
|
||||
# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
|
||||
#train: ./yolov7/tir_od/training_set.txt #./yolov7/tir_od/training_set.txt # ./yolov7/tir_od/tir_tiff_car_person_min_size_44_31_training_set.txt #./yolov7/tir_od/training_set.txt #./yolov7/tir_od/training_set.txt # 118287 images
|
||||
#val: ./yolov7/tir_od/validation_set.txt #./yolov7/tir_od/tir_tiff_car_person_min_size_44_31_validation_set.txt #./yolov7/tir_od/validation_set.txt #./yolov7/tir_od/val_tir_od.txt #./yolov7/tir_od/validation_set.txt # 5000 images
|
||||
test: ./yolov7/tir_od/test_debug/tir_tiff_tiff_folder_test_set_debug.txt # data at tir_tiff_tiff_files
|
||||
#test: ./tir_od/test-dev2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794
|
||||
|
||||
# number of classes
|
||||
nc: 2
|
||||
|
||||
# class names
|
||||
names: ['car', 'person']
|
|
@ -0,0 +1,18 @@
|
|||
# COCO 2017 dataset http://cocodataset.org
|
||||
|
||||
# download command/URL (optional)
|
||||
#Make symbolic link
|
||||
# sudo ln -s ~hanoch/projects/tir_frames_rois /mnt/Data/hanoch/tir_frames_rois
|
||||
path: /mnt/Data/hanoch/tir_frames_rois/yolo7_tir_data_all #/home/hanoch/projects/tir_frames_rois/tir_car_44person_31 #/home/hanochk/tir_frames_rois/yolo7_tir_data
|
||||
# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
|
||||
train: ./yolov7/tir_od/train_set_merge_val/training_val_set.txt
|
||||
val: ./yolov7/tir_od/validation_set.txt #./yolov7/tir_od/tir_tiff_car_person_min_size_44_31_validation_set.txt #./yolov7/tir_od/validation_set.txt #./yolov7/tir_od/val_tir_od.txt #./yolov7/tir_od/validation_set.txt # 5000 images
|
||||
#test: ./tir_od/test-dev2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794
|
||||
|
||||
# number of classes
|
||||
nc: 2
|
||||
|
||||
# class names
|
||||
names: ['car', 'person']
|
||||
|
||||
|
6
test.py
6
test.py
|
@ -241,10 +241,10 @@ def test(data,
|
|||
if not training or 1:
|
||||
# assert len(pred[:, :4]) == 1
|
||||
x, y, w, h = xyxy2xywh(pred[:, :4])[0]
|
||||
if w * h > hyp['person_size_small_medium_th']:
|
||||
if w * h > hyp['person_size_small_medium_th'] and w * h <= hyp['car_size_small_medium_th']:
|
||||
stats_person_medium.append((correct.cpu(), pred[:, 4].cpu(), pred[:, 5].cpu(), tcls))
|
||||
if w * h > hyp['car_size_small_medium_th']:
|
||||
stats_all_large.append((correct.cpu(), pred[:, 4].cpu(), pred[:, 5].cpu(), tcls))
|
||||
if w * h > hyp['car_size_small_medium_th']:
|
||||
stats_all_large.append((correct.cpu(), pred[:, 4].cpu(), pred[:, 5].cpu(), tcls))
|
||||
|
||||
# Plot images aa = np.repeat(img[0,:,:,:].cpu().permute(1,2,0).numpy(), 3, axis=2).astype('float32') cv2.imwrite('test/exp40/test_batch88_labels__.jpg', aa*255)
|
||||
if plots and batch_i < 10 or 1:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
source /home/hanoch/.virtualenvs/tir_od/bin/activate
|
||||
cp -rp /home/hanoch/projects/tir_od/runs/train/* /mnt/Data/hanoch/runs/train/
|
||||
#cp -rp /home/hanoch/projects/tir_od/runs/train/* /mnt/Data/hanoch/runs/train/
|
||||
if [ -z $1 ] ; then
|
||||
python -u /home/hanoch/projects/tir_od/yolov7/tools/merge_results.py
|
||||
else
|
||||
|
|
11
train.py
11
train.py
|
@ -542,8 +542,15 @@ def train(hyp, opt, device, tb_writer=None):
|
|||
'%g/%g' % (epoch, epochs - 1), mem, *mloss, targets.shape[0], imgs.shape[-1])
|
||||
pbar.set_description(s)
|
||||
|
||||
# import tifffile
|
||||
# for ix, img in enumerate(imgs):
|
||||
# print(ix, torch.std(img), torch.quantile(img, 0.5))
|
||||
# tifffile.imwrite(os.path.join('/home/hanoch/projects/tir_od', 'img_scl_bef_mosaic' + str(ix)+'.tiff'),
|
||||
# img.cpu().numpy().transpose(1, 2, 0))
|
||||
#
|
||||
|
||||
# Plot
|
||||
if plots and ni < 10:
|
||||
if plots and ni < 100:
|
||||
f = save_dir / f'train_batch{ni}.jpg' # filename
|
||||
Thread(target=plot_images, args=(imgs, targets, paths, f, opt.input_channels), daemon=True).start()
|
||||
# if tb_writer:
|
||||
|
@ -939,6 +946,8 @@ FT : you need the --cfg of arch yaml because nc-classes are changing
|
|||
--workers 8 --device 0 --batch-size 16 --data data/tir_od.yaml --img 640 640 --weights ./yolov7/yolov7-tiny.pt --cfg cfg/training/yolov7-tiny.yaml --name yolov7 --hyp hyp.tir_od.tiny_aug.yaml --adam --norm-type single_image_mean_std --input-channels 3 --linear-lr --epochs 2
|
||||
|
||||
|
||||
--workers 8 --device 0 --batch-size 32 --data data/tir_od.yaml --img 640 640 --weights /mnt/Data/hanoch/tir_frames_rois/yolov7.pt --cfg cfg/training/yolov7.yaml --name yolov7 --hyp hyp.tir_od.tiny_aug_gamma_scaling_before_mosaic.yaml --adam --norm-type single_image_percentile_0_1 --input-channels 1 --linear-lr --epochs 100 --nosave --gamma-aug-prob 0.2 --cache-images
|
||||
|
||||
class EMA_Clip(EMA):
|
||||
#Exponential moving average
|
||||
def _init_(self, mu, avg_factor=5):
|
||||
|
|
|
@ -118,10 +118,9 @@ def create_dataloader(path, imgsz, batch_size, stride, opt, hyp=None, augment=Fa
|
|||
rank=-1, world_size=1, workers=8, image_weights=False, quad=False, prefix='',rel_path_images='', num_cls=-1):
|
||||
# Make sure only the first process in DDP process the dataset first, and the following others can use the cache
|
||||
if augment:
|
||||
if opt.gamma_aug_prob > 0:
|
||||
hyp['gamma_liklihood'] = opt.gamma_aug_prob
|
||||
print("", 100 * '==')
|
||||
print('gamma_liklihood was overriden by optional value ', opt.gamma_aug_prob)
|
||||
hyp['gamma_liklihood'] = opt.gamma_aug_prob
|
||||
print("", 100 * '==')
|
||||
print('gamma_liklihood was overriden by optional value ', opt.gamma_aug_prob)
|
||||
|
||||
with torch_distributed_zero_first(rank):
|
||||
scaling_before_mosaic = bool(hyp.get('scaling_before_mosaic', False))
|
||||
|
@ -714,7 +713,8 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|||
|
||||
# Letterbox
|
||||
shape = self.batch_shapes[self.batch[index]] if self.rect else self.img_size # final letterboxed shape
|
||||
img, ratio, pad = letterbox(img, shape, color=(filling_value, filling_value, filling_value), auto=False, scaleup=self.augment)
|
||||
# img, ratio, pad = letterbox(img, shape, color=(img.mean(), img.mean(), img.mean()), auto=False, scaleup=self.augment)
|
||||
img, ratio, pad = letterbox(img, shape, auto=False, scaleup=self.augment)
|
||||
shapes = (h0, w0), ((h / h0, w / w0), pad) # for COCO mAP rescaling
|
||||
|
||||
labels = self.labels[index].copy()
|
||||
|
@ -749,7 +749,8 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|||
scale=hyp['scale'],
|
||||
shear=hyp['shear'],
|
||||
perspective=hyp['perspective'],
|
||||
filling_value=filling_value)
|
||||
filling_value=filling_value,
|
||||
is_fill_by_mean_img=self.is_tir_signal)
|
||||
|
||||
if random.random() < hyp['inversion']:
|
||||
img = inversion_aug(img)
|
||||
|
@ -836,6 +837,9 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|||
# if np.isnan(img).any():
|
||||
# print('img {} index : {} is nan fin'.format(self.img_files[index], index))
|
||||
# raise
|
||||
# import tifffile
|
||||
# tifffile.imwrite(os.path.join('/home/hanoch/projects/tir_od', 'img_before_last_scaling' + str(index) + '.tiff'),
|
||||
# img.transpose(1, 2, 0))
|
||||
img = np.ascontiguousarray(img)
|
||||
# print('\n 2nd', img.shape)
|
||||
return torch.from_numpy(img), labels_out, self.img_files[index], shapes
|
||||
|
@ -996,7 +1000,8 @@ def load_mosaic(self, index, filling_value):
|
|||
shear=self.hyp['shear'],
|
||||
perspective=self.hyp['perspective'],
|
||||
border=self.mosaic_border,
|
||||
filling_value=filling_value) # border to remove
|
||||
filling_value=filling_value,
|
||||
is_fill_by_mean_img=self.is_tir_signal) # border to remove
|
||||
|
||||
return img4, labels4
|
||||
|
||||
|
@ -1086,7 +1091,8 @@ def load_mosaic9(self, index, filling_value):
|
|||
shear=self.hyp['shear'],
|
||||
perspective=self.hyp['perspective'],
|
||||
border=self.mosaic_border,
|
||||
filling_value=filling_value) # border to remove
|
||||
filling_value=filling_value,
|
||||
is_fill_by_mean_img=self.is_tir_signal) # border to remove
|
||||
|
||||
return img9, labels9
|
||||
|
||||
|
@ -1274,7 +1280,7 @@ def letterbox(img, new_shape=(640, 640), color=(114, 114, 114), auto=True, scale
|
|||
|
||||
|
||||
def random_perspective(img, targets=(), segments=(), degrees=10, translate=.1, scale=.1, shear=10, perspective=0.0,
|
||||
border=(0, 0), filling_value=114):
|
||||
border=(0, 0), filling_value=114, is_fill_by_mean_img=False):
|
||||
# torchvision.transforms.RandomAffine(degrees=(-10, 10), translate=(.1, .1), scale=(.9, 1.1), shear=(-10, 10))
|
||||
# targets = [cls, xyxy]
|
||||
|
||||
|
@ -1312,6 +1318,8 @@ def random_perspective(img, targets=(), segments=(), degrees=10, translate=.1, s
|
|||
# Combined rotation matrix
|
||||
M = T @ S @ R @ P @ C # order of operations (right to left) is IMPORTANT
|
||||
if (border[0] != 0) or (border[1] != 0) or (M != np.eye(3)).any(): # image changed
|
||||
if is_fill_by_mean_img:
|
||||
filling_value = int(img.mean()+1) # filling value can be only an integer hance when scaling before mosaic signal is [0,1] then in the random perspective the posibilities for filling values are 0 or 1
|
||||
if perspective:
|
||||
img = cv2.warpPerspective(img, M, dsize=(width, height), borderValue=(filling_value, filling_value, filling_value))
|
||||
else: # affine
|
||||
|
|
Loading…
Reference in New Issue