Add Trackable dependencies on a list of Layers.
(self, layers)
| 388 | return self._dynamic or any(layer.dynamic for layer in self.layers) |
| 389 | |
| 390 | def _track_layers(self, layers): |
| 391 | """Add Trackable dependencies on a list of Layers.""" |
| 392 | weight_layer_index = 0 |
| 393 | for layer_index, layer in enumerate(layers): |
| 394 | try: |
| 395 | if layer.weights: |
| 396 | # Keep a separate index for layers which have weights. This allows |
| 397 | # users to insert Layers without weights anywhere in the network |
| 398 | # without breaking checkpoints. |
| 399 | self._track_trackable( |
| 400 | layer, name='layer_with_weights-%d' % weight_layer_index, |
| 401 | overwrite=True) |
| 402 | weight_layer_index += 1 |
| 403 | except ValueError: |
| 404 | # The layer might have weights, but may not be built yet. We just treat |
| 405 | # it as layer without weight. |
| 406 | pass |
| 407 | |
| 408 | # Even if it doesn't have weights, we should still track everything in |
| 409 | # case it has/will have Trackable dependencies. |
| 410 | self._track_trackable( |
| 411 | layer, name='layer-%d' % layer_index, overwrite=True) |
| 412 | |
| 413 | def __setattr__(self, name, value): |
| 414 | if not getattr(self, '_self_setattr_tracking', True): |
no test coverage detected