Skip to content

Commit 5c1adbc

Browse files
committed
unstablecnn edit
1 parent 3857a92 commit 5c1adbc

9 files changed

Lines changed: 261 additions & 8 deletions

File tree

config/CNN/NP/data_spec.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"validation": {
3+
"base_path" : "data/NPFILE",
4+
"filename" : "val.dat",
5+
"partition" : 200,
6+
"random" : true,
7+
"random_seed" : 123,
8+
"dim_shuffle" : [0,3,2,1],
9+
"batch_size": 256,
10+
"keep_flatten" : false,
11+
"reader_type" : "NP"
12+
},
13+
14+
"training" : {
15+
"base_path" : "data/NPFILE",
16+
"filename" : "train.dat",
17+
"partition" : 200,
18+
"random" : true,
19+
"random_seed" : 123,
20+
"dim_shuffle" : [0,3,2,1],
21+
"batch_size": 256,
22+
"keep_flatten" : false,
23+
"reader_type" : "NP"
24+
},
25+
26+
"testing" : {
27+
"base_path" : "data/NPFILE",
28+
"filename" : "train.dat",
29+
"partition" : 200,
30+
"random" : true,
31+
"random_seed" : 123,
32+
"dim_shuffle" : [0,3,2,1],
33+
"batch_size": 256,
34+
"keep_flatten" : false,
35+
"reader_type" : "NP"
36+
}
37+
}

config/CNN/NP/model_conf.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"comment" : "nnetType :: (Mandatory) specify Type of Network (CNN,RBM) ",
3+
"nnetType" : "CNN",
4+
5+
"comment" : "train_data :: (Mandatory) specify the working directory containing data configuration and output ",
6+
"wdir" : "wdir",
7+
8+
"comment" : "valid_data (Mandatory) specify the path of the validation data relative to the working directory",
9+
"data_spec" : "config/CNN/NP/data_spec.json",
10+
11+
"comment" : "hidden_nnet_spec :: (Mandatory) specify the path of hidden network configuration specification relative to working directory",
12+
"nnet_spec" : "config/CNN/NP/nnet_spec.json",
13+
14+
"comment" : "hidden_output_file :: (Mandatory) specify the path of convolution network output file relative to working directory",
15+
"hidden_output_file" : "hidden_out.model",
16+
17+
"comment" : "conv_output_file :: (Mandatory) specify the path of convolution network output file relative to working directory",
18+
"conv_output_file" : "conv_out.model",
19+
20+
"comment" : "input_shape :: (Mandatory) specify the input shape of a given feature vector" ,
21+
"input_shape" : [3,28,28],
22+
23+
"comment" : "batch_size :: specify the mini batch size while training, default 256",
24+
"batch_size" : 256,
25+
26+
"comment" : "momentum :: Specify the momentum factor while training default 0.5",
27+
"momentum" : 0.5,
28+
29+
"comment" : "n_outs :: Specify the number of outputs",
30+
"n_outs" : 8,
31+
32+
"comment" : "l_rate_method :: Two method l_rate method are supported C: Constant learning rate and E : Exponential decay",
33+
"l_rate_method" : "C",
34+
35+
"comment" : "l_rate :: learning rate configuration",
36+
"l_rate" : {
37+
"learning_rate" : 0.08,
38+
"epoch_num" : 0,
39+
40+
"start_rate" : 0.08,
41+
"scale_by" : 0.5,
42+
"min_derror_decay_start" : 0.05,
43+
"min_derror_stop" : 0.05,
44+
"min_epoch_decay_start" : 15,
45+
"init_error" :100
46+
},
47+
"export_path" : "data/export"
48+
}

config/CNN/NP/nnet_spec.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"comment" : "layers :: convolution layer configuration",
3+
"cnn": {
4+
"layers": [
5+
{
6+
"convmat_dim" : [5,5],
7+
"num_filters" : 100,
8+
"poolsize" : [2,2],
9+
"flatten" : false,
10+
"update" : true
11+
},
12+
{
13+
"convmat_dim" : [4,4],
14+
"num_filters" : 200,
15+
"poolsize" : [2,2],
16+
"flatten" : true,
17+
"update" : true
18+
}
19+
],
20+
21+
"comment" : "activation :: sigmoid or tanh",
22+
"activation" : "tanh",
23+
24+
"comment" : "use_fast :: To use pylearn2 library for faster computation or not",
25+
"use_fast" : false
26+
},
27+
28+
"comment" : "layers :: hidden layer configuration",
29+
"mlp" : {
30+
31+
"layers": [500,200],
32+
33+
"comment" : "activation :: sigmoid or tanh",
34+
"activation" : "tanh"
35+
}
36+
}
37+

config/CNN/T/data_spec.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"validation": {
3+
"base_path" : "data/TFILE",
4+
"filename" : "val1.dat",
5+
"partition" : 0.002,
6+
"random" : true,
7+
"random_seed" : 123,
8+
"input_shape" : [1,10,5],
9+
"dim_shuffle" : [0,1,2,3],
10+
"batch_size": 8,
11+
"keep_flatten" : false,
12+
"reader_type" : "T1"
13+
},
14+
15+
"training" : {
16+
"base_path" : "data/TFILE",
17+
"filename" : "train1.dat",
18+
"partition" : 0.002,
19+
"random" : true,
20+
"random_seed" : 123,
21+
"input_shape" : [1,10,5],
22+
"dim_shuffle" : [0,1,2,3],
23+
"batch_size": 8,
24+
"keep_flatten" : false,
25+
"reader_type" : "T1"
26+
},
27+
28+
"testing" : {
29+
"base_path" : "data/TFILE",
30+
"filename" : "train1.dat",
31+
"partition" : 0.002,
32+
"random" : true,
33+
"random_seed" : 123,
34+
"input_shape" : [1,10,5],
35+
"dim_shuffle" : [0,1,2,3],
36+
"batch_size": 8,
37+
"keep_flatten" : false,
38+
"reader_type" : "T1"
39+
}
40+
}

config/CNN/T/mlp_spec.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
3+
"comment" : "layers :: hidden layer configuration",
4+
"layers": [100,200],
5+
6+
"comment" : "activation :: sigmoid or tanh",
7+
"activation" : "tanh"
8+
}

config/CNN/T/model_conf.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"comment" : "nnetType :: (Mandatory) specify Type of Network (CNN,RBM) ",
3+
"nnetType" : "CNN",
4+
5+
"comment" : "train_data :: (Mandatory) specify the working directory containing data configuration and output ",
6+
"wdir" : "wdir",
7+
8+
"comment" : "valid_data (Mandatory) specify the path of the validation data relative to the working directory",
9+
"data_spec" : "config/CNN/T/data_spec.json",
10+
11+
"comment" : "nnet_spec :: (Mandatory) specify the path of convolution network configuration specification relative to working directory",
12+
"nnet_spec" : "config/CNN/T/nnet_spec.json",
13+
14+
"comment" : "hidden_output_file :: (Mandatory) specify the path of convolution network output file relative to working directory",
15+
"hidden_output_file" : "hidden_out.model",
16+
17+
"comment" : "conv_output_file :: (Mandatory) specify the path of convolution network output file relative to working directory",
18+
"conv_output_file" : "conv_out.model",
19+
20+
"comment" : "input_shape :: (Mandatory) specify the input shape of a given feature vector" ,
21+
"input_shape" : [1,10,5],
22+
23+
"comment" : "batch_size :: specify the mini batch size while training, default 256",
24+
"batch_size" : 8,
25+
26+
"comment" : "momentum :: Specify the momentum factor while training default 0.5",
27+
"momentum" : 0.5,
28+
29+
"comment" : "n_outs :: Specify the number of outputs",
30+
"n_outs" : 8,
31+
32+
"comment" : "l_rate_method :: Two method l_rate method are supported C: Constant learning rate and E : Exponential decay",
33+
"l_rate_method" : "C",
34+
35+
"comment" : "l_rate :: learning rate configuration",
36+
"l_rate" : {
37+
"learning_rate" : 0.08,
38+
"epoch_num" : 10,
39+
40+
"start_rate" : 0.08,
41+
"scale_by" : 0.5,
42+
"min_derror_decay_start" : 0.05,
43+
"min_derror_stop" : 0.05,
44+
"min_epoch_decay_start" : 15,
45+
"init_error" :100
46+
},
47+
"export_path" : "data/export"
48+
}

config/CNN/T/nnet_spec.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"comment" : "layers :: convolution layer configuration",
3+
"cnn" : {
4+
"layers": [
5+
{
6+
"convmat_dim" : [3,2],
7+
"num_filters" : 100,
8+
"poolsize" : [2,2],
9+
"flatten" : true,
10+
"update" : true
11+
}
12+
13+
],
14+
15+
"comment" : "activation :: sigmoid or tanh",
16+
"activation" : "tanh",
17+
18+
"comment" : "use_fast :: To use pylearn2 library for faster computation or not",
19+
"use_fast" : false
20+
},
21+
22+
"comment" : "layers :: hidden layer configuration",
23+
"mlp" : {
24+
"layers": [100,200],
25+
26+
"comment" : "activation :: sigmoid or tanh",
27+
"activation" : "tanh"
28+
}
29+
}

run/run_CNN.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ def runCNN(arg):
4343
else :
4444
model_configs = load_model(arg,'CNN')
4545

46-
conv_configs,conv_layer_configs = load_conv_spec(model_configs['conv_nnet_spec'],model_configs['batch_size'],
46+
conv_configs,conv_layer_configs,mlp_configs = load_conv_spec(model_configs['nnet_spec'],model_configs['batch_size'],
4747
model_configs['input_shape'])
4848

49-
mlp_configs = load_mlp_spec(model_configs['hidden_nnet_spec']);
5049
data_spec = load_data_spec(model_configs['data_spec']);
5150

5251
numpy_rng = numpy.random.RandomState(89677)

utils/load_conf.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def load_mlp_spec(input_file):
109109
logger.info("Loading mlp properties from %s ...",input_file)
110110
return load_json(input_file);
111111

112-
112+
113113
#############################################################################
114114
#CNN
115115
#############################################################################
@@ -141,9 +141,12 @@ def initModelCNN(data):
141141
def load_conv_spec(input_file,batch_size,input_shape):
142142
logger.info("Loading convnet properties from %s ...",input_file)
143143
data = load_json(input_file)
144-
145-
layer_configs=data.pop('layers');
146-
conv_configs = data;
144+
if not data.has_key('cnn'):
145+
logger.critical("CNN configuration is not present in " + str(input_file))
146+
exit(1)
147+
cnn_data = data['cnn'];
148+
layer_configs=cnn_data.pop('layers');
149+
conv_configs = cnn_data;
147150
if len(layer_configs)==0:
148151
print "Error: No convnet configuration avaialable.."
149152
exit(1)
@@ -159,7 +162,7 @@ def load_conv_spec(input_file,batch_size,input_shape):
159162

160163
current_map_number = layer_configs[layer_index]['num_filters']
161164
layer_configs[layer_index]['filter_shape']=[current_map_number,prev_map_number];
162-
layer_configs[layer_index]['filter_shape'].extend(layer_configs[layer_index]['convmat_dim']);
165+
layer_configs[layer_index]['filter_shape'].extend(layer_configs[layer_index][' ']);
163166

164167
layer_configs[layer_index]['output_shape'] = [batch_size,current_map_number];
165168
if not len(layer_configs[layer_index]['input_shape'][2:]) == len(layer_configs[layer_index]['convmat_dim']):
@@ -172,7 +175,11 @@ def load_conv_spec(input_file,batch_size,input_shape):
172175
input_shape.append(outdim);
173176

174177
prev_map_number = current_map_number
175-
return (conv_configs,layer_configs)
178+
if not data.has_key('cnn'):
179+
logger.critical("mlp configuration is not present in " + str(input_file))
180+
exit(1)
181+
mlp_configs = data['mlp'];
182+
return (conv_configs,layer_configs,mlp_configs)
176183

177184
#############################################################################
178185
#DBN/RBM

0 commit comments

Comments
 (0)