Inserts ancillary layers into the model with the proper order.
(model, ancillary_layers, metrics_names, new_nodes)
| 58 | |
| 59 | |
| 60 | def _insert_ancillary_layers(model, ancillary_layers, metrics_names, new_nodes): |
| 61 | """Inserts ancillary layers into the model with the proper order.""" |
| 62 | # Sort `AddMetric` layers so they agree with metrics_names. |
| 63 | metric_layers = [ |
| 64 | layer for layer in ancillary_layers if isinstance(layer, AddMetric) |
| 65 | ] |
| 66 | metric_layers.sort(key=lambda layer: metrics_names.index(layer.metric_name)) |
| 67 | ancillary_layers = [ |
| 68 | layer for layer in ancillary_layers if not isinstance(layer, AddMetric) |
| 69 | ] + metric_layers |
| 70 | model._insert_layers(ancillary_layers, relevant_nodes=list(new_nodes)) |
| 71 | |
| 72 | |
| 73 | def _make_new_nodes(nodes_by_depth, layer_fn, layer_map, tensor_map): |
no test coverage detected