The “grid” of images is created by flattening the images provided as a batch of image tensors (4D) into a single image tensor (3D).
The shapes are created by placing the images next to each other using the specified nrow and padding arguments as described in the docs 1.