Initializer base class: all initializers inherit from this class.
| 53 | |
| 54 | |
| 55 | class Initializer(object): |
| 56 | """Initializer base class: all initializers inherit from this class.""" |
| 57 | |
| 58 | def __call__(self, shape, dtype=None, partition_info=None): |
| 59 | """Returns a tensor object initialized as specified by the initializer. |
| 60 | |
| 61 | Args: |
| 62 | shape: Shape of the tensor. |
| 63 | dtype: Optional dtype of the tensor. If not provided use the initializer |
| 64 | dtype. |
| 65 | partition_info: Optional information about the possible partitioning of a |
| 66 | tensor. |
| 67 | """ |
| 68 | raise NotImplementedError |
| 69 | |
| 70 | def get_config(self): |
| 71 | """Returns the configuration of the initializer as a JSON-serializable dict. |
| 72 | |
| 73 | Returns: |
| 74 | A JSON-serializable Python dict. |
| 75 | """ |
| 76 | return {} |
| 77 | |
| 78 | @classmethod |
| 79 | def from_config(cls, config): |
| 80 | """Instantiates an initializer from a configuration dictionary. |
| 81 | |
| 82 | Example: |
| 83 | |
| 84 | ```python |
| 85 | initializer = RandomUniform(-1, 1) |
| 86 | config = initializer.get_config() |
| 87 | initializer = RandomUniform.from_config(config) |
| 88 | ``` |
| 89 | |
| 90 | Args: |
| 91 | config: A Python dictionary. It will typically be the output of |
| 92 | `get_config`. |
| 93 | |
| 94 | Returns: |
| 95 | An Initializer instance. |
| 96 | """ |
| 97 | return cls(**config) |
| 98 | |
| 99 | |
| 100 | @tf_export(v1=["initializers.zeros", "zeros_initializer"]) |
no outgoing calls