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

Function save_image_grid_auto

eval_code/recons/utils/vis_utils.py:25–41  ·  view source on GitHub ↗

images: np.ndarray of shape (N, H, W, 3) in [0, 255] or torch.Tensor of shape (N, 3, H, W) in range [0, 1]

(images: Union[np.ndarray, torch.Tensor], save_path: str)

Source from the content-addressed store, hash-verified

23
24
25def save_image_grid_auto(images: Union[np.ndarray, torch.Tensor], save_path: str):
26 """
27 images: np.ndarray of shape (N, H, W, 3) in [0, 255] or torch.Tensor of shape (N, 3, H, W) in range [0, 1]
28 """
29 if isinstance(images, torch.Tensor):
30 assert images.ndim == 4 and (images.shape[1] == 3 or images.shape[-1] == 3), f"images must be a 4D torch tensor with shape (N, 3, H, W) or (N, H, W, 3)"
31 if images.shape[1] == 3:
32 images = images.permute(0, 2, 3, 1)
33 images = (images.detach().cpu().numpy() * 255).astype(np.uint8)
34 elif isinstance(images, np.ndarray):
35 assert images.ndim == 4 and images.shape[3] == 3, f"images must be a 4D numpy array with shape (N, H, W, 3)"
36 else:
37 raise ValueError(f"images must be a numpy array or a torch tensor, but got {type(images)}")
38
39 rows = math.floor(math.sqrt(len(images)))
40 cols = math.ceil(len(images) / rows)
41 save_image_grid(images, (rows, cols), save_path)

Callers 2

mainFunction · 0.90
mainFunction · 0.90

Calls 1

save_image_gridFunction · 0.85

Tested by

no test coverage detected