Skip to content

Commit 6047dc2

Browse files
authored
Update new scheme for garnet support (example data and config files) (#5)
* update for new example scheme (data and config) * new file to probe data and configuration example availability
1 parent c963325 commit 6047dc2

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# Contribution guidelines
22

3-
- When you add a `keras` model, please save the architecture and weights in `.json` and `.h5` files
3+
- When you add a `keras` model, please save the architecture and weights in `<model-name>.json` and `<model-name>_weights.h5` files.
4+
5+
- If you have example **data** you want to add, please save them in `data/` with names `<model-name>_input.*` and `<model-name>_output.*`. Where `*` can either be `npy` or `dat`.
6+
7+
- If you have example **configuration** you want to add, please save them in `config-files/` with names `<model-name>_config.yml`

available_data_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"KERAS_dense_16x500x500x500x500x500x5.json": {"example_data": false, "example_config": false}, "KERAS_3layer.json": {"example_data": false, "example_config": false}, "KERAS_3layer_batch_norm.json": {"example_data": false, "example_config": false}, "KERAS_dense_16x100x100x100x100x100x5.json": {"example_data": false, "example_config": false}, "garnet_3layer.json": {"example_data": false, "example_config": true}, "jetTagger_Conv2D_Small_NoBatchNorm.json": {"example_data": false, "example_config": false}, "KERAS_dense_16x200x200x200x200x200x5.json": {"example_data": false, "example_config": false}, "jetTagger_Conv2D_Small.json": {"example_data": false, "example_config": false}, "KERAS_3layer_binarydense_relu_max.json": {"example_data": false, "example_config": false}, "KERAS_conv1d_small.json": {"example_data": false, "example_config": false}, "KERAS_3layer_ternary_small.json": {"example_data": false, "example_config": false}, "KERAS_1layer.json": {"example_data": false, "example_config": false}, "KERAS_conv1d.json": {"example_data": false, "example_config": false}, "qkeras_3layer.json": {"example_data": false, "example_config": false}, "KERAS_3layer_binary_smaller.json": {"example_data": false, "example_config": false}, "keras_bnn.json": {"example_data": false, "example_config": false}, "KERAS_conv2d_model.json": {"example_data": false, "example_config": false}, "garnet_1layer.json": {"example_data": true, "example_config": true}, "two_layer_model.pt": {"example_data": false, "example_config": false}, "three_layer_model.pt": {"example_data": false, "example_config": false}, "two_layer_pytorch.onnx": {"example_data": false, "example_config": false}, "three_layer_pytorch.onnx": {"example_data": false, "example_config": false}, "three_layer_keras.onnx": {"example_data": false, "example_config": false}, "conv2d_small_mp_keras.onnx": {"example_data": false, "example_config": false}, "two_layer_keras.onnx": {"example_data": false, "example_config": false}, "conv1d_small_keras.onnx": {"example_data": false, "example_config": false}, "three_layer_bn_pytorch.onnx": {"example_data": false, "example_config": false}, "dense_big_keras.onnx": {"example_data": false, "example_config": false}, "conv2d_small_keras.onnx": {"example_data": false, "example_config": false}, "three_layer_bn_keras.onnx": {"example_data": false, "example_config": false}, "3layer.pb": {"example_data": false, "example_config": false}}

available_models.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"onnx": ["dense_big_keras.onnx", "conv2d_small_mp_keras.onnx", "two_layer_pytorch.onnx", "two_layer_keras.onnx", "three_layer_bn_keras.onnx", "conv1d_small_keras.onnx", "three_layer_pytorch.onnx", "three_layer_bn_pytorch.onnx", "three_layer_keras.onnx", "conv2d_small_keras.onnx"], "pytorch": ["two_layer_model.pt", "three_layer_model.pt"], "tensorflow": ["3layer.pb"], "keras": ["KERAS_3layer.json", "KERAS_dense_16x500x500x500x500x500x5.json", "KERAS_conv1d_small.json", "jetTagger_Conv2D_Small.json", "KERAS_3layer_ternary_small.json", "qkeras_3layer.json", "KERAS_dense_16x200x200x200x200x200x5.json", "keras_bnn.json", "garnet_1layer.json", "jetTagger_Conv2D_Small_NoBatchNorm.json", "garnet_3layer.json", "KERAS_3layer_binary_smaller.json", "KERAS_3layer_binarydense_relu_max.json", "KERAS_conv2d_model.json", "KERAS_dense_16x100x100x100x100x100x5.json", "KERAS_3layer_batch_norm.json", "KERAS_1layer.json", "KERAS_conv1d.json"]}
1+
{"keras": ["KERAS_dense_16x500x500x500x500x500x5.json", "KERAS_3layer.json", "KERAS_3layer_batch_norm.json", "KERAS_dense_16x100x100x100x100x100x5.json", "garnet_3layer.json", "jetTagger_Conv2D_Small_NoBatchNorm.json", "KERAS_dense_16x200x200x200x200x200x5.json", "jetTagger_Conv2D_Small.json", "KERAS_3layer_binarydense_relu_max.json", "KERAS_conv1d_small.json", "KERAS_3layer_ternary_small.json", "KERAS_1layer.json", "KERAS_conv1d.json", "qkeras_3layer.json", "KERAS_3layer_binary_smaller.json", "keras_bnn.json", "KERAS_conv2d_model.json", "garnet_1layer.json"], "pytorch": ["two_layer_model.pt", "three_layer_model.pt"], "onnx": ["two_layer_pytorch.onnx", "three_layer_pytorch.onnx", "three_layer_keras.onnx", "conv2d_small_mp_keras.onnx", "two_layer_keras.onnx", "conv1d_small_keras.onnx", "three_layer_bn_pytorch.onnx", "dense_big_keras.onnx", "conv2d_small_keras.onnx", "three_layer_bn_keras.onnx"], "tensorflow": ["3layer.pb"]}

scan.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,83 @@
11
import os
22
import json
33

4+
5+
def scan_data_config(model_name):
6+
"""
7+
Take a model name and return a dictionary of whether the associated data and configuration files
8+
are available for that model or not.
9+
"""
10+
11+
available_data_config = {
12+
'example_data': False,
13+
'example_config': False}
14+
15+
#Check data availability
16+
for filename in os.listdir("./data/"):
17+
if filename.startswith(model_name):
18+
available_data_config['example_data'] = True
19+
20+
#Check config file availability
21+
for filename in os.listdir("./config-files/"):
22+
if filename.startswith(model_name):
23+
available_data_config['example_config'] = True
24+
25+
return available_data_config
26+
27+
428
def scan_subdir(model_type):
5-
"""Scan a directory and return a list of example models."""
29+
"""Scan a directory and return a list of example models, and a dictionary indicating
30+
whether each model has associated example data and example config file or not."""
631

732
#Create the path to the sub directory
833
dir_path = model_type + "/"
934

1035
#List of available models
1136
available_models = []
37+
38+
#Dictionary to save data's and config's availability
39+
data_config_avai = {}
1240

1341
for filename in os.listdir(dir_path):
1442

1543
if model_type == 'keras':
1644
if filename.endswith('.json'):
1745
available_models.append(filename)
46+
data_config_avai[filename] = scan_data_config(filename[:-5])
1847
elif model_type == 'pytorch':
1948
if filename.endswith('.pt'):
2049
available_models.append(filename)
50+
data_config_avai[filename] = scan_data_config(filename[:-3])
2151
elif model_type == 'tensorflow':
2252
if filename.endswith('.pb'):
2353
available_models.append(filename)
54+
data_config_avai[filename] = scan_data_config(filename[:-3])
2455
elif model_type == 'onnx':
2556
if filename.endswith('.onnx'):
2657
available_models.append(filename)
58+
data_config_avai[filename] = scan_data_config(filename[:-5])
2759

28-
return available_models
60+
return available_models, data_config_avai
2961

3062
def scan():
3163
"""Scan all directories that contain example models and write to a file."""
3264

3365
available_types = ['keras', 'pytorch', 'onnx', 'tensorflow']
3466

67+
#Dictionary to save available model list
3568
model_dict = {}
69+
70+
#Dictionary to check for data and configuration availability
71+
data_config_avai = {}
3672

3773
for model_type in available_types:
38-
model_dict[model_type] = scan_subdir(model_type)
74+
model_dict[model_type], temp_data_config_avai = scan_subdir(model_type)
75+
76+
#Upate the availability of data and configuration for new scanned model
77+
data_config_avai.update(temp_data_config_avai)
3978

4079
# Serialize data into file:
4180
json.dump(model_dict, open("available_models.json", 'w' ))
42-
81+
json.dump(data_config_avai, open("available_data_config.json", 'w' ))
82+
4383
scan()

0 commit comments

Comments
 (0)