MCPcopy Index your code
hub / github.com/tensorlayer/TensorLayer / all_layers

Method all_layers

tensorlayer/models/core.py:349–398  ·  view source on GitHub ↗

Return all layers of this network in a list.

(self)

Source from the content-addressed store, hash-verified

347
348 @property
349 def all_layers(self):
350 """Return all layers of this network in a list."""
351 if self._all_layers is not None:
352 return self._all_layers
353
354 if self._inputs is not None and self._outputs is not None:
355 # static model
356 return self._all_layers
357 else:
358 # dynamic model
359 self._all_layers = list()
360 attr_list = [attr for attr in dir(self) if attr[:2] != "__"]
361 attr_list.remove("all_weights")
362 attr_list.remove("trainable_weights")
363 attr_list.remove("nontrainable_weights")
364 attr_list.remove("_all_weights")
365 attr_list.remove("_trainable_weights")
366 attr_list.remove("_nontrainable_weights")
367 attr_list.remove("all_layers")
368 attr_list.remove("_all_layers")
369 attr_list.remove("n_weights")
370 for idx, attr in enumerate(attr_list):
371 try:
372 if isinstance(getattr(self, attr), Layer):
373 nowlayer = getattr(self, attr)
374 if not nowlayer._built:
375 raise AttributeError("Layer %s not built yet." % repr(nowlayer))
376 self._all_layers.append(nowlayer)
377 elif isinstance(getattr(self, attr), Model):
378 nowmodel = getattr(self, attr)
379 self._all_layers.append(nowmodel)
380 elif isinstance(getattr(self, attr), list):
381 self._all_layers.extend(_add_list_to_all_layers(getattr(self, attr)))
382 # TODO: define customised exception for TL
383 except AttributeError as e:
384 raise e
385 except Exception:
386 pass
387
388 # check layer name uniqueness
389 local_layer_name_dict = set()
390 for layer in self._all_layers:
391 if layer.name in local_layer_name_dict:
392 raise ValueError(
393 'Layer name \'%s\' has already been used by another layer. Please change the layer name.' %
394 layer.name
395 )
396 else:
397 local_layer_name_dict.add(layer.name)
398 return self._all_layers
399
400 @property
401 def trainable_weights(self):

Callers

nothing calls this directly

Calls 2

_add_list_to_all_layersFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected