From c0a4c3458f285eaa2e4a345dfe4fb1c061e11128 Mon Sep 17 00:00:00 2001 From: Noah <595311942@qq.com> Date: Sat, 12 Mar 2022 17:29:28 +0800 Subject: [PATCH] fix remove rearrange_OUMVLP & pretreatment bug --- misc/pretreatment.py | 11 ++++++----- misc/rearrange_OUMVLP.py | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/misc/pretreatment.py b/misc/pretreatment.py index 94bb803..15bcbf2 100644 --- a/misc/pretreatment.py +++ b/misc/pretreatment.py @@ -46,8 +46,8 @@ def imgs2pickle(img_groups: Tuple, output_path: Path, img_size: int = 64, verbos # As the height of a person is larger than the width, # use the height to calculate resize ratio. - ratio = img.shape[1] // img.shape[0] - img = cv2.resize(img, (img_size * ratio, img_size), interpolation=cv2.INTER_CUBIC) + ratio = img.shape[1] / img.shape[0] + img = cv2.resize(img, (int(img_size * ratio), img_size), interpolation=cv2.INTER_CUBIC) # Get the median of the x-axis and take it as the person's x-center. x_csum = img.sum(axis=0).cumsum() @@ -81,11 +81,12 @@ def imgs2pickle(img_groups: Tuple, output_path: Path, img_size: int = 64, verbos if verbose: logging.debug(f'Saving {pkl_path}...') pickle.dump(to_pickle, open(pkl_path, 'wb')) + logging.info(f'Saved {len(to_pickle)} valid frames to {pkl_path}.') + if len(to_pickle) < 5: logging.warning(f'{sinfo} has less than 5 valid data.') - logging.info(f'Saved {len(to_pickle)} valid frames to {pkl_path}.') def pretreat(input_path: Path, output_path: Path, img_size: int = 64, workers: int = 4, verbose: bool = False) -> None: @@ -121,7 +122,7 @@ def pretreat(input_path: Path, output_path: Path, img_size: int = 64, workers: i if __name__ == '__main__': parser = argparse.ArgumentParser(description='OpenGait dataset pretreatment module.') - parser.add_argument('-r', '--root_path', default='', type=str, help='Root path of raw dataset.') + parser.add_argument('-r', '--input_path', default='', type=str, help='Root path of raw dataset.') parser.add_argument('-o', '--output_path', default='', type=str, help='Output path of pickled dataset.') parser.add_argument('-l', '--log_file', default='./pretreatment.log', type=str, help='Log file path. Default: ./pretreatment.log') parser.add_argument('-n', '--n_workers', default=4, type=int, help='Number of thread workers. Default: 4') @@ -137,4 +138,4 @@ if __name__ == '__main__': for k, v in args.__dict__.items(): logging.debug(f'{k}: {v}') - pretreat(Path(args.root_path), Path(args.output_path), args.n_workers, args.img_size, args.verbose) + pretreat(input_path=Path(args.root_path), output_path=Path(args.output_path), img_size=args.img_size, workers=args.n_workers, verbose=args.verbose) diff --git a/misc/rearrange_OUMVLP.py b/misc/rearrange_OUMVLP.py index 45eb33f..d9ba412 100644 --- a/misc/rearrange_OUMVLP.py +++ b/misc/rearrange_OUMVLP.py @@ -25,11 +25,11 @@ def rearrange(input_path: Path, output_path: Path) -> None: dst = os.path.join(output_path, sid.name, seq, view) os.makedirs(dst, exist_ok=True) for subfile in os.listdir(src): - if subfile.endswith('.png'): + if subfile not in os.listdir(dst) and subfile.endswith('.png'): os.symlink(os.path.join(src, subfile), os.path.join(dst, subfile)) - else: - os.remove(os.path.join(src, subfile)) + # else: + # os.remove(os.path.join(src, subfile)) progress.update(1)