Plot a single or multiple values from the metric. Args: val: Either a single result from calling `metric.forward` or `metric.compute` or a list of these results. If no value is provided, will automatically call `metric.compute` and plot that result. a
(
self, val: Optional[Union[Tensor, Sequence[Tensor]]] = None, ax: Optional[_AX_TYPE] = None
)
| 173 | return kl.mean(), kl.std() |
| 174 | |
| 175 | def plot( |
| 176 | self, val: Optional[Union[Tensor, Sequence[Tensor]]] = None, ax: Optional[_AX_TYPE] = None |
| 177 | ) -> _PLOT_OUT_TYPE: |
| 178 | """Plot a single or multiple values from the metric. |
| 179 | |
| 180 | Args: |
| 181 | val: Either a single result from calling `metric.forward` or `metric.compute` or a list of these results. |
| 182 | If no value is provided, will automatically call `metric.compute` and plot that result. |
| 183 | ax: An matplotlib axis object. If provided will add plot to that axis |
| 184 | |
| 185 | Returns: |
| 186 | Figure and Axes object |
| 187 | |
| 188 | Raises: |
| 189 | ModuleNotFoundError: |
| 190 | If `matplotlib` is not installed |
| 191 | |
| 192 | .. plot:: |
| 193 | :scale: 75 |
| 194 | |
| 195 | >>> # Example plotting a single value |
| 196 | >>> import torch |
| 197 | >>> from torchmetrics.image.inception import InceptionScore |
| 198 | >>> metric = InceptionScore() |
| 199 | >>> metric.update(torch.randint(0, 255, (50, 3, 299, 299), dtype=torch.uint8)) |
| 200 | >>> fig_, ax_ = metric.plot() # the returned plot only shows the mean value by default |
| 201 | |
| 202 | .. plot:: |
| 203 | :scale: 75 |
| 204 | |
| 205 | >>> # Example plotting multiple values |
| 206 | >>> import torch |
| 207 | >>> from torchmetrics.image.inception import InceptionScore |
| 208 | >>> metric = InceptionScore() |
| 209 | >>> values = [ ] |
| 210 | >>> for _ in range(3): |
| 211 | ... # we index by 0 such that only the mean value is plotted |
| 212 | ... values.append(metric(torch.randint(0, 255, (50, 3, 299, 299), dtype=torch.uint8))[0]) |
| 213 | >>> fig_, ax_ = metric.plot(values) |
| 214 | |
| 215 | """ |
| 216 | val = val or self.compute()[0] # by default we select the mean to plot |
| 217 | return self._plot(val, ax) |