Skip to content

Instantly share code, notes, and snippets.

@himanshurawlani
Created December 26, 2019 18:49
Show Gist options
  • Save himanshurawlani/b50afcc2545ec894324731230fdff6e7 to your computer and use it in GitHub Desktop.
Save himanshurawlani/b50afcc2545ec894324731230fdff6e7 to your computer and use it in GitHub Desktop.
def construct_image_batch(image_group, BATCH_SIZE):
# get the max image shape
max_shape = tuple(max(image.shape[x] for image in image_group) for x in range(3))
# construct an image batch object
image_batch = np.zeros((BATCH_SIZE,) + max_shape, dtype='float32')
# copy all images to the upper left part of the image batch object
for image_index, image in enumerate(image_group):
image_batch[image_index, :image.shape[0], :image.shape[1], :image.shape[2]] = image
return image_batch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment