Skip to content

Commit 94e6d9d

Browse files
fix: download_unpack_cnn_models.py. 1. Change path to models. 2. Fix download issue
1 parent 45cc0cd commit 94e6d9d

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

archived_models/download_unpack_cnn_models.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def download_unpack_zip(zip_name, output_path, zip_path,
3838
Download and unpack one zip file
3939
"""
4040

41-
digit_match = re.search(r'\d.zip$', zip_name) # if we have multi archive
41+
digit_match = re.search(r'fcn\d.zip$', zip_name) # if we have multi archive
4242
if digit_match:
4343
name = zip_name[:-5] # cut last character with number
4444
else:
@@ -54,7 +54,7 @@ def download_unpack_zip(zip_name, output_path, zip_path,
5454
else:
5555
print("[INFO] Skip downloading {}. Model already exists here {}".
5656
format(zip_name, model_out_folder))
57-
return False
57+
return True
5858

5959
file_name_url = git_hub_repo_url + '/' + zip_name
6060
file_name_zip = zip_path / zip_name
@@ -65,13 +65,24 @@ def download_unpack_zip(zip_name, output_path, zip_path,
6565
print(" [ERROR]. Can not access to Zip file by address {}".
6666
format(file_name_url))
6767
return False
68+
try:
69+
with requests.get(file_name_url, stream=True) as r_zip_file:
70+
with open(file_name_zip, 'wb') as f_download:
71+
shutil.copyfileobj(r_zip_file.raw, f_download)
72+
except Exception as error:
73+
print(" [ERROR]. Can not download to file by address {}"
74+
" Reason: {}".
75+
format(file_name_url, error))
76+
return False
6877

69-
with requests.get(file_name_url, stream=True) as r_zip_file:
70-
with open(file_name_zip, 'wb') as f_download:
71-
shutil.copyfileobj(r_zip_file.raw, f_download)
72-
73-
with zipfile.ZipFile(file_name_zip, 'r') as zip_ref:
74-
zip_ref.extractall(output_path)
78+
try:
79+
with zipfile.ZipFile(file_name_zip, 'r') as zip_ref:
80+
zip_ref.extractall(output_path)
81+
except Exception as error:
82+
print(" [ERROR]. Can not unpack {}"
83+
" Reason: {}".
84+
format(file_name_zip, error))
85+
return False
7586

7687
print("[INFO] {} is downloaded and unpacked"
7788
.format(zip_name))
@@ -94,8 +105,7 @@ def arg2bool(bool_arg):
94105

95106

96107
def main():
97-
git_hub_repo_url = 'https://github.com/foss-for-synopsys-dwc-arc-processors/synopsys-caffe-models/raw/master/caffe_models_zipped'
98-
108+
git_hub_repo_url = 'https://github.com/foss-for-synopsys-dwc-arc-processors/synopsys-caffe-models/raw/master/archived_models/models'
99109
parser = argparse.ArgumentParser()
100110

101111
parser.add_argument(
@@ -166,10 +176,10 @@ def main():
166176
zip_path = output_path/"download" # folder for downloaded zip files
167177
try:
168178
zip_path.mkdir(parents=True, exist_ok=True)
169-
except:
179+
except Exception as error:
170180
print(
171181
"[ERROR]. Problem of creating folder to download zipped CNN Models:"
172-
" {}".format(zip_path))
182+
" Reason {}".format(zip_path, error))
173183
exit(1)
174184

175185
print("[INFO] NN Models path is {}".format(output_path))

0 commit comments

Comments
 (0)