perceptor.utils

perceptor.utils.cache(model: T) T[source]
perceptor.utils.gradient_checkpoint(tensor: Tensor) GradientCheckpoint[source]

Gradient checkpointing to save compute for common part of graph.

Usage:

>>> checkpoint = gradient_checkpoint(images)
>>> for text_loss in text_losses:
>>>     text_loss(checkpoint.tensor()).backward()
>>> checkpoint.continue_backward()
perceptor.utils.pil_image(images: ~lantern.tensor.Tensor.dims.<locals>.InheritTensor) <module 'PIL.Image' from '/home/docs/checkouts/readthedocs.org/user_builds/perceptor/envs/stable/lib/python3.8/site-packages/PIL/Image.py'>[source]

Convert a tensor to a PIL image.

Parameters

images – a tensor of shape (N, C, H, W)