images: numpy array of shape (N, H, W, 3) grid_shape: (rows, cols)
(images: np.ndarray, grid_shape: tuple, save_path: str)
| 7 | |
| 8 | |
| 9 | def save_image_grid(images: np.ndarray, grid_shape: tuple, save_path: str): |
| 10 | """ |
| 11 | images: numpy array of shape (N, H, W, 3) |
| 12 | grid_shape: (rows, cols) |
| 13 | """ |
| 14 | H, W = images.shape[1], images.shape[2] |
| 15 | grid = np.zeros((grid_shape[0]*H, grid_shape[1]*W, 3), dtype=np.uint8) |
| 16 | |
| 17 | for i in range(min(len(images), grid_shape[0]*grid_shape[1])): |
| 18 | row = i // grid_shape[1] |
| 19 | col = i % grid_shape[1] |
| 20 | grid[row*H:(row+1)*H, col*W:(col+1)*W] = images[i] |
| 21 | |
| 22 | Image.fromarray(grid).save(save_path) |
| 23 | |
| 24 | |
| 25 | def save_image_grid_auto(images: Union[np.ndarray, torch.Tensor], save_path: str): |
no outgoing calls
no test coverage detected