Removes and returns any ancillary layers from `layers` based on `model`. Ancillary layers are part of the model topology but not used to compute the model outputs, e.g., layers from `add_loss` and `add_metric`. Args: model: A Keras Model. layer_map: A map to from layers in the `model
(model, layer_map, layers)
| 230 | |
| 231 | |
| 232 | def _remove_ancillary_layers(model, layer_map, layers): |
| 233 | """Removes and returns any ancillary layers from `layers` based on `model`. |
| 234 | |
| 235 | Ancillary layers are part of the model topology but not used to compute the |
| 236 | model outputs, e.g., layers from `add_loss` and `add_metric`. |
| 237 | |
| 238 | Args: |
| 239 | model: A Keras Model. |
| 240 | layer_map: A map to from layers in the `model` to those in `layers`. |
| 241 | layers: A list of all layers. |
| 242 | |
| 243 | Returns: |
| 244 | Two lists of layers: (1) `layers` with the ancillary layers removed, and (2) |
| 245 | the ancillary layers. |
| 246 | """ |
| 247 | ancillary_layers = [] # Additional layers for computing losses and metrics. |
| 248 | if not model._is_graph_network: |
| 249 | return layers, ancillary_layers |
| 250 | |
| 251 | # Ancillary layers are those with depth < 0. |
| 252 | depths = [depth for depth in model._nodes_by_depth.keys() if depth < 0] |
| 253 | depths.sort(reverse=True) # Order topologically from inputs to outputs. |
| 254 | for depth in depths: |
| 255 | for node in model._nodes_by_depth[depth]: |
| 256 | ancillary_layers.append(layer_map[node.outbound_layer]) |
| 257 | |
| 258 | return [l for l in layers if l not in ancillary_layers], ancillary_layers |
| 259 | |
| 260 | |
| 261 | def _clone_sequential_model(model, input_tensors=None, layer_fn=_clone_layer): |
no test coverage detected