Created
September 27, 2018 15:44
-
-
Save mjbhobe/648812b4fabadc044fd195252936e155 to your computer and use it in GitHub Desktop.
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
from keras.datasets.mnist import load_data | |
# load the data - it returns 2 tuples of digits & labels - one for | |
# the train set & the other for the test set | |
(train_digits, train_labels), (test_digits, test_labels) = load_data() | |
# display 14 random images from the training set | |
import numpy as np | |
np.random.seed(123) | |
rand_14 = np.random.randint(0, train_digits.shape[0],14) | |
sample_digits = train_digits[rand_14] | |
sample_labels = train_labels[rand_14] | |
# code to view the images | |
num_rows, num_cols = 2, 7 | |
f, ax = plt.subplots(num_rows, num_cols, figsize=(12,5), | |
gridspec_kw={'wspace':0.03, 'hspace':0.01}, | |
squeeze=True) | |
for r in range(num_rows): | |
for c in range(num_cols): | |
image_index = r * 7 + c | |
ax[r,c].axis("off") | |
ax[r,c].imshow(sample_digits[image_index], cmap='gray') | |
ax[r,c].set_title('No. %d' % sample_labels[image_index]) | |
plt.show() | |
plt.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment