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

Method plot

utils/torchmetric_fvd.py:445–495  ·  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

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected