-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprepare_data.py
50 lines (45 loc) · 2.21 KB
/
prepare_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from gsdp.utils.dump_tools import make_path_exists
import os
import wget
# init -----------------------------------------------------------------------------
_CUSTOM_MODELS = ['MNIST']
_KERAS_MODELS = ['VGG16', 'ResNet50']
prototypes_relative_path = '/data/*.h5'
models_relative_path = '/model/*.json'
weights_relative_path = '/model/*.h5'
current_dir2 = os.path.dirname(os.path.realpath(__file__))
url_datasets = "https://www.verlab.dcc.ufmg.br/gsdp/"
# local procedures -------------------------------------------------------------------
def download_gsdp_data():
_models = _CUSTOM_MODELS + _KERAS_MODELS
models_path_name = 'models'
for model in _models:
print('\n'+ '#'*12 + ' Downloading data for Keras-' + model + ' pre-trained model ' + '#'*50)
prototypes_filename = os.path.join(models_path_name,model,'data','prototypes.h5')
output_dir = os.path.join(models_path_name,model,'data')
make_path_exists(output_dir)
prototypes_url = url_datasets + prototypes_filename
print('\n ---> Downloading computed prototypes from: ' + prototypes_url+ ')')
wget.download(prototypes_url, out=output_dir)
if model in _CUSTOM_MODELS:
print('\n ---> Downloading custom model files:')
for file in ['model.json','weights.h5']:
model_filename = os.path.join(models_path_name, model, 'model',file )
output_dir = os.path.join(models_path_name, model, 'model')
make_path_exists(output_dir)
file_url = url_datasets + model_filename
print('\n -> Downloading Keras-' + model+ ' ' + file + ' from: ' + file_url + ')')
wget.download(file_url, out=output_dir)
def models_resources():
_models = _CUSTOM_MODELS + _KERAS_MODELS
resources = []
for model in _models:
resources.append(model + prototypes_relative_path)
if model in _CUSTOM_MODELS:
resources.append(model + models_relative_path)
resources.append(model + weights_relative_path)
return resources
# MAIN
if __name__ == "__main__":
# download prototypes and models weights
download_gsdp_data()