Skip to content

Commit 3857a92

Browse files
committed
Fix:Config+Added Main
1 parent d1ba392 commit 3857a92

14 files changed

Lines changed: 138 additions & 88 deletions

File tree

config/CNN/model_conf.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
"wdir" : "wdir",
77

88
"comment" : "valid_data (Mandatory) specify the path of the validation data relative to the working directory",
9-
"data_spec" : "config/CNN/data_spec.json",
9+
"data_spec" : "data_spec.json",
1010

1111
"comment" : "hidden_nnet_spec :: (Mandatory) specify the path of hidden network configuration specification relative to working directory",
12-
"hidden_nnet_spec" : "config/CNN/mlp_spec.json",
12+
"hidden_nnet_spec" : "mlp_spec.json",
1313

1414
"comment" : "conv_nnet_spec :: (Mandatory) specify the path of convolution network configuration specification relative to working directory",
15-
"conv_nnet_spec" : "config/CNN/conv_spec.json",
15+
"conv_nnet_spec" : "conv_spec.json",
1616

1717
"comment" : "hidden_output_file :: (Mandatory) specify the path of convolution network output file relative to working directory",
1818
"hidden_output_file" : "hidden_out.model",

config/CNN1/model_conf.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
"wdir" : "wdir",
77

88
"comment" : "valid_data (Mandatory) specify the path of the validation data relative to the working directory",
9-
"data_spec" : "config/CNN1/data_spec.json",
9+
"data_spec" : "data_spec.json",
1010

1111
"comment" : "hidden_nnet_spec :: (Mandatory) specify the path of hidden network configuration specification relative to working directory",
12-
"hidden_nnet_spec" : "config/CNN1/mlp_spec.json",
12+
"hidden_nnet_spec" : "mlp_spec.json",
1313

1414
"comment" : "conv_nnet_spec :: (Mandatory) specify the path of convolution network configuration specification relative to working directory",
15-
"conv_nnet_spec" : "config/CNN1/conv_spec.json",
15+
"conv_nnet_spec" : "conv_spec.json",
1616

1717
"comment" : "hidden_output_file :: (Mandatory) specify the path of convolution network output file relative to working directory",
1818
"hidden_output_file" : "hidden_out.model",

config/DBN/model_conf.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"wdir" : "wdir",
77

88
"comment" : "valid_data (Mandatory) specify the path of the validation data relative to the working directory",
9-
"data_spec" : "config/DBN/data_spec.json",
9+
"data_spec" : "data_spec.json",
1010

1111
"comment" : "rbm_nnet_spec:: (Mandatory) specify the path of RBM network configuration specification relative to working directory",
12-
"rbm_nnet_spec" : "config/DBN/rbm_spec.json",
12+
"rbm_nnet_spec" : "rbm_spec.json",
1313

1414
"comment" : "output_file :: (Mandatory) specify the path of RBM network output file relative to working directory",
1515
"output_file" : "rbm_out.model",

config/SDA/model_conf.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"wdir" : "wdir",
77

88
"comment" : "valid_data (Mandatory) specify the path of the validation data relative to the working directory",
9-
"data_spec" : "config/SDA/data_spec.json",
9+
"data_spec" : "data_spec.json",
1010

1111
"comment" : "sda_nnet_spec:: (Mandatory) specify the path of SDA network configuration specification relative to working directory",
12-
"sda_nnet_spec" : "config/SDA/sda_spec.json",
12+
"sda_nnet_spec" : "sda_spec.json",
1313

1414
"comment" : "output_file :: (Mandatory) specify the path of SDA network output file relative to working directory",
1515
"output_file" : "sda_out.model",

io_modules/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
def setLogger(level="INFO",stderr=True,name=None,logFile='python-dnn.log'):
2+
def setLogger(level="INFO",stderr=True,logFile='python-dnn.log',name=None):
33
import logging,sys
44

55
#get Logger

models/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def __init__(self):
1111
self.params = [];
1212
self.delta_params = [];
1313
self.n_layers = 0;
14+
self.type = None;
1415

1516
# allocate symbolic variables for the data
1617
self.x = T.matrix('x') # the data is presented as rasterized images
@@ -22,6 +23,9 @@ def __init__(self):
2223
self.errors = None
2324
self.finetune_cost = None
2425

26+
def getType(self):
27+
return self.type
28+
2529
def pretraining_functions(self, train_x, batch_size):
2630
"""
2731
Should be implemeted by derived class

run.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python2.7
2+
# Copyright 2014 G.K SUDHARSHAN <sudharpun90@gmail.com> IIT Madras
3+
# Copyright 2014 Abil N George<mail@abilng.in> IIT Madras
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
12+
# KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
13+
# WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
14+
# MERCHANTABLITY OR NON-INFRINGEMENT.
15+
# See the Apache 2 License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
19+
20+
from utils.load_conf import load_model
21+
import sys
22+
23+
import logging
24+
logger = logging.getLogger(__name__)
25+
from io_modules import setLogger
26+
27+
28+
def setLoggerLevel(modelConfig):
29+
# Set the level which determines what you see
30+
try:
31+
level = modelConfig['logger_level']
32+
except KeyError:
33+
level = "INFO"
34+
35+
if level == "INFO":
36+
logger.setLevel(logging.INFO)
37+
elif level == "DEBUG":
38+
logger.setLevel(logging.DEBUG)
39+
elif level == "ERROR":
40+
logger.setLevel(logging.ERROR)
41+
else:
42+
logger.setLevel(logging.WARNING)
43+
44+
45+
def runNet(modelConfig):
46+
nnetType = modelConfig ['nnetType']
47+
logger.info("Loading Other Configuration for %s",nnetType);
48+
if nnetType == 'CNN':
49+
from run.run_CNN import runCNN as runModel
50+
elif nnetType == 'RBM':
51+
from run.run_DBN import runRBM as runModel
52+
elif nnetType == 'SDA':
53+
from run.run_SDA import runSdA as runModel
54+
else :
55+
logger.error('Unknown nnet Type')
56+
return 1
57+
runModel(modelConfig)
58+
59+
60+
if __name__ == '__main__':
61+
setLogger();
62+
modelConfig = load_model(sys.argv[1])
63+
setLoggerLevel(modelConfig)
64+
runNet(modelConfig)

run/__init__.py

Whitespace-only changes.

run_CNN.py renamed to run/run_CNN.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@
3636
logger = logging.getLogger(__name__)
3737

3838

39-
def runCNN(configFile):
40-
model_configs = load_model(configFile,'CNN')
39+
def runCNN(arg):
40+
41+
if type(arg) is dict:
42+
model_configs = arg
43+
else :
44+
model_configs = load_model(arg,'CNN')
45+
4146
conv_configs,conv_layer_configs = load_conv_spec(model_configs['conv_nnet_spec'],model_configs['batch_size'],
4247
model_configs['input_shape'])
4348

run_CNNFeat.py renamed to run/run_CNNFeat.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@
3232
import logging
3333
logger = logging.getLogger(__name__)
3434

35-
def runCNNFeat(configFile):
36-
model_configs = load_model(configFile,'CNN')
35+
def runCNNFeat(arg):
36+
37+
if type(arg) is dict:
38+
model_configs = arg
39+
else :
40+
model_configs = load_model(arg,'CNN')
41+
42+
3743
batch_size = model_configs['batch_size'];
3844
conv_configs,conv_layer_configs = load_conv_spec(model_configs['conv_nnet_spec'],model_configs['batch_size'],
3945
model_configs['input_shape'])

0 commit comments

Comments
 (0)