-
Notifications
You must be signed in to change notification settings - Fork 970
/
cifar10-sampler-7.1.2.py
executable file
·47 lines (39 loc) · 1.08 KB
/
cifar10-sampler-7.1.2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'''
Demonstrates how to sample and plot CIFAR10 images
'''
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from tensorflow.keras.datasets import cifar10
import matplotlib.pyplot as plt
import other_utils
import math
# load dataset
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
# sample cifar10 from train dataset
size = 1
side = int(math.sqrt(size))
indexes = np.random.randint(0, x_train.shape[0], size=size)
images = x_train[indexes]
gray_images = other_utils.rgb2gray(x_train[indexes])
# plot color cifar10
plt.figure(figsize=(side,side))
for i in range(len(indexes)):
plt.subplot(side, side, i + 1)
image = images[i]
plt.imshow(image)
plt.axis('off')
plt.savefig("cifar10-color-samples.png")
plt.show()
plt.close('all')
# plot gray cifar10
plt.figure(figsize=(side,side))
for i in range(len(indexes)):
plt.subplot(side, side, i + 1)
image = gray_images[i]
plt.imshow(image, cmap='gray')
plt.axis('off')
plt.savefig("cifar10-gray-samples.png")
plt.show()
plt.close('all')