(๋ณธ ํ๋ก์ ํธ ์ฝ๋๋ ํจ์บ ๋ฅ๋ฌ๋ ๊ฐ์๋ฅผ ์ฐธ๊ณ ํ ์ฝ๋์ด๋ค)
<celeb_a ๋ฐ์ดํฐ์
์ถ์ฒ>
https://www.tensorflow.org/datasets/catalog/celeb_a
celeb_a | TensorFlow Datasets
CelebFaces Attributes Dataset (CelebA)์ ๊ฐ๊ฐ 40 ๊ฐ์ ์์ฑ ์ฃผ์์ด์๋ 20 ๋ง ๊ฐ ์ด์์ ์ ๋ช ์ธ ์ด๋ฏธ์ง๊ฐ ํฌํจ ๋ ๋๊ท๋ชจ ์ผ๊ตด ์์ฑ ๋ฐ์ดํฐ ์ธํธ์ ๋๋ค. ์ด ๋ฐ์ดํฐ ์ธํธ์ ์ด๋ฏธ์ง๋ ํฐ ํฌ์ฆ ๋ณํ๊ณผ ๋ฐฐ๊ฒฝ ํผ
www.tensorflow.org
caleba ๋ฐ์ดํฐ์
์ 40๊ฐ์ ์์ฑ, 10,177๊ฐ์ ์ ์, 20๋ง๊ฐ ์ด์์ ์ ๋ช
์ธ ์ด๋ฏธ์ง๊ฐ ํฌํจ๋ ๋๊ท๋ชจ ์ผ๊ตด ์์ฑ ๋ฐ์ดํฐ์
์ด๋ค.
ํ์ฉ - ์ผ๊ตด ์์ฑ์ธ์, ์ผ๊ตด ๊ฐ์ง, ์ผ๊ตด ์์นํ์
celeba์ ์์ฑ๋ค์ ๋ค์๊ณผ ๊ฐ์ด dictionary๋ก ๊ตฌ์ฑ๋์ด ์๋ค.
FeaturesDict({
'attributes': FeaturesDict({
'5_o_Clock_Shadow': tf.bool,
'Arched_Eyebrows': tf.bool,
'Attractive': tf.bool,
'Bags_Under_Eyes': tf.bool,
'Bald': tf.bool,
'Bangs': tf.bool,
'Big_Lips': tf.bool,
'Big_Nose': tf.bool,
'Black_Hair': tf.bool,
'Blond_Hair': tf.bool,
'Blurry': tf.bool,
'Brown_Hair': tf.bool,
'Bushy_Eyebrows': tf.bool,
'Chubby': tf.bool,
'Double_Chin': tf.bool,
'Eyeglasses': tf.bool,
'Goatee': tf.bool,
'Gray_Hair': tf.bool,
'Heavy_Makeup': tf.bool,
'High_Cheekbones': tf.bool,
'Male': tf.bool,
'Mouth_Slightly_Open': tf.bool,
'Mustache': tf.bool,
'Narrow_Eyes': tf.bool,
'No_Beard': tf.bool,
'Oval_Face': tf.bool,
'Pale_Skin': tf.bool,
'Pointy_Nose': tf.bool,
'Receding_Hairline': tf.bool,
'Rosy_Cheeks': tf.bool,
'Sideburns': tf.bool,
'Smiling': tf.bool,
'Straight_Hair': tf.bool,
'Wavy_Hair': tf.bool,
'Wearing_Earrings': tf.bool,
'Wearing_Hat': tf.bool,
'Wearing_Lipstick': tf.bool,
'Wearing_Necklace': tf.bool,
'Wearing_Necktie': tf.bool,
'Young': tf.bool,
}),
'image': Image(shape=(218, 178, 3), dtype=tf.uint8),
'landmarks': FeaturesDict({
'lefteye_x': tf.int64,
'lefteye_y': tf.int64,
'leftmouth_x': tf.int64,
'leftmouth_y': tf.int64,
'nose_x': tf.int64,
'nose_y': tf.int64,
'righteye_x': tf.int64,
'righteye_y': tf.int64,
'rightmouth_x': tf.int64,
'rightmouth_y': tf.int64,
}),
})
์ฑ๋ณ, ์์ ์ฌ๋ถ, ์ ์, ์๊ฒฝ ์ฐฉ์ฉ, ๋ชจ์ ์ฐฉ์ฉ, ์จ์ด๋ธ ๋จธ๋ฆฌ, ๊ฐ์๋จธ๋ฆฌ ์ฌ๋ถ ๋ฑ๋ฑ ๋ง์ ์์ฑ๋ค์ด ์กด์ฌํ๋ค. ์ด ์ค์์ ๋ณธ ํ๋ก์ ํธ์์๋ ์ฑ๋ณ(Male)๊ณผ ์์ ์ฌ๋ถ(Smiling)๋ฅผ ๋ถ๋ฅํด ๋ด๋ ๋ชจ๋ธ์ ๋ง๋ค ๊ฒ์ด๋ค.
์์ฑ์ ๊บผ๋ผ๋๋ ['attributes']['Male'] ์ด๋ฐ์์ผ๋ก ๊บผ๋ด์ฃผ๋ฉด ๋๋ค.
์ ์ฒด ๋ฐ์ดํฐ ์
๋ค์ด๋ก๋
import tensorflow_datasets as tfds
# tfds.list_builders() -> ๋ฐ์ดํฐ์
๋ชฉ๋ก ์ ์ฒด๋ณด๊ธฐ
celeb_a = tfds.load('celeb_a') # celeb_a ๋ฐ์ดํฐ์
๋ถ๋ฌ์ค๊ธฐ
๋ณธ ํ๋ก์ ํธ์์๋ ์ถ์๋ celeba ๋ฐ์ดํฐ์
์ ์ฌ์ฉํ ๊ฒ์ด๋ค. ์ถ์ํ๋ ์ฝ๋๋ ์๋ตํ์ง๋ง, ๊ณผ์ ์ ์ ์ด๋ณด๋ฉด
1. celeb_a['validation']๊ณผ celeb_a['test'] ๋ฅผ ๊ฐ๊ฐ train, test ๋ก ํ ๋นํด์ค๋ค.
2. Male, Smiling ์์ฑ๋ง ๋ถ๋ฌ์ train_images, train_labels, test_images, test_labels๋ฅผ ์์ฑํ๋ค.
---> ์ฌ๊ธฐ์ test_images์ test_labels ๋ง ์ด์ฉํ์ฌ ๋ฐ์ดํฐ ์ถ์
3. test_images์ test_labels์์ ์๋๋จ์, ์์๋๋จ์, ์๋์ฌ์, ์์๋์ฌ์๋ฅผ ๋ถ๋ฆฌํด๋ด์ด ๊ฐ๊ฐ 550๊ฐ์ฉ ์๋ผ ๊ณ ๋ฅด๊ฒ ์ถ์ํ์ฌ ํฉํด์ง๋ค ---> ๊ทธ๋ผ ์ด 2200๊ฐ๊ฐ ๋๋ค!
4. 2200๊ฐ ์ง๋ฆฌ ๋ฐ์ดํฐ๋ฅผ ์์ด์ฃผ๊ณ , 2000๊ฐ๊น์ง train, ๋๋จธ์ง 200๊ฐ๋ test๋ก ํ ๋นํ๋ค.
5. ์ด๋ฅผ ๋ค์ train_images, train_labels, test_images, test_labels ๋ก ๋๋์ด์ฃผ๋ฉด ๋! ์ถ์ํ๋ ๊ฒ ๋ฒ๊ฑฐ๋ก์ฐ๋ฏ๋ก npzํ์ผ๋ก ์ ์ฅํด๋์.
celeba_small ๋ฐ์ดํฐ ์ดํด๋ณด๊ธฐ
(1) ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ณ train, test ๋ฐ์ดํฐ ๋๋๊ธฐ
celeba_small = np.load('./celeba_small.npz')
# ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐ
train_images = celeba_small['train_images']
train_labels = celeba_small['train_labels']
test_images = celeba_small['test_images']
test_labels = celeba_small['test_labels']
(2) ์ฌ์ง ํ์ฅ ๊บผ๋ด์ ์๊ฐํ ํด๋ณด๊ธฐ
plt.imshow(train_images[777])
plt.colorbar()
plt.show()
print(train_labels[777])
777๋ฒ์งธ ์ฌ์ง์ ๊บผ๋ด๋ณด์๋ค.
๊ฒฐ๊ณผ๋ ์ด๋ฌํ๋ค. ์๋ ๊ฒ ๊ฐ๊ธฐ๋ ํ๋ฐ ์์ง์๋ ์ฌ์๋ผ๊ณ ๋ผ๋ฒจ๋ง์ด ๋์ด์๋ค!
(3) ๋ฐ์ดํฐ์ ๋ฒ์, ํฌ๊ธฐ, ๋ฐ์ดํฐ ํ์
์์๋ณด๊ธฐ
- ๋ฒ์
# 0์ด ์๋ ์ซ์ 50๊ฐ๋ง ์ถ๋ ฅํด๋ณด๊ธฐ
train_images[train_images != 0][:50]
test_images[test_images != 0][:50]
# ๋ฐ์ดํฐ์ ์ต์๊ฐ / ์ต๋๊ฐ
print(train_images.min(), train_images.max())
print(train_labels.min(), train_labels.max())
print(test_images.min(), test_images.max())
print(test_labels.min(), test_labels.max())
50๊ฐ ์ถ๋ ฅํ ๋ฐ์ดํฐ๋ค์ ๋ชจ๋ 0๊ณผ 1์ฌ์ด์ ๊ฐ๋ค์ด์ด์ผ ํ๊ณ , ์ด๋ฏธ์ง์ ๋ฒ์๋ 0.0-1.0, ๋ผ๋ฒจ์ ๋ฒ์๋ 0-1 ์ผ๋ก ๋์ค๋ฉด ์ ์!
- ํฌ๊ธฐ
print(train_images.shape, test_images.shape)
print(train_labels.shape, test_labels.shape)
(2000, 72, 59, 3) (200, 72, 59, 3)
(2000, 2) (200, 2)
์ด์ ๊ฐ์ด ๋์ค๋ฉด ์ ์! ์ฌ์ง์ ํฌ๊ธฐ๋ฅผ ๋ฐ์ดํฐ ์ถ์ํ ๋ ์ค์ฌ์ ์๋ณธ๋ณด๋ค๋ ์๋ค. ์ ๋ฒ ํ๋ก์ ํธ mnist ์ ๋ฌ๋ฆฌ ์ฑ๋ 3์ด ์ถ๊ฐ๋์ด ์์ด ์๋ค๋ ๊ฒ์ ์ ์ ์๋ค!
- ๋ฐ์ดํฐ ํ์
print(train_images.dtype, test_images.dtype)
print(train_labels.dtype, test_labels.dtype)
float64 float64
int8 int8
์์ ๊ฐ์ด ๋์ค๋ฉด ์ ์! ์ด๊ฑธ ํตํด ์ ์ฌ์ค์ dtype์ด float64์ด๊ณ , ๋ฒ์๊ฐ 0.0 - 1.0 ์ด๋ฏ๋ก normalize๋ฅผ ์ํด์ค๋ ๋๋ค๋ ๊ฒ์ด๋ค.
๋ฒ์, ํฌ๊ธฐ, ๋ฐ์ดํฐ ํ์
์ ์์๋ก ํ์ธํ๋ ์ต๊ด์ ๊ฐ์!
๋ค์์๋ ์ ์ฒ๋ฆฌ์ ์๊ฐํ์ ๋ํ ํฌ์คํ
์ ํ ์์ ์ด๋ค.
'๋ฐ์ดํฐ ๋ถ์ ์ด๋ก > ๋ฅ๋ฌ๋' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[celeba ํ๋ก์ ํธ] 3. ๋ชจ๋ธ๋ง, ๋ฉํฐ ์์ํ ๋ชจ๋ธ๋ง (0) | 2021.06.09 |
---|---|
[celeba ํ๋ก์ ํธ] 2. celeba ๋ฐ์ดํฐ์ ์ ์ฒ๋ฆฌ, ์๊ฐํ (0) | 2021.06.07 |
[MNIST ํ๋ก์ ํธ] 3. Noise ์ถ๊ฐ, RNN ๋ชจ๋ธ๋ง (0) | 2021.06.07 |
[MNIST ํ๋ก์ ํธ] 2. MNIST ๋ฐ์ดํฐ์ ์ ์ฒ๋ฆฌ, ์๊ฐํ (0) | 2021.06.07 |
[MNIST ํ๋ก์ ํธ] 1. MNIST ๋ฐ์ดํฐ ์์๋ณด๊ธฐ (0) | 2021.06.07 |