Skip to content
박선준 edited this page Apr 1, 2018 · 16 revisions

2주차(2018.04.01)

'모두를 위한 딥러닝' 7~11강 학습

MNIST

Making MNIST Data

First, create 0~9 grid images using this, then run the script below.

from scipy import misc
import numpy as np
import os

user_id = 0
for i in range(10):
    if not os.path.exists(str(i)):
        os.makedirs(str(i))
    grid_img = misc.imread(str(i)+".png")
    count = 0;
    for x in np.array_split(grid_img, 5, 1):
        for y in np.array_split(x, 2, 0):
            arr = np.array(y)
            misc.imsave(str(i)+'/mnist_'+str(user_id)+str(count)+'.png', y[0:28, 0:28])
            count+=1;

CNN(Convolutional Neural Network)

CIFAR-10 Image Classification using CNN

training data

from tensorflow.python.keras._impl.keras.datasets.cifar10 import load_data

label_name = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']

(x_train, y_train), (x_test, y_test) = load_data()
y_one_hot_train = tf.squeeze(tf.one_hot(y_train, 10), 1)
y_one_hot_test = tf.squeeze(tf.one_hot(y_test, 10), 1)

batch

batch_size = 100

total_batch = int(len(x_train) / batch_size)
for batch_x, batch_y in zip(np.split(x_train, batch_size), np.split(y_one_hot_train, batch_size)):
    #using batch_x, batch_y

result

for i in random.sample(range(1, int(len(x_test))), 10):
    plt.imshow(x_test[i])
    predict_label = sess.run(tf.arg_max(hypothesis, 1),
                         feed_dict={X: np.expand_dims(x_test[i], 0), Y: np.expand_dims(y_one_hot_test[i], 0),
                                   keep_prob: 1})
    textstr = 'predicted : ' + label_name[int(predict_label)] + ", label : " + label_name[y_test[i][0]]
    plt.text(1, 40, textstr, fontsize=14)
    plt.subplots_adjust(bottom=0.25)
    plt.show()

Clone this wiki locally