MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / tensor_to_pil

Function tensor_to_pil

modeling/pi3/utils/basic.py:105–121  ·  view source on GitHub ↗

Converts a PyTorch tensor to a PIL image. Automatically moves the channel dimension (if it has size 3) to the last axis before converting. Args: tensor (torch.Tensor): Input tensor. Expected shape can be [C, H, W], [H, W, C], or [H, W]. Returns: PIL.Image: The

(tensor)

Source from the content-addressed store, hash-verified

103 return total_params
104
105def tensor_to_pil(tensor):
106 """
107 Converts a PyTorch tensor to a PIL image. Automatically moves the channel dimension
108 (if it has size 3) to the last axis before converting.
109
110 Args:
111 tensor (torch.Tensor): Input tensor. Expected shape can be [C, H, W], [H, W, C], or [H, W].
112
113 Returns:
114 PIL.Image: The converted PIL image.
115 """
116 if torch.is_tensor(tensor):
117 array = tensor.detach().cpu().numpy()
118 else:
119 array = tensor
120
121 return array_to_pil(array)
122
123
124def array_to_pil(array):

Callers

nothing calls this directly

Calls 1

array_to_pilFunction · 0.70

Tested by

no test coverage detected