From cfd888b88018eb30de1e1ef88b75875cde87bf07 Mon Sep 17 00:00:00 2001 From: liuzx Date: Wed, 12 Jul 2023 15:45:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'openi.py'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openi.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/openi.py b/openi.py index 476f92d..34d8313 100644 --- a/openi.py +++ b/openi.py @@ -81,6 +81,29 @@ def obs_copy_folder(folder_dir, obs_folder_url): print('moxing upload {} to {} failed: '.format(folder_dir,obs_folder_url) + str(e)) return +# def c2net_multidataset_to_env(multi_data_url, data_dir): +# """ +# c2net copy single or multi dataset to training image +# """ +# multi_data_json = json.loads(multi_data_url) +# for i in range(len(multi_data_json)): +# zipfile_path = data_dir + "/" + multi_data_json[i]["dataset_name"] +# try: +# mox.file.copy(multi_data_json[i]["dataset_url"], zipfile_path) +# print("Successfully Download {} to {}".format(multi_data_json[i]["dataset_url"],zipfile_path)) +# #get filename and unzip the dataset +# filename = os.path.splitext(multi_data_json[i]["dataset_name"])[0] +# filePath = data_dir + "/" + filename +# if not os.path.exists(filePath): +# os.makedirs(filePath) +# #If it is a tar compressed package, you can use os.system("tar -xvf {} {}".format(zipfile_path, filePath)) +# os.system("unzip {} -d {}".format(zipfile_path, filePath)) + +# except Exception as e: +# print('moxing download {} to {} failed: '.format( +# multi_data_json[i]["dataset_url"], zipfile_path) + str(e)) +# return + def c2net_multidataset_to_env(multi_data_url, data_dir): """ c2net copy single or multi dataset to training image @@ -96,13 +119,17 @@ def c2net_multidataset_to_env(multi_data_url, data_dir): filePath = data_dir + "/" + filename if not os.path.exists(filePath): os.makedirs(filePath) - #If it is a tar compressed package, you can use os.system("tar -xvf {} {}".format(zipfile_path, filePath)) - os.system("unzip {} -d {}".format(zipfile_path, filePath)) + if zipfile_path.endswith(".tar.gz"): + os.system("tar -zxvf {} -C {}".format(zipfile_path, filePath)) + elif zipfile_path.endswith(".zip"): + os.system("unzip {} -d {}".format(zipfile_path, filePath)) + else: + print("The dataset is not in tar.gz or zip format!") except Exception as e: print('moxing download {} to {} failed: '.format( multi_data_json[i]["dataset_url"], zipfile_path) + str(e)) - return + return class EnvToOpenIEpochEnd(Callback):