Skip to content

Instantly share code, notes, and snippets.

@afspies
Created December 25, 2021 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afspies/b1cf52bbc50168ec1d899b86acec20b2 to your computer and use it in GitHub Desktop.
Save afspies/b1cf52bbc50168ec1d899b86acec20b2 to your computer and use it in GitHub Desktop.
Python Library Shape Conventions
# Originally taken from Xander Steenbrugge
# cv2:
height, width, _ = img.shape
img_resized = cv2.resize(img, (new_width, new_height))
img_pixel_values = img[top:down, left:right, :]
# PIL
width, height = img.size
img_resized = img.resize((new_width, new_height))
# PyTorch
[n, channels, height, width] = pt_img_tensor.shape
[n, height, width, channels] = tf_img_tensor.shape # with data_format = 'channels_last'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment