keras 0.2.0__py2.7.egg
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- EGG-INFO/PKG-INFO +11 -0
- EGG-INFO/SOURCES.txt +51 -0
- EGG-INFO/dependency_links.txt +1 -0
- EGG-INFO/requires.txt +6 -0
- EGG-INFO/top_level.txt +1 -0
- EGG-INFO/zip-safe +1 -0
- keras/__init__.py +15 -0
- keras/__init__.pyc +0 -0
- keras/activations.py +49 -0
- keras/activations.pyc +0 -0
- keras/backend/__init__.py +39 -0
- keras/backend/__init__.pyc +0 -0
- keras/backend/common.py +31 -0
- keras/backend/common.pyc +0 -0
- keras/backend/tensorflow_backend.py +602 -0
- keras/backend/tensorflow_backend.pyc +0 -0
- keras/backend/theano_backend.py +622 -0
- keras/backend/theano_backend.pyc +0 -0
- keras/callbacks.py +295 -0
- keras/callbacks.pyc +0 -0
- keras/constraints.py +45 -0
- keras/constraints.pyc +0 -0
- keras/datasets/__init__.py +0 -0
- keras/datasets/__init__.pyc +0 -0
- keras/datasets/cifar.py +22 -0
- keras/datasets/cifar.pyc +0 -0
- keras/datasets/cifar10.py +31 -0
- keras/datasets/cifar10.pyc +0 -0
- keras/datasets/cifar100.py +28 -0
- keras/datasets/cifar100.pyc +0 -0
- keras/datasets/data_utils.py +50 -0
- keras/datasets/data_utils.pyc +0 -0
- keras/datasets/imdb.py +66 -0
- keras/datasets/imdb.pyc +0 -0
- keras/datasets/mnist.py +23 -0
- keras/datasets/mnist.pyc +0 -0
- keras/datasets/reuters.py +148 -0
- keras/datasets/reuters.pyc +0 -0
- keras/initializations.py +86 -0
- keras/initializations.pyc +0 -0
- keras/layers/__init__.py +0 -0
- keras/layers/__init__.pyc +0 -0
- keras/layers/advanced_activations.py +156 -0
- keras/layers/advanced_activations.pyc +0 -0
- keras/layers/containers.py +405 -0
- keras/layers/containers.pyc +0 -0
- keras/layers/convolutional.py +505 -0
- keras/layers/convolutional.pyc +0 -0
- keras/layers/core.py +1428 -0
- keras/layers/core.pyc +0 -0
- keras/layers/embeddings.py +88 -0
- keras/layers/embeddings.pyc +0 -0
- keras/layers/noise.py +55 -0
- keras/layers/noise.pyc +0 -0
- keras/layers/normalization.py +123 -0
- keras/layers/normalization.pyc +0 -0
- keras/layers/ntm.py +326 -0
- keras/layers/ntm.pyc +0 -0
- keras/layers/recurrent.py +354 -0
- keras/layers/recurrent.pyc +0 -0
- keras/models.py +743 -0
- keras/models.pyc +0 -0
- keras/objectives.py +59 -0
- keras/objectives.pyc +0 -0
- keras/optimizers.py +229 -0
- keras/optimizers.pyc +0 -0
- keras/preprocessing/__init__.py +0 -0
- keras/preprocessing/__init__.pyc +0 -0
- keras/preprocessing/image.py +246 -0
- keras/preprocessing/image.pyc +0 -0
- keras/preprocessing/sequence.py +124 -0
- keras/preprocessing/sequence.pyc +0 -0
- keras/preprocessing/text.py +176 -0
- keras/preprocessing/text.pyc +0 -0
- keras/regularizers.py +86 -0
- keras/regularizers.pyc +0 -0
- keras/utils/__init__.py +0 -0
- keras/utils/__init__.pyc +0 -0
- keras/utils/generic_utils.py +133 -0
- keras/utils/generic_utils.pyc +0 -0
- keras/utils/io_utils.py +71 -0
- keras/utils/io_utils.pyc +0 -0
- keras/utils/layer_utils.py +93 -0
- keras/utils/layer_utils.pyc +0 -0
- keras/utils/np_utils.py +53 -0
- keras/utils/np_utils.pyc +0 -0
- keras/utils/test_utils.py +27 -0
- keras/utils/test_utils.pyc +0 -0
- keras/utils/theano_utils.py +44 -0
- keras/utils/theano_utils.pyc +0 -0
- keras/utils/visualize_util.py +41 -0
- keras/utils/visualize_util.pyc +0 -0
- keras/wrappers/__init__.py +0 -0
- keras/wrappers/__init__.pyc +0 -0
- keras/wrappers/scikit_learn.py +266 -0
- keras/wrappers/scikit_learn.pyc +0 -0
- tests/__init__.py +0 -0
- tests/__init__.pyc +0 -0
- tests/manual/__init__.py +0 -0
- tests/manual/__init__.pyc +0 -0
- tests/manual/check_autoencoder.py +134 -0
- tests/manual/check_autoencoder.pyc +0 -0
- tests/manual/check_callbacks.py +236 -0
- tests/manual/check_callbacks.pyc +0 -0
- tests/manual/check_constraints.py +100 -0
- tests/manual/check_constraints.pyc +0 -0
- tests/manual/check_masked_recurrent.py +130 -0
- tests/manual/check_masked_recurrent.pyc +0 -0
- tests/manual/check_model_utils.py +44 -0
- tests/manual/check_model_utils.pyc +0 -0
- tests/manual/check_save_weights.py +40 -0
- tests/manual/check_save_weights.pyc +0 -0
- tests/manual/check_wrappers.py +126 -0
- tests/manual/check_wrappers.pyc +0 -0
- tests/manual/check_yaml.py +101 -0
- tests/manual/check_yaml.pyc +0 -0
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from __future__ import absolute_import
|
|
3
|
+
from __future__ import print_function
|
|
4
|
+
|
|
5
|
+
from collections import OrderedDict
|
|
6
|
+
from .. import backend as K
|
|
7
|
+
from ..layers.core import Layer, Merge, Siamese, SiameseHead
|
|
8
|
+
from six.moves import range
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Sequential(Layer):
|
|
12
|
+
'''
|
|
13
|
+
Simple linear stack of layers.
|
|
14
|
+
|
|
15
|
+
inherited from Layer:
|
|
16
|
+
- get_params
|
|
17
|
+
- get_output_mask
|
|
18
|
+
- supports_masked_input
|
|
19
|
+
'''
|
|
20
|
+
|
|
21
|
+
def __init__(self, layers=[]):
|
|
22
|
+
self.layers = []
|
|
23
|
+
for layer in layers:
|
|
24
|
+
self.add(layer)
|
|
25
|
+
|
|
26
|
+
def set_previous(self, layer):
|
|
27
|
+
self.layers[0].previous = layer
|
|
28
|
+
|
|
29
|
+
def add(self, layer):
|
|
30
|
+
self.layers.append(layer)
|
|
31
|
+
if len(self.layers) > 1:
|
|
32
|
+
self.layers[-1].set_previous(self.layers[-2])
|
|
33
|
+
if not hasattr(self.layers[0], 'input'):
|
|
34
|
+
self.set_input()
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def params(self):
|
|
38
|
+
params = []
|
|
39
|
+
for l in self.layers:
|
|
40
|
+
if l.trainable:
|
|
41
|
+
params += l.get_params()[0]
|
|
42
|
+
return params
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def regularizers(self):
|
|
46
|
+
regularizers = []
|
|
47
|
+
for l in self.layers:
|
|
48
|
+
if l.trainable:
|
|
49
|
+
regularizers += l.get_params()[1]
|
|
50
|
+
return regularizers
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def constraints(self):
|
|
54
|
+
constraints = []
|
|
55
|
+
for l in self.layers:
|
|
56
|
+
if l.trainable:
|
|
57
|
+
constraints += l.get_params()[2]
|
|
58
|
+
return constraints
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def updates(self):
|
|
62
|
+
updates = []
|
|
63
|
+
for l in self.layers:
|
|
64
|
+
if l.trainable:
|
|
65
|
+
updates += l.get_params()[3]
|
|
66
|
+
return updates
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def output_shape(self):
|
|
70
|
+
return self.layers[-1].output_shape
|
|
71
|
+
|
|
72
|
+
def get_output(self, train=False):
|
|
73
|
+
return self.layers[-1].get_output(train)
|
|
74
|
+
|
|
75
|
+
def set_input(self):
|
|
76
|
+
for l in self.layers:
|
|
77
|
+
if hasattr(l, 'input'):
|
|
78
|
+
ndim = len(K.get_shape(l.input))
|
|
79
|
+
self.layers[0].input = K.placeholder(ndim=ndim)
|
|
80
|
+
break
|
|
81
|
+
|
|
82
|
+
def get_input(self, train=False):
|
|
83
|
+
if not hasattr(self.layers[0], 'input'):
|
|
84
|
+
self.set_input()
|
|
85
|
+
return self.layers[0].get_input(train)
|
|
86
|
+
|
|
87
|
+
@property
|
|
88
|
+
def input_shape(self):
|
|
89
|
+
return self.layers[0].input_shape
|
|
90
|
+
|
|
91
|
+
@property
|
|
92
|
+
def input(self):
|
|
93
|
+
return self.get_input()
|
|
94
|
+
|
|
95
|
+
def get_weights(self):
|
|
96
|
+
weights = []
|
|
97
|
+
for layer in self.layers:
|
|
98
|
+
weights += layer.get_weights()
|
|
99
|
+
return weights
|
|
100
|
+
|
|
101
|
+
def set_weights(self, weights):
|
|
102
|
+
for i in range(len(self.layers)):
|
|
103
|
+
nb_param = len(self.layers[i].params)
|
|
104
|
+
self.layers[i].set_weights(weights[:nb_param])
|
|
105
|
+
weights = weights[nb_param:]
|
|
106
|
+
|
|
107
|
+
def get_config(self):
|
|
108
|
+
return {"name": self.__class__.__name__,
|
|
109
|
+
"layers": [layer.get_config() for layer in self.layers]}
|
|
110
|
+
|
|
111
|
+
def count_params(self):
|
|
112
|
+
return sum([layer.count_params() for layer in self.layers])
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class Graph(Layer):
|
|
116
|
+
'''
|
|
117
|
+
Implement a NN graph with arbitrary layer connections,
|
|
118
|
+
arbitrary number of inputs and arbitrary number of outputs.
|
|
119
|
+
|
|
120
|
+
Note: Graph can only be used as a layer
|
|
121
|
+
(connect, input, get_input, get_output)
|
|
122
|
+
when it has exactly one input and one output.
|
|
123
|
+
|
|
124
|
+
inherited from Layer:
|
|
125
|
+
- get_output_mask
|
|
126
|
+
- supports_masked_input
|
|
127
|
+
- get_weights
|
|
128
|
+
- set_weights
|
|
129
|
+
'''
|
|
130
|
+
def __init__(self):
|
|
131
|
+
self.namespace = set() # strings
|
|
132
|
+
self.nodes = OrderedDict() # layer-like
|
|
133
|
+
self.inputs = {} # layer-like
|
|
134
|
+
self.input_order = [] # strings
|
|
135
|
+
self.outputs = {} # layer-like
|
|
136
|
+
self.output_order = [] # strings
|
|
137
|
+
self.input_config = [] # dicts
|
|
138
|
+
self.output_config = [] # dicts
|
|
139
|
+
self.node_config = [] # dicts
|
|
140
|
+
|
|
141
|
+
@property
|
|
142
|
+
def nb_input(self):
|
|
143
|
+
return len(self.inputs)
|
|
144
|
+
|
|
145
|
+
@property
|
|
146
|
+
def nb_output(self):
|
|
147
|
+
return len(self.outputs)
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def params(self):
|
|
151
|
+
params = []
|
|
152
|
+
for l in self.nodes.values():
|
|
153
|
+
if l.trainable:
|
|
154
|
+
params += l.get_params()[0]
|
|
155
|
+
return params
|
|
156
|
+
|
|
157
|
+
@property
|
|
158
|
+
def regularizers(self):
|
|
159
|
+
regularizers = []
|
|
160
|
+
for l in self.nodes.values():
|
|
161
|
+
if l.trainable:
|
|
162
|
+
regularizers += l.get_params()[1]
|
|
163
|
+
return regularizers
|
|
164
|
+
|
|
165
|
+
@property
|
|
166
|
+
def constraints(self):
|
|
167
|
+
constraints = []
|
|
168
|
+
for l in self.nodes.values():
|
|
169
|
+
if l.trainable:
|
|
170
|
+
constraints += l.get_params()[2]
|
|
171
|
+
return constraints
|
|
172
|
+
|
|
173
|
+
@property
|
|
174
|
+
def updates(self):
|
|
175
|
+
updates = []
|
|
176
|
+
for l in self.nodes.values():
|
|
177
|
+
if l.trainable:
|
|
178
|
+
updates += l.get_params()[3]
|
|
179
|
+
return updates
|
|
180
|
+
|
|
181
|
+
def set_previous(self, layer, connection_map={}):
|
|
182
|
+
if self.nb_input != layer.nb_output:
|
|
183
|
+
raise Exception('Cannot connect layers: input count does not match output count.')
|
|
184
|
+
if self.nb_input == 1:
|
|
185
|
+
self.inputs[self.input_order[0]].set_previous(layer)
|
|
186
|
+
else:
|
|
187
|
+
if not connection_map:
|
|
188
|
+
raise Exception('Cannot attach multi-input layer: no connection_map provided.')
|
|
189
|
+
for k, v in connection_map.items():
|
|
190
|
+
if k in self.inputs and v in layer.outputs:
|
|
191
|
+
self.inputs[k].set_previous(layer.outputs[v])
|
|
192
|
+
else:
|
|
193
|
+
raise Exception('Invalid connection map.')
|
|
194
|
+
|
|
195
|
+
def get_input(self, train=False):
|
|
196
|
+
if len(self.inputs) == len(self.outputs) == 1:
|
|
197
|
+
return self.inputs[self.input_order[0]].get_input(train)
|
|
198
|
+
else:
|
|
199
|
+
return dict([(k, v.get_input(train)) for k, v in self.inputs.items()])
|
|
200
|
+
|
|
201
|
+
@property
|
|
202
|
+
def input(self):
|
|
203
|
+
return self.get_input()
|
|
204
|
+
|
|
205
|
+
@property
|
|
206
|
+
def output_shape(self):
|
|
207
|
+
if self.nb_output == 1:
|
|
208
|
+
# return tuple
|
|
209
|
+
return self.outputs[self.output_order[0]].output_shape
|
|
210
|
+
else:
|
|
211
|
+
# return dictionary mapping output names to shape tuples
|
|
212
|
+
return dict([(k, v.output_shape) for k, v in self.outputs.items()])
|
|
213
|
+
|
|
214
|
+
def get_output(self, train=False):
|
|
215
|
+
if len(self.inputs) == len(self.outputs) == 1:
|
|
216
|
+
return self.outputs[self.output_order[0]].get_output(train)
|
|
217
|
+
else:
|
|
218
|
+
return dict([(k, v.get_output(train)) for k, v in self.outputs.items()])
|
|
219
|
+
|
|
220
|
+
def add_input(self, name, input_shape, dtype='float'):
|
|
221
|
+
if name in self.namespace:
|
|
222
|
+
raise Exception('Duplicate node identifier: ' + name)
|
|
223
|
+
self.namespace.add(name)
|
|
224
|
+
self.input_order.append(name)
|
|
225
|
+
layer = Layer() # empty layer
|
|
226
|
+
layer.set_input_shape(input_shape)
|
|
227
|
+
if dtype == 'float':
|
|
228
|
+
layer.input = K.placeholder(shape=layer.input_shape, name=name)
|
|
229
|
+
else:
|
|
230
|
+
if len(input_shape) == 1:
|
|
231
|
+
layer.input = K.placeholder(shape=layer.input_shape,
|
|
232
|
+
dtype='int32',
|
|
233
|
+
name=name)
|
|
234
|
+
else:
|
|
235
|
+
raise Exception('Type "int" can only be used with ndim==2 (Embedding).')
|
|
236
|
+
self.inputs[name] = layer
|
|
237
|
+
self.input_config.append({'name': name,
|
|
238
|
+
'input_shape': input_shape,
|
|
239
|
+
'dtype': dtype})
|
|
240
|
+
|
|
241
|
+
def add_node(self, layer, name, input=None, inputs=[],
|
|
242
|
+
merge_mode='concat', concat_axis=-1, dot_axes=-1,
|
|
243
|
+
create_output=False):
|
|
244
|
+
if name in self.namespace:
|
|
245
|
+
raise Exception('Duplicate node identifier: ' + name)
|
|
246
|
+
if input:
|
|
247
|
+
if input not in self.namespace:
|
|
248
|
+
raise Exception('Unknown node/input identifier: ' + input)
|
|
249
|
+
if input in self.nodes:
|
|
250
|
+
layer.set_previous(self.nodes[input])
|
|
251
|
+
elif input in self.inputs:
|
|
252
|
+
layer.set_previous(self.inputs[input])
|
|
253
|
+
if inputs:
|
|
254
|
+
to_merge = []
|
|
255
|
+
for n in inputs:
|
|
256
|
+
if n in self.nodes:
|
|
257
|
+
to_merge.append(self.nodes[n])
|
|
258
|
+
elif n in self.inputs:
|
|
259
|
+
to_merge.append(self.inputs[n])
|
|
260
|
+
else:
|
|
261
|
+
raise Exception('Unknown identifier: ' + n)
|
|
262
|
+
merge = Merge(to_merge, mode=merge_mode,
|
|
263
|
+
concat_axis=concat_axis, dot_axes=dot_axes)
|
|
264
|
+
layer.set_previous(merge)
|
|
265
|
+
|
|
266
|
+
self.namespace.add(name)
|
|
267
|
+
self.nodes[name] = layer
|
|
268
|
+
self.node_config.append({'name': name,
|
|
269
|
+
'input': input,
|
|
270
|
+
'inputs': inputs,
|
|
271
|
+
'merge_mode': merge_mode,
|
|
272
|
+
'concat_axis': concat_axis,
|
|
273
|
+
'dot_axes': dot_axes,
|
|
274
|
+
'create_output': create_output})
|
|
275
|
+
|
|
276
|
+
if create_output:
|
|
277
|
+
self.add_output(name, input=name)
|
|
278
|
+
|
|
279
|
+
def add_shared_node(self, layer, name, inputs=[], merge_mode=None,
|
|
280
|
+
concat_axis=-1, dot_axes=-1, outputs=[],
|
|
281
|
+
create_output=False):
|
|
282
|
+
'''
|
|
283
|
+
Used to shared / multi input-multi output node
|
|
284
|
+
|
|
285
|
+
Arguments
|
|
286
|
+
------------
|
|
287
|
+
layer - The layer to be shared across multiple inputs
|
|
288
|
+
name - Name of the shared layer
|
|
289
|
+
inputs - List of names of input nodes
|
|
290
|
+
merge_mode - Similar to merge_mode argument of add_node()
|
|
291
|
+
concat_axis - Similar to concat_axis argument of add_node()
|
|
292
|
+
dot_axes - Similar to dot_axes argument of add_node()
|
|
293
|
+
outputs - Names for output nodes. Used when merge_mode = None
|
|
294
|
+
create_output - Similar to create_output argument of add_node().
|
|
295
|
+
Output will be created only if merge_mode is given
|
|
296
|
+
'''
|
|
297
|
+
if name in self.namespace:
|
|
298
|
+
raise Exception('Duplicate node identifier: ' + name)
|
|
299
|
+
for o in outputs:
|
|
300
|
+
if o in self.namespace:
|
|
301
|
+
raise Exception('Duplicate node identifier: ' + o)
|
|
302
|
+
if merge_mode:
|
|
303
|
+
if merge_mode not in {'sum', 'ave', 'mul', 'dot', 'cos', 'concat', 'join'}:
|
|
304
|
+
raise Eception("Invalid merge mode")
|
|
305
|
+
layers = []
|
|
306
|
+
for i in range(len(inputs)):
|
|
307
|
+
input = inputs[i]
|
|
308
|
+
if input in self.nodes:
|
|
309
|
+
n = self.nodes[input]
|
|
310
|
+
if n.__class__.__name__ == 'Siamese':
|
|
311
|
+
if n.merge_mode is None:
|
|
312
|
+
for j in range(len(n.inputs)):
|
|
313
|
+
sh = SiameseHead(j)
|
|
314
|
+
sh.previous = n
|
|
315
|
+
layers.append(sh)
|
|
316
|
+
else:
|
|
317
|
+
layers.append(n)
|
|
318
|
+
else:
|
|
319
|
+
layers.append(n)
|
|
320
|
+
elif input in self.inputs:
|
|
321
|
+
n = self.inputs[input]
|
|
322
|
+
layers.append(n)
|
|
323
|
+
else:
|
|
324
|
+
raise Exception('Unknown identifier: ' + input)
|
|
325
|
+
s = Siamese(layer, layers, merge_mode, concat_axis=concat_axis, dot_axes=dot_axes)
|
|
326
|
+
s.set_name(name)
|
|
327
|
+
self.namespace.add(name)
|
|
328
|
+
self.nodes[name] = s
|
|
329
|
+
self.node_config.append({'name': name,
|
|
330
|
+
'inputs': inputs,
|
|
331
|
+
'merge_mode': merge_mode,
|
|
332
|
+
'concat_axis': concat_axis,
|
|
333
|
+
'dot_axes': dot_axes,
|
|
334
|
+
'create_output': create_output if merge_mode else False})
|
|
335
|
+
if not merge_mode:
|
|
336
|
+
for i in range(len(outputs)):
|
|
337
|
+
sh = SiameseHead(i)
|
|
338
|
+
sh.previous = s
|
|
339
|
+
sh_name = outputs[i]
|
|
340
|
+
sh.set_name(sh_name)
|
|
341
|
+
self.namespace.add(sh_name)
|
|
342
|
+
self.nodes[sh_name] = sh
|
|
343
|
+
self.node_config.append({'name': sh_name,
|
|
344
|
+
'inputs': [s],
|
|
345
|
+
'create_output': create_output})
|
|
346
|
+
if create_output:
|
|
347
|
+
self.add_output(sh_name, input=sh_name)
|
|
348
|
+
|
|
349
|
+
if create_output and merge_mode:
|
|
350
|
+
if merge_mode == 'join':
|
|
351
|
+
raise Exception("Output can not be of type OrderedDict")
|
|
352
|
+
self.add_output(name, input=name)
|
|
353
|
+
|
|
354
|
+
def add_output(self, name, input=None, inputs=[],
|
|
355
|
+
merge_mode='concat', concat_axis=-1, dot_axes=-1):
|
|
356
|
+
if name in self.output_order:
|
|
357
|
+
raise Exception('Duplicate output identifier: ' + name)
|
|
358
|
+
if input:
|
|
359
|
+
if input not in self.namespace:
|
|
360
|
+
raise Exception('Unknown node/input identifier: ' + input)
|
|
361
|
+
if input in self.nodes:
|
|
362
|
+
self.outputs[name] = self.nodes[input]
|
|
363
|
+
elif input in self.inputs:
|
|
364
|
+
self.outputs[name] = self.inputs[input]
|
|
365
|
+
if inputs:
|
|
366
|
+
to_merge = []
|
|
367
|
+
for n in inputs:
|
|
368
|
+
if n not in self.nodes:
|
|
369
|
+
raise Exception('Unknown identifier: ' + n)
|
|
370
|
+
to_merge.append(self.nodes[n])
|
|
371
|
+
merge = Merge(to_merge, mode=merge_mode,
|
|
372
|
+
concat_axis=concat_axis, dot_axes=dot_axes)
|
|
373
|
+
self.outputs[name] = merge
|
|
374
|
+
|
|
375
|
+
self.output_order.append(name)
|
|
376
|
+
self.output_config.append({'name': name,
|
|
377
|
+
'input': input,
|
|
378
|
+
'inputs': inputs,
|
|
379
|
+
'merge_mode': merge_mode,
|
|
380
|
+
'concat_axis': concat_axis,
|
|
381
|
+
'dot_axes': dot_axes})
|
|
382
|
+
|
|
383
|
+
def get_config(self):
|
|
384
|
+
return {"name": self.__class__.__name__,
|
|
385
|
+
"input_config": self.input_config,
|
|
386
|
+
"node_config": self.node_config,
|
|
387
|
+
"output_config": self.output_config,
|
|
388
|
+
"input_order": self.input_order,
|
|
389
|
+
"output_order": self.output_order,
|
|
390
|
+
"nodes": dict([(c["name"], self.nodes[c["name"]].get_config()) for c in self.node_config])}
|
|
391
|
+
|
|
392
|
+
def count_params(self):
|
|
393
|
+
return sum([layer.count_params() for layer in self.nodes.values()])
|
|
394
|
+
|
|
395
|
+
def get_weights(self):
|
|
396
|
+
weights = []
|
|
397
|
+
for layer in self.nodes.values():
|
|
398
|
+
weights += layer.get_weights()
|
|
399
|
+
return weights
|
|
400
|
+
|
|
401
|
+
def set_weights(self, weights):
|
|
402
|
+
for layer in self.nodes.values():
|
|
403
|
+
nb_param = len(layer.get_weights())
|
|
404
|
+
layer.set_weights(weights[:nb_param])
|
|
405
|
+
weights = weights[nb_param:]
|
|
Binary file
|