From 89dc0e357714ea8eb9e59f7e49e6f2fc66842308 Mon Sep 17 00:00:00 2001 From: RuihaiWu <37874862+warshallrho@users.noreply.github.com> Date: Thu, 25 Jul 2019 23:32:32 +0800 Subject: [PATCH 1/2] [fix bug] (1) add (non)trainable_weights in Layerlist (2) remove redundant parts in model.all_layers, otherwise model.all_weights may be wrong --- tensorlayer/layers/core.py | 2 ++ tensorlayer/models/core.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/tensorlayer/layers/core.py b/tensorlayer/layers/core.py index 8ea641d03..118ed0dc8 100644 --- a/tensorlayer/layers/core.py +++ b/tensorlayer/layers/core.py @@ -602,6 +602,8 @@ def __init__(self, layers, name=None): is_built = True for layer in self.layers: + self._trainable_weights.extend(layer.trainable_weights) + self._nontrainable_weights.extend(layer.nontrainable_weights) if layer._built is False: is_built = False if layer._built and layer.all_weights is not None: diff --git a/tensorlayer/models/core.py b/tensorlayer/models/core.py index bc9e9f525..74e48ee6d 100644 --- a/tensorlayer/models/core.py +++ b/tensorlayer/models/core.py @@ -358,7 +358,12 @@ def all_layers(self): attr_list.remove("all_weights") attr_list.remove("trainable_weights") attr_list.remove("nontrainable_weights") + attr_list.remove("_all_weights") + attr_list.remove("_trainable_weights") + attr_list.remove("_nontrainable_weights") attr_list.remove("all_layers") + attr_list.remove("_all_layers") + attr_list.remove("n_weights") for idx, attr in enumerate(attr_list): try: if isinstance(getattr(self, attr), Layer): From c396f24dfd38079823879e631c6909235d25e5be Mon Sep 17 00:00:00 2001 From: RuihaiWu <37874862+warshallrho@users.noreply.github.com> Date: Thu, 25 Jul 2019 23:37:46 +0800 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67ced0956..c867dd7fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -110,6 +110,8 @@ To release a new version, please update the changelog as followed: - Set allow_pickle=True in np.load() (#PR 1021) - Remove `private_method` decorator (#PR 1025) - Copy original model's `trainable_weights` and `nontrainable_weights` when initializing `ModelLayer` (#PR 1026) +- Copy original model's `trainable_weights` and `nontrainable_weights` when initializing `LayerList` (#PR 1029) +- remove redundant parts in `model.all_layers` (#PR 1029) ### Removed @@ -119,7 +121,7 @@ To release a new version, please update the changelog as followed: - @zsdonghao - @ChrisWu1997: #1010 #1015 #1025 -- @warshallrho: #1017 #1021 #1026 +- @warshallrho: #1017 #1021 #1026 #1029 - @ArnoldLIULJ: #1023 - @JingqingZ: #1023