-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconfig.py
246 lines (216 loc) · 7.95 KB
/
config.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
from __future__ import division
import time
from copy import deepcopy
from os import cpu_count
from gcn.utils import preprocess_model_config
import argparse
import pprint
import tensorflow as tf
import config_citation
import config_nell
configuration = {
# repeat times
'repeating' : 1,
# The default model configuration
'default':{
# Dataset and split
'dataset' : 'cora', # 'Dataset (cora | citeseer | pubmed | large_cora | nell.0.1 | nell.0.01 | nell.0.001)
'shuffle' : True, # random split or not
'train_size' : 4, # if train_size is a number, then use TRAIN_SIZE labels per class.
'validation_size' : 500, # 'Use VALIDATION_SIZE data to train model'
'validate' : False, # Whether use validation set
'test_size' : None, # If None, all rest are test set
'feature' : 'bow', # 'bow' | 'tfidf' | 'none'.
'Model' : 'IGCN', # 'LP', 'IGCN', 'GLP', 'MLP'
# 'alpha' in LP
'alpha' : 10,
# Neural Network Setting
'connection' : 'cc',
# A string contains only char "c" or "f"
# "c" stands for convolution.
# "f" stands for fully connected.
'layer_size' : [16],
# A list or any sequential object. Describe the size of each layer.
# e.g. "--connection ccd --layer_size [7,8]"
# This combination describe a network as follow:
# input_layer --convolution-> 7 nodes --convolution-> 8 nodes --dense-> output_layer
# (or say: input_layer -c-> 7 -c-> 8 -d-> output_layer)
# graph conv in layers
'conv_config' : [{
'conv' : 'rnm', # rnm, rw, ap
'k' : 1,
'alpha' : 1/10,
} for _ in range(2)],
'optimizer' : tf.train.AdamOptimizer,
'learning_rate' : 0.01, # 'Initial learning rate.'
'epochs' : 200, # 'Number of epochs to train.'
'dropout' : 0.5, # 'Dropout rate (1 - keep probability).'
'weight_decay' : 5e-4, # 'Weight for L2 loss on embedding matrix.'
# Filter as pre-processing
'smooth_config' :{
'type' : None, # 'taubin' | None | 'ap_appro'
'alpha' : 10, # alpha for AR filter
'k' : 2, # k for RNM and RW filter
},
'logging' : False, # 'Weather or not to record log'
'logdir' : '', # 'Log directory.''
'name' : None, # 'name of the model. Serve as an ID of model.'
'random_seed' : int(time.time()), # 'Random seed.'
'threads' : cpu_count(), #'Number of threads'
'train' : True,
},
# The list of model to be train.
# Only configurations that's different with default are specified here
'model_list':
[
# MLP
{
'Model': 'MLP',
'name' : 'MLP',
'connection': 'ff',
},
# LP
{
'Model': 'LP',
'name' : 'LP',
'alpha': 100,
},
# GCN
{
'Model': 'IGCN', # GCN is a special case of IGCN
'name' : 'GCN'
},
]
# IGCN
+ [
# IGCN(RNM)
{
'Model': 'IGCN',
'name' : 'IGCN_RNM',
'connection': 'cc',
'conv_config': [
{
'conv': 'rnm',
'k': 10 // 2,
},
{
'conv': 'rnm',
'k': 10 // 2,
}],
},
# IGCN(RW)
{
'Model': 'IGCN',
'name' : 'IGCN_RW',
'connection': 'cc',
'conv_config': [
{
'conv': 'rw',
'k': 20 // 2,
},
{
'conv': 'rw',
'k': 20 // 2,
}],
},
# IGCN(AR)
{
'Model': 'IGCN',
'name' : 'IGCN_AR',
'connection': 'cc',
'conv_config': [
{
'conv': 'ap',
'alpha': 20//2,
},
{
'conv': 'ap',
'alpha': 20//2,
}]
}
]
# GLP
+ [
# GLP(RNM)
{
'Model': 'GLP',
'name' : 'GLP_RNM',
'connection': 'ff',
'smooth_config': {
'type': 'rnm',
'k': 10,
}
},
# GLP(RW)
{
'Model': 'GLP',
'name' : 'GLP_RW',
'connection': 'ff',
'smooth_config': {
'type': 'rw',
'k': 20,
}
},
# GLP(AR)
{
'Model': 'GLP',
'name' : 'GLP_AR',
'connection': 'ff',
'smooth_config': {
'type': 'ap_appro',
'alpha': 20,
}
}
]
}
# Parse args
parser = argparse.ArgumentParser(description=(
"Implementation for IGCN and GLP model in our paper\n"
""""Label Efficient Semi-Supervised Learning via Graph Filtering. (CVPR-19)"\n"""
"Most configuration are specified in config.py, please read it and modify it as you want."))
parser.add_argument("--pset", type=str, help='Parameter Set, e.g. "config_citation.large_label_set"')
parser.add_argument("-v", "--verbose", action="store_true")
parser.add_argument("--seed", type=int, help='Random seed.')
parser.add_argument("--repeat", type=int, help='repeat times')
parser.add_argument("--dataset", type=str, help='dataset name')
parser.add_argument("--train-size", type=str, help='labels per class')
parser.add_argument("--validate", type=bool, default=None, help='True or False, if use validation set or not')
parser.add_argument("--epochs", type=int, help='training epochs')
parser.add_argument("--learning-rate", type=float, help='learning rate')
parser.add_argument("--dropout", type=float, help='dropout probability, from 0.0 to 1.0')
parser.add_argument("--weight-decay", type=float, help='L2 regularization')
parser.add_argument("--layer-size", type=eval, help='a python list of hidden layer widths')
args = parser.parse_args()
print(args)
if args.pset is not None:
configuration = eval(args.pset)
if args.verbose is not None:
configuration['default']['verbose'] = args.verbose
if args.seed is not None:
configuration['default']['random_seed']=args.seed
if args.repeat is not None:
configuration['repeating']=args.repeat
if args.dataset is not None:
configuration['default']['dataset'] = args.dataset
if args.train_size is not None:
configuration['default']['train_size'] = eval(args.train_size)
if args.validate is not None:
configuration['default']['validate'] = args.validate
if args.epochs is not None:
configuration['default']['epochs'] = args.epochs
if args.learning_rate is not None:
configuration['default']['learning_rate']=args.learning_rate
if args.dropout is not None:
configuration['default']['dropout'] = args.dropout
if args.weight_decay is not None:
configuration['default']['weight_decay'] = args.weight_decay
if args.layer_size is not None:
configuration['default']['layer_size'] = args.layer_size
pprint.PrettyPrinter(indent=4).pprint(configuration)
def set_default_attr(model):
model_config = deepcopy(configuration['default'])
model_config.update(model)
return model_config
configuration['model_list'] = list(map(set_default_attr, configuration['model_list']))
for model_config in configuration['model_list']:
preprocess_model_config(model_config)