

์ฌ๊ธฐ์๋ง ์ปค์ ์ด๊ธฐ
251224 ์๊ธ์จ MNIST ๋ฅผ ํ์ดํ ์น๋ก ๊ตฌํํ๊ธฐ.

์ฌ๊ธฐ์ ์์ง์ผ๋ก ๋ค์ด๋ฐ๊ธฐ
MNIST Dataset
The MNIST database of handwritten digits (http://yann.lecun.com)
www.kaggle.com
๋์คํธ | TensorFlow Datasets
๋์คํธ | TensorFlow Datasets
์ด ํ์ด์ง๋ Cloud Translation API๋ฅผ ํตํด ๋ฒ์ญ๋์์ต๋๋ค. ๋์คํธ ์ปฌ๋ ์ ์ ์ฌ์ฉํด ์ ๋ฆฌํ๊ธฐ ๋ด ํ๊ฒฝ์ค์ ์ ๊ธฐ์ค์ผ๋ก ์ฝํ ์ธ ๋ฅผ ์ ์ฅํ๊ณ ๋ถ๋ฅํ์ธ์. ์์ผ๋ก ์ด ์ซ์์ MNIST ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋๋ค. ๋
www.tensorflow.org
ํ ์ํ๋ก ์ฐธ์กฐ ๋งํฌ

์์ง ๋ฐ์ ๊ฒ ์ค์ ์ด๋ ๊ฒ ํ๊ธฐ

์ฐ์ ๊ณต ํ์ผ๊ณผ ํด๋ ๋ง๋ค๊ธฐ
์ฌ๊ธฐ์
# ๋จธ์ ๋ฌ๋ ํ์ต์ Hello World ์ ๊ฐ์ MNIST(์๊ธ์จ ์ซ์ ์ธ์) ๋ฌธ์ ๋ฅผ ์ ๊ฒฝ๋ง์ผ๋ก ํ์ด๋ด ๋๋ค. import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # ํ ์ํ๋ก์ฐ์ ๊ธฐ๋ณธ ๋ด์ฅ๋ mnist ๋ชจ๋์ ์ด์ฉํ์ฌ ๋ฐ์ดํฐ๋ฅผ ๋ก๋ํฉ๋๋ค. # ์ง์ ํ ํด๋์ MNIST ๋ฐ์ดํฐ๊ฐ ์๋ ๊ฒฝ์ฐ ์๋์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ๋ค์ด๋ก๋ํฉ๋๋ค. # one_hot ์ต์ ์ ๋ ์ด๋ธ์ ๋๋ฌผ ๋ถ๋ฅ ์์ ์์ ๋ณด์๋ one_hot ๋ฐฉ์์ ๋ฐ์ดํฐ๋ก ๋ง๋ค์ด์ค๋๋ค. mnist = input_data.read_data_sets("./mnist/data/", one_hot=True) # MNIST ๋ฐ์ดํฐ๋ฅผ ๋ค์ด๋ก๋ ํ๋ค. from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) ######### # ์ ๊ฒฝ๋ง ๋ชจ๋ธ ๊ตฌ์ฑ ###### # ์ ๋ ฅ ๊ฐ์ ์ฐจ์์ [๋ฐฐ์นํฌ๊ธฐ, ํน์ฑ๊ฐ] ์ผ๋ก ๋์ด ์์ต๋๋ค. # ์๊ธ์จ ์ด๋ฏธ์ง๋ 28x28 ํฝ์ ๋ก ์ด๋ฃจ์ด์ ธ ์๊ณ , ์ด๋ฅผ 784๊ฐ์ ํน์ฑ๊ฐ์ผ๋ก ์ ํฉ๋๋ค. X = tf.placeholder(tf.float32, [None, 784]) # ๊ฒฐ๊ณผ๋ 0~9 ์ 10 ๊ฐ์ง ๋ถ๋ฅ๋ฅผ ๊ฐ์ง๋๋ค. Y = tf.placeholder(tf.float32, [None, 10]) # ์ ๊ฒฝ๋ง์ ๋ ์ด์ด๋ ๋ค์์ฒ๋ผ ๊ตฌ์ฑํฉ๋๋ค. # 784(์ ๋ ฅ ํน์ฑ๊ฐ) # -> 256 (ํ๋ ๋ ์ด์ด ๋ด๋ฐ ๊ฐฏ์) -> 256 (ํ๋ ๋ ์ด์ด ๋ด๋ฐ ๊ฐฏ์) # -> 10 (๊ฒฐ๊ณผ๊ฐ 0~9 ๋ถ๋ฅ) W1 = tf.Variable(tf.random_normal([784, 256], stddev=0.01)) # ์ ๋ ฅ๊ฐ์ ๊ฐ์ค์น๋ฅผ ๊ณฑํ๊ณ ReLU ํจ์๋ฅผ ์ด์ฉํ์ฌ ๋ ์ด์ด๋ฅผ ๋ง๋ญ๋๋ค. L1 = tf.nn.relu(tf.matmul(X, W1)) W2 = tf.Variable(tf.random_normal([256, 256], stddev=0.01)) # L1 ๋ ์ด์ด์ ์ถ๋ ฅ๊ฐ์ ๊ฐ์ค์น๋ฅผ ๊ณฑํ๊ณ ReLU ํจ์๋ฅผ ์ด์ฉํ์ฌ ๋ ์ด์ด๋ฅผ ๋ง๋ญ๋๋ค. L2 = tf.nn.relu(tf.matmul(L1, W2)) W3 = tf.Variable(tf.random_normal([256, 10], stddev=0.01)) # ์ต์ข ๋ชจ๋ธ์ ์ถ๋ ฅ๊ฐ์ W3 ๋ณ์๋ฅผ ๊ณฑํด 10๊ฐ์ ๋ถ๋ฅ๋ฅผ ๊ฐ์ง๊ฒ ๋ฉ๋๋ค. model = tf.matmul(L2, W3) cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(logits=model, labels=Y)) optimizer = tf.train.AdamOptimizer(0.001).minimize(cost) ######### # ์ ๊ฒฝ๋ง ๋ชจ๋ธ ํ์ต ###### init = tf.global_variables_initializer() sess = tf.Session() sess.run(init) batch_size = 100 total_batch = int(mnist.train.num_examples / batch_size) for epoch in range(15): total_cost = 0 for i in range(total_batch): # ํ ์ํ๋ก์ฐ์ mnist ๋ชจ๋ธ์ next_batch ํจ์๋ฅผ ์ด์ฉํด # ์ง์ ํ ํฌ๊ธฐ๋งํผ ํ์ตํ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ต๋๋ค. batch_xs, batch_ys = mnist.train.next_batch(batch_size) _, cost_val = sess.run([optimizer, cost], feed_dict={X: batch_xs, Y: batch_ys}) total_cost += cost_val print('Epoch:', '%04d' % (epoch + 1), 'Avg. cost =', '{:.3f}'.format(total_cost / total_batch)) print('์ต์ ํ ์๋ฃ!') ######### # ๊ฒฐ๊ณผ ํ์ธ ###### # model ๋ก ์์ธกํ ๊ฐ๊ณผ ์ค์ ๋ ์ด๋ธ์ธ Y์ ๊ฐ์ ๋น๊ตํฉ๋๋ค. # tf.argmax ํจ์๋ฅผ ์ด์ฉํด ์์ธกํ ๊ฐ์์ ๊ฐ์ฅ ํฐ ๊ฐ์ ์์ธกํ ๋ ์ด๋ธ์ด๋ผ๊ณ ํ๊ฐํฉ๋๋ค. # ์) [0.1 0 0 0.7 0 0.2 0 0 0 0] -> 3 is_correct = tf.equal(tf.argmax(model, 1), tf.argmax(Y, 1)) accuracy = tf.reduce_mean(tf.cast(is_correct, tf.float32)) print('์ ํ๋:', sess.run(accuracy, feed_dict={X: mnist.test.images, Y: mnist.test.labels}))
---> ์ด ๋ฒ์ ์ ํ ์ํ๋ก ๋ฒ์ ์ด๊ณ ํ์ดํ ์น ๋ฒ์ ์ ๋ง์ถฐ์, ์ซ์์ธ์ํ๋ ์ฝ๋๋ก ๋ณ๊ฒฝํด์ค. ์คํ์ _main_์ผ๋ก ํด์ค
@app/mnist/number_recognition.py ์ด ํ์ผ๋ง ์คํํด์ค
python app/mnist/number_recognition.py
--๋์ค์๋ ์ง์ ์ ๋ ฅํ๊ธฐ
ํจ์ _์ ๋์คํธ | TensorFlow Datasets
ํจ์ _์ ๋์คํธ | TensorFlow Datasets
์ด ํ์ด์ง๋ Cloud Translation API๋ฅผ ํตํด ๋ฒ์ญ๋์์ต๋๋ค. ํจ์ _์ ๋์คํธ ์ปฌ๋ ์ ์ ์ฌ์ฉํด ์ ๋ฆฌํ๊ธฐ ๋ด ํ๊ฒฝ์ค์ ์ ๊ธฐ์ค์ผ๋ก ์ฝํ ์ธ ๋ฅผ ์ ์ฅํ๊ณ ๋ถ๋ฅํ์ธ์. Fashion-MNIST๋ 60,000๊ฐ์ ์์ ๋ก ๊ตฌ์ฑ๋
www.tensorflow.org
์ฌ๊ธฐ ๋ค์ด๊ฐ๊ธฐ
zalandoresearch/fashion-mnist: A MNIST-like fashion product database. Benchmark
GitHub - zalandoresearch/fashion-mnist: A MNIST-like fashion product database. Benchmark
A MNIST-like fashion product database. Benchmark :point_down: - GitHub - zalandoresearch/fashion-mnist: A MNIST-like fashion product database. Benchmark
github.com
์ด๊ฑธ ๊น ํด๋ก ํ๊ธฐ


์์ง ํ๊ธฐ
4๊ฐ ํ์ผ ๋ฃ์ด๋๊ธฐ

์ฌ๊ธฐ์
import tensorflow as tf
from tensorflow import keras
import matplotlib.pyplot as plt
import numpy as np
class MnistTest:
def __init__(self):
self.class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
def create_model(self) -> []:
fashion_mnist = http://keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
# print('ํ: %d, ์ด: %d' % (train_images.shape[0], train_images.shape[1]))
# print('ํ: %d, ์ด: %d' % (test_images.shape[0], test_images.shape[1]))
# plt.figure()
# plt.imshow(train_images[3])
# plt.colorbar()
# plt.grid(False)
# http://plt.show()
train_images = train_images / 255.0
test_images = test_images / 255.0
plt.figure(figsize=(10, 10))
for i in range(25):
plt.subplot(5, 5, i + 1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(train_images[i], cmap=http://plt.cm.binary)
plt.xlabel(self.class_names[train_labels[i]])
# http://plt.show()
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(128, activation='relu'),
keras.layers.Dense(10, activation='softmax')
])
"""
relu ( Recitified Linear Unit ์ ๋ฅํ ์ ํ ์ ๋)
๋ฏธ๋ถ ๊ฐ๋ฅํ 0๊ณผ 1์ฌ์ด์ ๊ฐ์ ๊ฐ๋๋ก ํ๋ ์๊ณ ๋ฆฌ์ฆ
softmax
nn (neural network )์ ์ต์์์ธต์์ ์ฌ์ฉ๋๋ฉฐ classfication ์ ์ํ function
๊ฒฐ๊ณผ๋ฅผ ํ๋ฅ ๊ฐ์ผ๋ก ํด์ํ๊ธฐ ์ํ ์๊ณ ๋ฆฌ์ฆ
"""
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
# learning
http://model.fit(train_images, train_labels, epochs=5)
# test
test_loss, test_acc = model.evaluate(test_images, test_labels)
print('\n ํ
์คํธ ์ ํ๋: ', test_acc)
# prediction
predictions = model.predict(test_images)
print(predictions[3])
# 10๊ฐ ํด๋์ค์ ๋ํ ์์ธก์ ๊ทธ๋ํํ
arr = [predictions,test_labels,test_images]
return arr
def plot_image(self, i, predictions_array, true_label, img)->[]:
print(' === plot_image ๋ก ์ง์
===')
predictions_array, true_label, img = predictions_array[i], true_label[i], img[i]
plt.grid(False)
plt.xticks([])
plt.yticks([])
plt.imshow(img, cmap=http://plt.cm.binary)
# http://plt.show()
predicted_label = np.argmax(predictions_array)
if predicted_label == true_label:
color = 'blue'
else:
color = 'red'
plt.xlabel("{} {:2.0f}% ({})".format(self.class_names[predicted_label],
100 * np.max(predictions_array),
self.class_names[true_label]),
color=color)
@staticmethod
def plot_value_array(i, predictions_array, true_label):
predictions_array, true_label = predictions_array[i], true_label[i]
plt.grid(False)
plt.xticks([])
plt.yticks([])
thisplot = http://plt.bar(range(10), predictions_array, color="#777777")
plt.ylim([0, 1])
predicted_label = np.argmax(predictions_array)
thisplot[predicted_label].set_color('red')
thisplot[true_label].set_color('blue')
---> ์ด ๋ฒ์ ์ ํ ์ํ๋ก ๋ฒ์ ์ด๊ณ ํ์ดํ ์น ๋ฒ์ ์ ๋ง์ถฐ์, ํจ์ ์ธ์ํ๋ ์ฝ๋๋ก ๋ณ๊ฒฝํด์ค. ์คํ์ __main__์ผ๋ก ํ๋๋ก ํด์ค
python app/mnist/fashion_recognition.py

Discover Ultralytics YOLO models | State-of-the-Art Computer Vision
Discover Ultralytics YOLO models | State-of-the-Art Computer Vision
Explore Ultralytics YOLO models - a state-of-the-art AI architecture designed for highly-accurate vision AI modeling. Ideal for businesses, academics, tech-users, and AI enthusiasts.
www.ultralytics.com



๊ณตํ์ผ ๋ง๋ค๊ธฐ
detect ํ์ผ์ด ์๋์ผ๋ก ๋ง๋ค์ด์ง
๊ฑฐ๊ธฐ์ ์ด ๋ด์ฉ ๋ฃ๊ณ ํ๋กฌํํธ ๋ฃ๊ธฐ
@face_detect.py (5-6) ์ด ํ์ผ์ ๊ฒฝ๋ก๋ฅผ ์ด๋ฏธ์ง๋ฅผ ์ฐธ์กฐํด์ ๋๊ฐ ์ค์ ํด์ค


python face_detect.py

์ผ๊ตด์ด ๋ฝ ๋ธ!
์ผ๊ตด ์ฌ์ง์ผ๋ก ๋์ด์์ด์ผํจ
def mosaic(img, rect, size): (x1, y1, x2, y2) = rect w = x2 - x1 h = y2 - y1 i_rect = img[y1:y2, x1:x2] i_small = cv2.resize(i_rect, (size, size)) i_mos = cv2.resize(i_small, (w, h), interpolation=cv2.INTER_AREA) img2 = img.copy() img2[y1:y2, x1:x2] = i_mos return img2
-- ๋ชจ์์ดํฌ ์ถ๊ฐ
์ด๋ฏธ์ง ์์ฑํ๊ธฐ, ๋ชจ์์ดํฌ ํ๊ธฐ
'Project ESG+AI > [์ผ์ KPMG]ESG ๋ฐ์ดํฐ ํ์ฉ ํ์คํ ๊ฐ๋ฐ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| 65์ผ์ฐจ. (1) | 2026.01.16 |
|---|---|
| 49์ผ์ฐจ. (0) | 2025.12.19 |
| 47์ผ์ฐจ. ํ๋ก์ ํธ์ ๋ง์ถฐ์ AI ๋ชจ๋ธ ์ ํํ๊ณ ์ค์ ํ๊ธฐ (1) | 2025.12.18 |
| 46์ผ์ฐจ. (1) | 2025.12.16 |
| 45์ผ์ฐจ. (0) | 2025.12.15 |