Skip to content

Instantly share code, notes, and snippets.

@shayaf84
Last active August 28, 2020 16:27
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 shayaf84/a194fcd4ed8ed29676a5a6a171b7c7c7 to your computer and use it in GitHub Desktop.
Save shayaf84/a194fcd4ed8ed29676a5a6a171b7c7c7 to your computer and use it in GitHub Desktop.
Function that displays an image
def plot_one_image(data, labels = [], index = None, image_shape = [64,64,3]):
num_dims = len(data.shape)
num_labels = len(labels)
# reshape data if necessary
if num_dims == 1:
data = data.reshape(target_shape)
if num_dims == 2:
data = data.reshape(np.vstack[-1, image_shape])
num_dims = len(data.shape)
# check if single or multiple images
if num_dims == 3:
if num_labels > 1:
print('Multiple labels does not make sense for single image.')
return
label = labels
if num_labels == 0:
label = ''
image = data
if num_dims == 4:
image = data[index, :]
label = labels[index]
# plot image of interest
print('Label: %s'%label)
plt.imshow(image)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment