From f49ec1d7df259d7498be1b636fdfac17a175af80 Mon Sep 17 00:00:00 2001 From: Kaipeng Deng Date: Thu, 21 Mar 2019 10:39:26 +0800 Subject: [PATCH] Fix process exit error and shuffle gt error (#1911) * fix shuffle gt bug. * fix process exit bug. --- fluid/PaddleCV/yolov3/data_utils.py | 2 +- fluid/PaddleCV/yolov3/image_utils.py | 2 +- fluid/PaddleCV/yolov3/models/yolov3.py | 1 - fluid/PaddleCV/yolov3/reader.py | 10 ++++++++-- fluid/PaddleCV/yolov3/train.py | 5 +++-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/fluid/PaddleCV/yolov3/data_utils.py b/fluid/PaddleCV/yolov3/data_utils.py index ac022593..c43e040a 100644 --- a/fluid/PaddleCV/yolov3/data_utils.py +++ b/fluid/PaddleCV/yolov3/data_utils.py @@ -124,7 +124,7 @@ class GeneratorEnqueuer(object): for thread in self._threads: if self._use_multiprocessing: if thread.is_alive(): - thread.terminate() + thread.join(timeout) else: thread.join(timeout) if self._manager: diff --git a/fluid/PaddleCV/yolov3/image_utils.py b/fluid/PaddleCV/yolov3/image_utils.py index 6933721e..a35e20be 100644 --- a/fluid/PaddleCV/yolov3/image_utils.py +++ b/fluid/PaddleCV/yolov3/image_utils.py @@ -154,7 +154,7 @@ def random_expand(img, gtboxes, max_ratio=4., fill=None, keep_ratio=True, thresh def shuffle_gtbox(gtbox, gtlabel, gtscore): gt = np.concatenate([gtbox, gtlabel[:, np.newaxis], gtscore[:, np.newaxis]], axis=1) - idx = np.arange(gt.shape[1]) + idx = np.arange(gt.shape[0]) np.random.shuffle(idx) gt = gt[idx, :] return gt[:, :4], gt[:, 4], gt[:, 5] diff --git a/fluid/PaddleCV/yolov3/models/yolov3.py b/fluid/PaddleCV/yolov3/models/yolov3.py index b28c14bd..9ea4ef44 100644 --- a/fluid/PaddleCV/yolov3/models/yolov3.py +++ b/fluid/PaddleCV/yolov3/models/yolov3.py @@ -134,7 +134,6 @@ class YOLOv3(object): anchor_mask = cfg.anchor_masks[i] if self.is_train: - ignore_thresh = float(self.ignore_thresh) loss = fluid.layers.yolov3_loss( x=out, gtbox=self.gtbox, diff --git a/fluid/PaddleCV/yolov3/reader.py b/fluid/PaddleCV/yolov3/reader.py index 5d37402d..1f3ce354 100644 --- a/fluid/PaddleCV/yolov3/reader.py +++ b/fluid/PaddleCV/yolov3/reader.py @@ -250,10 +250,11 @@ dsr = DataSetReader() def train(size=416, batch_size=64, shuffle=True, + total_iter=0, mixup_iter=0, random_sizes=[], - num_workers=12, - max_queue=36, + num_workers=8, + max_queue=32, use_multiprocessing=True): generator = dsr.get_reader('train', size, batch_size, shuffle, int(mixup_iter/num_workers), random_sizes) @@ -266,6 +267,7 @@ def train(size=416, yield data def reader(): + cnt = 0 try: enqueuer = GeneratorEnqueuer( infinite_reader(), use_multiprocessing=use_multiprocessing) @@ -279,6 +281,10 @@ def train(size=416, else: time.sleep(0.02) yield generator_out + cnt += 1 + if cnt >= total_iter: + enqueuer.stop() + return generator_out = None finally: if enqueuer is not None: diff --git a/fluid/PaddleCV/yolov3/train.py b/fluid/PaddleCV/yolov3/train.py index f3ac6e3e..07f74a54 100644 --- a/fluid/PaddleCV/yolov3/train.py +++ b/fluid/PaddleCV/yolov3/train.py @@ -86,8 +86,9 @@ def train(): if cfg.random_shape: random_sizes = [32 * i for i in range(10, 20)] - mixup_iter = cfg.max_iter - cfg.start_iter - cfg.no_mixup_iter - train_reader = reader.train(input_size, batch_size=cfg.batch_size, shuffle=True, mixup_iter=mixup_iter*devices_num, random_sizes=random_sizes, use_multiprocessing=cfg.use_multiprocess) + total_iter = cfg.max_iter - cfg.start_iter + mixup_iter = total_iter - cfg.no_mixup_iter + train_reader = reader.train(input_size, batch_size=cfg.batch_size, shuffle=True, total_iter=total_iter*devices_num, mixup_iter=mixup_iter*devices_num, random_sizes=random_sizes, use_multiprocessing=cfg.use_multiprocess) py_reader = model.py_reader py_reader.decorate_paddle_reader(train_reader) -- GitLab