(์ด๋ฒ ํ๋ก์ ํธ ์ฝ๋๋ ํจ์บ ๋ฅ๋ฌ๋ ๊ฐ์๋ฅผ ์ฐธ๊ณ ํ ์ฝ๋์ด๋ค)
์ค๋ ์์๋ณผ ๋ฐ์ดํฐ๋ ๋ฅ๋ฌ๋ ์ ๋ฌธ ๋ ๋ฌด์กฐ๊ฑด ๋ฐฐ์ฐ๋ ์ ๋ช ํ ์ด๋ฏธ์ง ๋ฐ์ดํฐ์ธ MNIST ๋ฐ์ดํฐ์ ์ด๋ค.
์ฌ์ง๊ณผ ๊ฐ์ด ์์ผ๋ก ์ง์ ์ด ์ซ์๋ค๋ก ์ด๋ฃจ์ด์ง ๋ํ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ด๋ค. ์ด๋ฒ ๋ฅ๋ฌ๋ ์ฒซ ํ๋ก์ ํธ๋ก๋ RNN์ผ๋ก MNIST๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฅํด๋ด๋ ์์ ์ ์งํํ ๊ฒ์ด๋ค.
<MNIST ๋ฐ์ดํฐ ๋ค์ด๋ฐ๊ธฐ>
http://yann.lecun.com/exdb/mnist/
MNIST handwritten digit database, Yann LeCun, Corinna Cortes and Chris Burges
yann.lecun.com
์ฌ๊ธฐ์ ๋ฐ์ดํฐ๋ฅผ ๋ค์ด๋ฐ์ ์ ์๋ค.
๋๋ ์ฌ์ดํธ์์ ๋ค์ด๋ฐ์ง ์๊ณ , keras์ dataset์์ ์ง์ํด์ฃผ๋ ์ฌ๋ฌ ๋ฐ์ดํฐ๋ค ์ค MNIST๋ ์๊ธฐ ๋๋ฌธ์ ์ฝ๋๋ก ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์ฌ ๊ฒ์ด๋ค.
(1) mnist ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐ
mnist = keras.datasets.mnist
((train_images, train_labels), (test_images, test_labels) = mnist.load_data()
(2) MNIST ๋ฐ์ดํฐ ํฌ๊ธฐ ์์๋ณด๊ธฐ
print(f"train_images: {train_images.shape}")
print(f"train_labels: {train_labels.shape}")
print(f"test__images: {test_images.shape}")
print(f"test_labels: {test_labels.shape}")
๋ฐ์ดํฐ ํฌ๊ธฐ๋ shape์ผ๋ก ์์๋ณผ ์ ์๋ค. ์์๊ฐ์ด ์ถ๋ ฅํ๋ฉด train image๋ ์ด 60000์ฅ, test image๋ ์ด 10000์ฅ์ผ๋ก ๊ตฌ์ฑ๋ ๊ฒ์ ์ ์ ์๋ค.
์ด๋ฏธ์ง๊ฐ (60000, 28, 28) ์ธ ๊ฒ์ ์ด 60000์ฅ, ํฌ๊ธฐ๊ฐ 28x28์ธ ์ด๋ฏธ์ง๋ผ๋ ๋ป์ด๋ค.
(3) ์ฌ์ง ์ถ๋ ฅํด๋ณด๊ธฐ
plt.figure()
plt.imshow(train_images[7777], cmap='gray') # ์ด๋ฏธ์ง ์๊ฐํ, ํ๋ฐฑ์ผ๋ก ์ถ๋ ฅ
plt.colorbar() # ์ฐ์ธก ์ปฌ๋ฌ๋ฐ ์์ฑ
plt.grid(True) # grid ์์ฑ
plt.show()
print(train_labels[7777]) # ๋ผ๋ฒจ ์ถ๋ ฅ
7์ ์ข์ํ๊ธฐ ๋๋ฌธ์ 7777๋ฒ์งธ ์ฌ์ง์ ์ถ๋ ฅํด ๋ดค๋ค.
๊ทธ๋ฌ๋๋ ์ด๋ฐ ๊ทธ๋ฆผ์ด ๋์๋ค. 8์ฒ๋ผ ์๊ฒผ๊ณ , ๋ผ๋ฒจ์ ์ถ๋ ฅํ ๊ฒฐ๊ณผ๋ 8์ด ๋์๋ค.
(4) MNIST ๋ฐ์ดํฐ์ ์ data type ์์๋ณด๊ธฐ
print(train_images.dtype)
print(train_labels.dtype)
print(test_images.dtype)
print(test_labels.dtype)
data์ type์ ์๊ธฐ ์ํด dtype์ ์ฌ์ฉํด์ค๋ค. ์์ ๊ฐ์ด ์ถ๋ ฅํ๋ฉด ๋ชจ๋ uint8 ์ด ๋์ค๋ ๊ฒ์ ์ ์ ์๋ค. uint8์ด ๋ฌด์จ ํ์ ์ธ์ง ๊ถ๊ธํด์ ๊ตฌ๊ธ๋ง ํด๋ณด์๋๋ unsigned interger ์ด๋ฏ๋ก ์์๋ง ํํํ๋ ํ์ ์ด๋ฉฐ, 0-255 ์ฌ์ด์ ์ ์ํ ํ์ ์ด๋ค. 2^8 ๊ฐ์๋งํผ ํํ์ด ๊ฐ๋ฅํ๋ค.
numpy๊ด๋ จ data type ์ฐธ๊ณ ์๋ฃ
https://numpy.org/doc/stable/user/basics.types.html
Data types — NumPy v1.20 Manual
Array Scalars NumPy generally returns elements of arrays as array scalars (a scalar with an associated dtype). Array scalars differ from Python scalars, but for the most part they can be used interchangeably (the primary exception is for versions of Python
numpy.org
์ฌ๊ธฐ๊น์ง MNIST๋ฐ์ดํฐ์ ๋ํ์ฌ ์์๋ณด์๋ค. ์ด ์ ๋ฆฌํ์๋ฉด train 60000์ฅ ํฌ๊ธฐ 28x28, test 10000์ฅ ํฌ๊ธฐ 28x28 ์ธ ์๊ธ์จ ๋ฐ์ดํฐ์ ์ด๋ค. ๊ธฐ๋ณธ data type์ uint8์์ ์ ์ ์๋ค.
๋ฅ๋ฌ๋ ํ๋ก์ ํธ๋ฅผ ์งํ์ ํ๋ฉฐ ์ฌ๋ฌ ๋ฐ์ดํฐ์ ์ ๋ถ์ํด ๋ณผ๊ฒ์ด์ง๋ง ๋ฐ์ดํฐ์ ๊ณผ ์นํด์ง๋ ๊ฒ๋ ์ค์ํ ๋ถ๋ถ์ธ ๊ฒ ๊ฐ์ ๋ฐ๋ก ํฌ์คํ ์ ํ๋ค. ์ด์ ๋ค์์๋ MNIST ๋ฐ์ดํฐ๋ฅผ ๋ ์์ธํ ์์๋ณด๊ณ ์ ์ฒ๋ฆฌ ํ๋ฉฐ ๋ชจ๋ธ๋ง์ ํ ์ ์๋ ์ํ๋ก ๋ง๋ค์ด์ฃผ๋ ํฌ์คํ ์ ํ ์์ ์ด๋ค.
'๋ฐ์ดํฐ ๋ถ์ ์ด๋ก > ๋ฅ๋ฌ๋' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[celeba ํ๋ก์ ํธ] 2. celeba ๋ฐ์ดํฐ์ ์ ์ฒ๋ฆฌ, ์๊ฐํ (0) | 2021.06.07 |
---|---|
[celeba ํ๋ก์ ํธ] 1. celeba ๋ฐ์ดํฐ ์ดํด๋ณด๊ธฐ (0) | 2021.06.07 |
[MNIST ํ๋ก์ ํธ] 3. Noise ์ถ๊ฐ, RNN ๋ชจ๋ธ๋ง (0) | 2021.06.07 |
[MNIST ํ๋ก์ ํธ] 2. MNIST ๋ฐ์ดํฐ์ ์ ์ฒ๋ฆฌ, ์๊ฐํ (0) | 2021.06.07 |
๋ฅ๋ฌ๋์ ๋ํ์ฌ (0) | 2021.05.24 |