Count the total number of scalars composing the weights. Returns: An integer count. Raises: ValueError: if the layer isn't yet built (in which case its weights aren't yet defined).
(self)
| 1631 | 'instead.') |
| 1632 | |
| 1633 | def count_params(self): |
| 1634 | """Count the total number of scalars composing the weights. |
| 1635 | |
| 1636 | Returns: |
| 1637 | An integer count. |
| 1638 | |
| 1639 | Raises: |
| 1640 | ValueError: if the layer isn't yet built |
| 1641 | (in which case its weights aren't yet defined). |
| 1642 | """ |
| 1643 | if not self.built: |
| 1644 | if getattr(self, '_is_graph_network', False): |
| 1645 | with tf_utils.maybe_init_scope(self): |
| 1646 | self._maybe_build(self.inputs) |
| 1647 | else: |
| 1648 | raise ValueError('You tried to call `count_params` on ' + self.name + |
| 1649 | ', but the layer isn\'t built. ' |
| 1650 | 'You can build it manually via: `' + self.name + |
| 1651 | '.build(batch_input_shape)`.') |
| 1652 | return int(sum(np.prod(w.shape.as_list()) for w in self.weights)) |
| 1653 | |
| 1654 | @property |
| 1655 | def output_shape(self): |