r"""Calculates fan_in / fan_out value for given weight tensor, depending on given ``mode``. See :func:`calculate_fan_in_and_fan_out` for details. Args: tensor: weight tensor in ``NCHW`` format. mode: fan_in" or "fan_out".
(tensor: Tensor, mode: str)
| 154 | |
| 155 | |
| 156 | def calculate_correct_fan(tensor: Tensor, mode: str) -> float: |
| 157 | r"""Calculates fan_in / fan_out value for given weight tensor, depending on given |
| 158 | ``mode``. |
| 159 | |
| 160 | See :func:`calculate_fan_in_and_fan_out` for details. |
| 161 | |
| 162 | Args: |
| 163 | tensor: weight tensor in ``NCHW`` format. |
| 164 | mode: fan_in" or "fan_out". |
| 165 | """ |
| 166 | mode = mode.lower() |
| 167 | valid_modes = ["fan_in", "fan_out"] |
| 168 | if mode not in valid_modes: |
| 169 | raise ValueError( |
| 170 | "Mode {} not supported, please use one of {}".format(mode, valid_modes) |
| 171 | ) |
| 172 | |
| 173 | fan_in, fan_out = calculate_fan_in_and_fan_out(tensor) |
| 174 | return fan_in if mode == "fan_in" else fan_out |
| 175 | |
| 176 | |
| 177 | def xavier_uniform_(tensor: Tensor, gain: float = 1.0) -> None: |
no test coverage detected