Update main.py
Browse files
main.py
CHANGED
|
@@ -79,11 +79,12 @@ def download_openi(datasets):
|
|
| 79 |
"""
|
| 80 |
下载多个数据集到不同目录,如果保存路径不存在则不下载,如果配置文件中已存在则不下载
|
| 81 |
"""
|
| 82 |
-
for dataset in
|
| 83 |
dataset_name = dataset["dataset_name"]
|
| 84 |
file_name = dataset["file_name"]
|
| 85 |
save_path = os.path.join(".", dataset["save_path"])
|
| 86 |
|
|
|
|
| 87 |
if not os.path.exists(save_path):
|
| 88 |
print(f"保存路径 {save_path} 不存在,跳过下载 {file_name}。")
|
| 89 |
continue
|
|
@@ -93,17 +94,22 @@ def download_openi(datasets):
|
|
| 93 |
config.read(os.path.join(save_path, 'time.ini'))
|
| 94 |
|
| 95 |
# 检查 time.ini 配置文件中是否已存在该文件
|
| 96 |
-
if config.has_option(
|
| 97 |
print(f"配置文件中已存在 {file_name},跳过下载。")
|
| 98 |
continue
|
| 99 |
|
|
|
|
| 100 |
os.system(f'openi dataset download {dataset_name} {file_name} --cluster NPU --save_path {save_path}')
|
| 101 |
print(f"数据集 {file_name} 已下载到 {save_path} 目录。")
|
| 102 |
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
| 104 |
with open(os.path.join(save_path, 'time.ini'), 'w') as configfile:
|
| 105 |
config.write(configfile)
|
| 106 |
|
|
|
|
| 107 |
extract_path = os.path.join(save_path, os.path.splitext(file_name)[0])
|
| 108 |
if not os.path.exists(extract_path):
|
| 109 |
os.makedirs(extract_path)
|
|
|
|
| 79 |
"""
|
| 80 |
下载多个数据集到不同目录,如果保存路径不存在则不下载,如果配置文件中已存在则不下载
|
| 81 |
"""
|
| 82 |
+
for dataset in openi_datasets:
|
| 83 |
dataset_name = dataset["dataset_name"]
|
| 84 |
file_name = dataset["file_name"]
|
| 85 |
save_path = os.path.join(".", dataset["save_path"])
|
| 86 |
|
| 87 |
+
# 检查保存路径是否存在
|
| 88 |
if not os.path.exists(save_path):
|
| 89 |
print(f"保存路径 {save_path} 不存在,跳过下载 {file_name}。")
|
| 90 |
continue
|
|
|
|
| 94 |
config.read(os.path.join(save_path, 'time.ini'))
|
| 95 |
|
| 96 |
# 检查 time.ini 配置文件中是否已存在该文件
|
| 97 |
+
if config.has_option('downloaded_files', file_name):
|
| 98 |
print(f"配置文件中已存在 {file_name},跳过下载。")
|
| 99 |
continue
|
| 100 |
|
| 101 |
+
# 下载数据集
|
| 102 |
os.system(f'openi dataset download {dataset_name} {file_name} --cluster NPU --save_path {save_path}')
|
| 103 |
print(f"数据集 {file_name} 已下载到 {save_path} 目录。")
|
| 104 |
|
| 105 |
+
# 更新对应数据集的 time.ini 配置文件
|
| 106 |
+
if not config.has_section('downloaded_files'):
|
| 107 |
+
config.add_section('downloaded_files')
|
| 108 |
+
config.set('downloaded_files', file_name, 'True')
|
| 109 |
with open(os.path.join(save_path, 'time.ini'), 'w') as configfile:
|
| 110 |
config.write(configfile)
|
| 111 |
|
| 112 |
+
# 解压文件
|
| 113 |
extract_path = os.path.join(save_path, os.path.splitext(file_name)[0])
|
| 114 |
if not os.path.exists(extract_path):
|
| 115 |
os.makedirs(extract_path)
|