MCPcopy Create free account
hub / github.com/CompVis/zigma / plot

Method plot

utils/torchmetric_sfid.py:438–488  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

436 return out
437
438 def plot(
439 self,
440 val: Optional[Union[Tensor, Sequence[Tensor]]] = None,
441 ax: Optional[_AX_TYPE] = None,
442 ) -> _PLOT_OUT_TYPE:
443 """Plot a single or multiple values from the metric.
444
445 Args:
446 val: Either a single result from calling `metric.forward` or `metric.compute` or a list of these results.
447 If no value is provided, will automatically call `metric.compute` and plot that result.
448 ax: An matplotlib axis object. If provided will add plot to that axis
449
450 Returns:
451 Figure and Axes object
452
453 Raises:
454 ModuleNotFoundError:
455 If `matplotlib` is not installed
456
457 .. plot::
458 :scale: 75
459
460 >>> # Example plotting a single value
461 >>> import torch
462 >>> from torchmetrics.image.fid import FrechetInceptionDistance
463 >>> imgs_dist1 = torch.randint(0, 200, (100, 3, 299, 299), dtype=torch.uint8)
464 >>> imgs_dist2 = torch.randint(100, 255, (100, 3, 299, 299), dtype=torch.uint8)
465 >>> metric = FrechetInceptionDistance(feature=64)
466 >>> metric.update(imgs_dist1, real=True)
467 >>> metric.update(imgs_dist2, real=False)
468 >>> fig_, ax_ = metric.plot()
469
470 .. plot::
471 :scale: 75
472
473 >>> # Example plotting multiple values
474 >>> import torch
475 >>> from torchmetrics.image.fid import FrechetInceptionDistance
476 >>> imgs_dist1 = lambda: torch.randint(0, 200, (100, 3, 299, 299), dtype=torch.uint8)
477 >>> imgs_dist2 = lambda: torch.randint(100, 255, (100, 3, 299, 299), dtype=torch.uint8)
478 >>> metric = FrechetInceptionDistance(feature=64)
479 >>> values = [ ]
480 >>> for _ in range(3):
481 ... metric.update(imgs_dist1(), real=True)
482 ... metric.update(imgs_dist2(), real=False)
483 ... values.append(metric.compute())
484 ... metric.reset()
485 >>> fig_, ax_ = metric.plot(values)
486
487 """
488 return self._plot(val, ax)
489
490
491if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected