From 37cbe89ef060c4b9789617b3e539a4c58a56d457 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 28 Apr 2020 13:45:27 -0700 Subject: [PATCH] test/train jpg for png --- test.py | 4 ++-- train.py | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/test.py b/test.py index a4e1ce81..b79f1d1a 100644 --- a/test.py +++ b/test.py @@ -26,7 +26,7 @@ def test(cfg, verbose = opt.task == 'test' # Remove previous - for f in glob.glob('test_batch*.png'): + for f in glob.glob('test_batch*.jpg'): os.remove(f) # Initialize model @@ -83,7 +83,7 @@ def test(cfg, whwh = torch.Tensor([width, height, width, height]).to(device) # Plot images with bounding boxes - f = 'test_batch%g.png' % batch_i # filename + f = 'test_batch%g.jpg' % batch_i # filename if batch_i < 1 and not os.path.exists(f): plot_images(imgs=imgs, targets=targets, paths=paths, fname=f) diff --git a/train.py b/train.py index d32f59e0..ddd66588 100644 --- a/train.py +++ b/train.py @@ -53,6 +53,7 @@ if f: if hyp['fl_gamma']: print('Using FocalLoss(gamma=%g)' % hyp['fl_gamma']) + def train(): cfg = opt.cfg data = opt.data @@ -83,7 +84,7 @@ def train(): hyp['cls'] *= nc / 80 # update coco-tuned hyp['cls'] to current dataset # Remove previous results - for f in glob.glob('*_batch*.png') + glob.glob(results_file): + for f in glob.glob('*_batch*.jpg') + glob.glob(results_file): os.remove(f) # Initialize model @@ -149,7 +150,7 @@ def train(): # Scheduler https://arxiv.org/pdf/1812.01187.pdf lf = lambda x: (((1 + math.cos(x * math.pi / epochs)) / 2) ** 1.0) * 0.95 + 0.05 # cosine scheduler = lr_scheduler.LambdaLR(optimizer, lr_lambda=lf) - scheduler.last_epoch=start_epoch - 1 # see link below + scheduler.last_epoch = start_epoch - 1 # see link below # https://discuss.pytorch.org/t/a-problem-occured-when-resuming-an-optimizer/28822 # Plot lr schedule @@ -289,7 +290,7 @@ def train(): # Plot if ni < 1: - f = 'train_batch%g.png' % i # filename + f = 'train_batch%g.jpg' % i # filename plot_images(imgs=imgs, targets=targets, paths=paths, fname=f) if tb_writer: tb_writer.add_image(f, cv2.imread(f)[:, :, ::-1], dataformats='HWC') @@ -388,7 +389,8 @@ if __name__ == '__main__': parser.add_argument('--cfg', type=str, default='cfg/yolov3-spp.cfg', help='*.cfg path') parser.add_argument('--data', type=str, default='data/coco2017.data', help='*.data path') parser.add_argument('--multi-scale', action='store_true', help='adjust (67%% - 150%%) img_size every 10 batches') - parser.add_argument('--img-size', nargs='+', type=int, default=[320, 640], help='[min_train, max-train, test] img sizes') + parser.add_argument('--img-size', nargs='+', type=int, default=[320, 640], + help='[min_train, max-train, test] img sizes') parser.add_argument('--rect', action='store_true', help='rectangular training') parser.add_argument('--resume', action='store_true', help='resume training from last.pt') parser.add_argument('--nosave', action='store_true', help='only save final checkpoint')