From 400250ed857b3aad85584fdcaf5c1709187c997a Mon Sep 17 00:00:00 2001 From: haoyuying <35907364+haoyuying@users.noreply.github.com> Date: Mon, 30 Nov 2020 14:47:14 +0800 Subject: [PATCH] fix download dataset issue --- demo/image_classification/predict.py | 2 +- paddlehub/utils/download.py | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/demo/image_classification/predict.py b/demo/image_classification/predict.py index 9823b7bd..11fc4e09 100644 --- a/demo/image_classification/predict.py +++ b/demo/image_classification/predict.py @@ -5,5 +5,5 @@ if __name__ == '__main__': model = hub.Module( name='resnet50_vd_imagenet_ssld', label_list=["roses", "tulips", "daisy", "sunflowers", "dandelion"], - oad_checkpoint='/PATH/TO/CHECKPOINT') + load_checkpoint='/PATH/TO/CHECKPOINT') result = model.predict(['flower.jpg']) diff --git a/paddlehub/utils/download.py b/paddlehub/utils/download.py index 164f05d4..5f80e41f 100644 --- a/paddlehub/utils/download.py +++ b/paddlehub/utils/download.py @@ -15,20 +15,27 @@ import os +import filelock + import paddlehub.env as hubenv from paddle.utils.download import get_path_from_url from paddlehub.utils import log, utils, xarfile def download_data(url): - save_name = os.path.basename(url).split('.')[0] - output_path = os.path.join(hubenv.DATA_HOME, save_name) - - if not os.path.exists(output_path): - get_path_from_url(url, hubenv.DATA_HOME) def _wrapper(Dataset): - return Dataset + + def _download_dataset_from_url(*args, **kwargs): + save_name = os.path.basename(url).split('.')[0] + output_path = os.path.join(hubenv.DATA_HOME, save_name) + lock = filelock.FileLock(os.path.join(hubenv.TMP_HOME, save_name)) + with lock: + if not os.path.exists(output_path): + default_downloader.download_file_and_uncompress(url, hubenv.DATA_HOME, True) + + return Dataset(*args, **kwargs) + return _download_dataset_from_url return _wrapper -- GitLab