plot_videos#
- deepinv.utils.plot_videos(vid_list: Tensor | List[Tensor], titles: str | List[str] | None = None, time_dim: int = 2, rescale_mode: str = 'min_max', display: bool = False, figsize: Tuple[int] | None = None, dpi: int | None = None, save_fn: str | None = None, return_anim: bool = False, anim_writer: str | None = None, anim_kwargs: dict = {}, **plot_kwargs)[source]#
Plots and animates a list of image sequences.
Plots videos as sequence of side-by-side frames, and saves animation (e.g. GIF) or displays as interactive HTML in notebook. This is useful for e.g. time-varying inverse problems. Individual frames are plotted with
deepinv.utils.plot()
vid_list can either be a video or a list of them. A video is defined as images of shape [B,C,H,W] augmented with a time dimension specified by
time_dim
, e.g. of shape [B,C,T,H,W] andtime_dim=2
. All videos must be same time-length.Per frame of the videos, this function calls
deepinv.utils.plot()
, see its params to see how the frames are plotted.To display an interactive HTML video in an IPython notebook, use
display=True
. Note IPython must be installed for this.
- Examples:
Display list of image sequences live in a notebook:
>>> from deepinv.utils import plot_videos >>> x = torch.rand((1, 3, 5, 8, 8)) # B,C,T,H,W image sequence >>> y = torch.rand((1, 3, 5, 16, 16)) >>> plot_videos([x, y], display=True) # Display interactive view in notebook (requires IPython) >>> plot_videos([x, y], save_fn="vid.gif") # Save video as GIF
- Parameters:
vid_list (Union[torch.Tensor, List[torch.Tensor]]) – video or list of videos as defined above
titles (Union[str, List[str]]) – titles of images in frame, defaults to None
time_dim (int) – time dimension of the videos. All videos should have same length in this dimension, or length 1. After indexing this dimension, the resulting images should be of shape [B,C,H,W]. Defaults to 2
rescale_mode (str) – rescaling mode for
deepinv.utils.plot()
, defaults to “min_max”display (bool) – display an interactive HTML video in an IPython notebook, defaults to False
figsize (tuple[int], None) – size of the figure. If None, calculated from size of img list.
save_fn (str) – if not None, save the animation to this filename. File extension must be provided, note
anim_writer
might have to be specified. Defaults to Noneanim_writer (str) – animation writer, see https://matplotlib.org/stable/users/explain/animations/animations.html#animation-writers, defaults to None
return_anim (bool) – return matplotlib animation object, defaults to False
dpi (int) – DPI of saved videos.
anim_kwargs (dict) – keyword args for matplotlib FuncAnimation init
plot_kwargs (**) – kwargs to pass to
deepinv.utils.plot()
Examples using plot_videos
:#
Self-supervised MRI reconstruction with Artifact2Artifact