Retrieves a layer based on either its name (unique) or index. If `name` and `index` are both provided, `index` will take precedence. Indices are based on order of horizontal graph traversal (bottom-up). Arguments: name: String, name of layer. index: Integer, index of la
(self, name=None, index=None)
| 498 | self._layers) |
| 499 | |
| 500 | def get_layer(self, name=None, index=None): |
| 501 | """Retrieves a layer based on either its name (unique) or index. |
| 502 | |
| 503 | If `name` and `index` are both provided, `index` will take precedence. |
| 504 | Indices are based on order of horizontal graph traversal (bottom-up). |
| 505 | |
| 506 | Arguments: |
| 507 | name: String, name of layer. |
| 508 | index: Integer, index of layer. |
| 509 | |
| 510 | Returns: |
| 511 | A layer instance. |
| 512 | |
| 513 | Raises: |
| 514 | ValueError: In case of invalid layer name or index. |
| 515 | """ |
| 516 | # TODO(fchollet): We could build a dictionary based on layer names |
| 517 | # since they are constant, but we have not done that yet. |
| 518 | if index is not None: |
| 519 | if len(self.layers) <= index: |
| 520 | raise ValueError('Was asked to retrieve layer at index ' + str(index) + |
| 521 | ' but model only has ' + str(len(self.layers)) + |
| 522 | ' layers.') |
| 523 | else: |
| 524 | return self.layers[index] |
| 525 | else: |
| 526 | if not name: |
| 527 | raise ValueError('Provide either a layer name or layer index.') |
| 528 | for layer in self.layers: |
| 529 | if layer.name == name: |
| 530 | return layer |
| 531 | raise ValueError('No such layer: ' + name) |
| 532 | |
| 533 | @property |
| 534 | def trainable_weights(self): |
no outgoing calls