From 4f7fee45ff03d9e53a4b8e5b1c39e265a8ba68ea Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 21 Jun 2019 21:27:50 +0200 Subject: [PATCH] updates --- train.py | 2 +- utils/datasets.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/train.py b/train.py index ace3a567..666da626 100644 --- a/train.py +++ b/train.py @@ -315,7 +315,7 @@ if __name__ == '__main__': parser.add_argument('--batch-size', type=int, default=8, help='batch size') parser.add_argument('--accumulate', type=int, default=8, help='number of batches to accumulate before optimizing') parser.add_argument('--cfg', type=str, default='cfg/yolov3-spp.cfg', help='cfg file path') - parser.add_argument('--data-cfg', type=str, default='data/coco.data', help='coco.data file path') + parser.add_argument('--data-cfg', type=str, default='data/coco_64img.data', help='coco.data file path') parser.add_argument('--single-scale', action='store_true', help='train at fixed size (no multi-scale)') parser.add_argument('--img-size', type=int, default=416, help='inference size (pixels)') parser.add_argument('--resume', action='store_true', help='resume training flag') diff --git a/utils/datasets.py b/utils/datasets.py index e0221c32..e28c6da5 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -266,10 +266,10 @@ class LoadImagesAndLabels(Dataset): # for training/testing h, w, _ = img.shape if self.rect: shape = self.batch_shapes[self.batch[index]] - img, ratio, padw, padh = letterbox(img, new_shape=shape, mode='rect') + img, ratiow, ratioh, padw, padh = letterbox(img, new_shape=shape, mode='rect') else: shape = self.img_size - img, ratio, padw, padh = letterbox(img, new_shape=shape, mode='square') + img, ratiow, ratioh, padw, padh = letterbox(img, new_shape=shape, mode='scaleFill') # Load labels labels = [] @@ -280,10 +280,10 @@ class LoadImagesAndLabels(Dataset): # for training/testing if x.size > 0: # Normalized xywh to pixel xyxy format labels = x.copy() - labels[:, 1] = ratio * w * (x[:, 1] - x[:, 3] / 2) + padw - labels[:, 2] = ratio * h * (x[:, 2] - x[:, 4] / 2) + padh - labels[:, 3] = ratio * w * (x[:, 1] + x[:, 3] / 2) + padw - labels[:, 4] = ratio * h * (x[:, 2] + x[:, 4] / 2) + padh + labels[:, 1] = ratiow * w * (x[:, 1] - x[:, 3] / 2) + padw + labels[:, 2] = ratioh * h * (x[:, 2] - x[:, 4] / 2) + padh + labels[:, 3] = ratiow * w * (x[:, 1] + x[:, 3] / 2) + padw + labels[:, 4] = ratioh * h * (x[:, 2] + x[:, 4] / 2) + padh # Augment image and labels if self.augment: @@ -340,6 +340,7 @@ def letterbox(img, new_shape=416, color=(127.5, 127.5, 127.5), mode='auto'): ratio = float(new_shape) / max(shape) else: ratio = max(new_shape) / max(shape) # ratio = new / old + ratiow, ratioh = ratio, ratio new_unpad = (int(round(shape[1] * ratio)), int(round(shape[0] * ratio))) # Compute padding https://github.com/ultralytics/yolov3/issues/232 @@ -352,12 +353,16 @@ def letterbox(img, new_shape=416, color=(127.5, 127.5, 127.5), mode='auto'): elif mode is 'rect': # square dw = (new_shape[1] - new_unpad[0]) / 2 # width padding dh = (new_shape[0] - new_unpad[1]) / 2 # height padding + elif mode is 'scaleFill': + dw, dh = 0.0, 0.0 + new_unpad = (new_shape, new_shape) + ratiow, ratioh = new_shape/shape[1], new_shape/shape[0] top, bottom = int(round(dh - 0.1)), int(round(dh + 0.1)) left, right = int(round(dw - 0.1)), int(round(dw + 0.1)) img = cv2.resize(img, new_unpad, interpolation=cv2.INTER_LINEAR) # resized, no border img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color) # padded square - return img, ratio, dw, dh + return img, ratiow, ratioh, dw, dh def random_affine(img, targets=(), degrees=(-10, 10), translate=(.1, .1), scale=(.9, 1.1), shear=(-2, 2),