Last active
August 28, 2020 16:27
-
-
Save shayaf84/a194fcd4ed8ed29676a5a6a171b7c7c7 to your computer and use it in GitHub Desktop.
Function that displays an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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