'20 JUN : ์ง์ ๋ฒ์ญํ๋ฉฐ ์์ ํ colab ๋ ธํธ๋ถ ๋งํฌ๋ฅผ ์ ์คํด์ ์์ง ์งํ์ค์ ๋๋ค.
---
์ ์ถ์ฒ : https://machinelearningmastery.com/develop-a-caption-generation-model-in-keras/
By Jason Brownlee on Nov 24, 2017 / Last updated on Aug 7, 2019
How to Use Small Experiments to Develop a Caption Generation Model in Keras
Caption generation is a challenging artificial intelligence problem where a textual description must be generated for a photograph. It requires both methods from computer vision to understand the content of the image and a language model from the field of
machinelearningmastery.com
* ์๋ ๊ธ์ ์ ์ด์จ ๋ธ๋ผ์ด๋ฆฌ์ "Keras์์ ์บก์ ์์ฑ ๋ชจ๋ธ์ ๋ง๋๋ ๋ฒ"์ ๋ฒ์ญํ ๊ธ์ ๋๋ค.
์บก์ ์์ฑ์ ์ฌ์ง์ ๋ํ ์ค๋ช ์ ๋ง๋ค์ด๋ด๋, ์ด๋ ค์ด ์ธ๊ณต์ง๋ฅ ๋ฌธ์ ์ ๋๋ค. ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด์๋ ์ด๋ฏธ์ง์ ์ฝํ ํธ๋ฅผ ์ดํดํ๋ ์ปดํจํฐ ๋น์ ๊ณผ ์์ฐ์ด์ฒ๋ฆฌ ๋ถ์ผ์์ ์ด๋ฏธ์ง์ ๋ํด ์ดํดํ ๋ด์ฉ์ ์ฌ๋ฐ๋ฅธ ์์์ ๋จ์ด๋ก ์นํํ๋ ๋ญ๊ท์ง ๋ชจ๋ธ์ด ํ์ํฉ๋๋ค. ์ต๊ทผ ๋ฅ๋ฌ๋์ผ๋ก ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ์ต์ ์ ๊ฒฐ๊ณผ๋ฌผ์ ๋ฌ์ฑํ์ต๋๋ค.
์ง์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ง๊ณ ์บก์ ์์ฑ ๋ชจ๋ธ์ ๊ฐ๋ฐํ๋ ๊ฒ์ ๋งค์ฐ ์ด๋ ค์ธ ์ ์์ต๋๋ค. ์ฃผ๋ก ๋ฐ์ดํฐ์ ๊ณผ ๋ชจ๋ธ์ด ๋๋ฌด ํฌ๊ธฐ ๋๋ฌธ์ ํธ๋ ์ธ์ ํ๋ ๋ฐ์ ์์ผ์ด ๊ฑธ๋ฆฌ๊ธฐ ๋๋ฌธ์ ๋๋ค. ์ด์ ๋ํ ๋์์ผ๋ก fuller ๋ฐ์ดํฐ์ ์ ์์ ์ํ๋ก ๋ชจ๋ธ configuration์ ํ์ํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค.
์ด ํํ ๋ฆฌ์ผ์์๋ ํ์ค ์ฌ์ง ์บก์ ๋ฐ์ดํฐ์ ์ ์ ์ ์ํ์ ์ด์ฉํ์ฌ ๋ค์ํ ๋ฅ๋ชจ๋ธ ๋์์ธ์ ํ์ํ๋ ๋ฐฉ๋ฒ์ ์์๋ณผ ๊ฒ์ ๋๋ค. ํํ ๋ฆฌ์ผ์ ๋๋ด๋ฉด ์ด๋ค ๊ฒ๋ค์ ์๊ฒ๋ ๊น์?
* ์ฌ์ง ์บก์ ์์ฑ ๋ชจ๋ธ๋ง์ ์ํด ๋ฐ์ดํฐ๋ฅผ ์ค๋นํ๋ ๋ฐฉ๋ฒ
* ๋ชจ๋ธ์ ์คํฌ์ ํ๊ฐํ๊ณ ํ๋ฅ ์ ํน์ฑ์ ์ ์ดํ๊ธฐ ์ํ ๋ฒ ์ด์ค๋ผ์ธ๊ณผ ํ ์คํธ ํ๋ค์ค๋ฅผ ์ค๊ณํ๋ ๋ฒ
* ๋ชจ๋ธ์ ์คํฌ, ํน์ง ์ถ์ถ ๋ชจ๋ธ, ์๋ ์๋ฒ ๋ฉ ๋ฑ ๋ชจ๋ธ์ ์คํฌ์ ํฅ์์ํค๊ธฐ ์ํ ํ๋กํผํฐ๋ฅผ ํ๊ฐํ๋ ๋ฐฉ๋ฒ
ํ ์คํธ ๋ถ๋ฅ, ๋ฒ์ญ, ์ฌ์ง ์บก์ ์์ฑ, ๋ฅ๋ฌ๋ ๋ชจ๋ธ์ ๊ฐ๋ฐํ๋ ๋ง์ ๋ฐฉ๋ฒ์ ์ ์ ์ ์ฑ ์์ ๋ง๋๋ณด์ธ์. 30๊ฐ์ง์ ๋จ๊ณ๋ณ ํํ ๋ฆฌ์ผ๊ณผ ์์ค์ฝ๋๋ ํฌํจ๋์ด ์์ต๋๋ค.
https://machinelearningmastery.com/deep-learning-for-nlp/
Deep Learning For Natural Language Processing
Deep Learning for Natural Language Processing Develop Deep Learning Models for your Natural Language Problems Working with Text is… important, under-discussed, and HARD We are awash with text, from books, papers, blogs, tweets, news, and increasingly text
machinelearningmastery.com
ํํ ๋ฆฌ์ผ ๊ฐ์
์ด ํํ ๋ฆฌ์ผ์ ์ด 6๊ฐ์ ๋ถ๋ถ์ผ๋ก ๋์ด์์ต๋๋ค.
1. ๋ฐ์ดํฐ ์ค๋น
2. ๋ฒ ์ด์ค ๋ผ์ธ ์บก์ ์์ฑ ๋ชจ๋ธ
3. ๋คํธ์ํฌ ์ฌ์ด์ฆ ํ๋ผ๋ฏธํฐ
4. ํผ์ณ ์ถ์ถ ๋ชจ๋ธ Configuring
5. ์๋ ์๋ฒ ๋ฉ ๋ชจ๋ธ
6. ๊ฒฐ๊ณผ ๋ถ์
ํ์ด์ฌ ํ๊ฒฝ
Python3์ Scipy. Scikit-learn, Pandas, Numpy, Matplotlib
Tensorflow์ Theano ๋ฐฑ์๋, Keras(2.0์ด์) ์ค์น๋์ด์์ด์ผ ํฉ๋๋ค.
ํ๊ฒฝ์ค์ ์ ๋ํด ๋์์ด ํ์ํ๋ค๋ฉด ์๋ ํํ ๋ฆฌ์ผ์ ์ฐธ๊ณ ํ์ธ์.
์๋์ฝ๋ค๋ก ๋จธ์ ๋ฌ๋๊ณผ ๋ฅ๋ฌ๋์ ์ํ ํ์ด์ฌ ํ๊ฒฝ ์ค์ ํ๋ ๋ฐฉ๋ฒ
https://machinelearningmastery.com/setup-python-environment-machine-learning-deep-learning-anaconda/
How to Setup Your Python Environment for Machine Learning with Anaconda
It can be difficult to install a Python machine learning environment on some platforms. Python itself must be installed first and then there are many packages to install, and it can be confusing for beginners. In this tutorial, you will discover how to set
machinelearningmastery.com
GPU ํ๊ฒฝ์์ ์ฝ๋๋ฅผ ๋๋ฆด ๊ฒ์ ์ถ์ฒํฉ๋๋ค. ์๋ง์กด ์น์๋น์ค์์ ์ ๋ ดํ ๊ฐ๊ฒฉ์ผ๋ก GPU์ ์ ์ํ ์ ์์ต๋๋ค. ์๋ ํํ ๋ฆฌ์ผ์ ์ฐธ๊ณ ํ์ธ์.
์๋ง์กด ์น์๋น์ค์์ ์ผ๋ผ์ค๋ฅผ ์ฌ์ฉํ์ฌ ๋๊ท๋ชจ์ ๋ฅ๋ฌ๋๋ชจ๋ธ์ ํ๊ฐํ๊ณ ๊ฐ๋ฐํ๋ ๋ฐฉ๋ฒ
How to Train Keras Deep Learning Models on AWS EC2 GPUs (step-by-step)
Keras is a Python deep learning library that provides easy and convenient access to the powerful numerical libraries like TensorFlow. Large deep learning models require a lot of compute time to run. You can run them on your CPU but it can take hours or day
machinelearningmastery.com
1. ๋ฐ์ดํฐ ์ค๋น
๋ชจ๋ธ์ ํธ๋ ์ด๋ ํ๊ธฐ ์ํธ ๋ฐ์ดํฐ์ ์ ๋จผ์ ์ค๋นํด์ผ ํฉ๋๋ค. ์ฝ 8,000์ฅ์ด ๋๋ ์ฌ์ง๊ณผ ์ค๋ช ์ผ๋ก ๊ตฌ์ฑ๋ Flickr8K ๋ฐ์ดํฐ์ ์ ์ฌ์ฉํด ๋ณผ ๊ฒ์ ๋๋ค. ๋ฐ์ดํฐ์ ์ ์๋์์ ๋ค์ด๋ฐ์ ์ ์์ต๋๋ค.
* ๋ฐ์ดํฐ์ ๊ณผ ํ ์คํธ (์ ๋ฐ์ดํธ : ๊ณต์ ์ฌ์ดํธ์์ ๋งํฌ๊ฐ ๋ด๋ ค๊ฐ์ ์ ์์ ๊นํ๋ธ ๋ ํฌ์์ ๋ฐ๋ก ๋ค์ด๋ฐ์ ์ ์๋ ๋งํฌ๋ฅผ ์ฒจ๋ถํฉ๋๋ค.)
https://github.com/jbrownlee/Datasets/releases/download/Flickr8k/Flickr8k_Dataset.zip
https://github.com/jbrownlee/Datasets/releases/download/Flickr8k/Flickr8k_text.zip
์์ ํ๊ณ ์๋ ๋๋ ํ ๋ฆฌ์ ์ฌ์ง๊ณผ ์ค๋ช ๋ฐ์ดํฐ์ ์์ถ์ ํ๊ณ ๊ฐ๊ฐ Flicker8k_Dataset, Flickr8k_text ํด๋์ ์ ์ฅํฉ๋๋ค.
๋ฐ์ดํฐ ์ค๋น์๋ ์ฌ์ง๊ณผ ํ ์คํธ ๊ฐ๊ฐ ๋๊ฐ์ง ๊ณผ์ ์ด ์์ต๋๋ค.
1-1 ํ ์คํธ ์ค๋น (๊ด์ฐฎ์ ํํ์ด ์๋ค๋ฉด ๋๊ธ๋ก ๋ถํ๋๋ฆฝ๋๋ค.)
๋ฐ์ดํฐ์ ์๋ ๊ฐ ์ฌ์ง์ ๋ํ ์ฌ๋ฌ ๋์คํฌ๋ฆฝ์ ์ด ํฌํจ๋์ด ์์ต๋๋ค. ์ค๋ช ํ ์คํธ์ ์ฝ๊ฐ์ ์ ์ ๊ณผ์ ์ ๊ฑฐ์น ๊ฒ์ ๋๋ค. ๋จผ์ ๋์คํฌ๋ฆฝ์ ์ด ํฌํจ๋ ํ์ผ์ ๋ชจ๋ ๋ถ๋ฌ์ฌ ๊ฒ์ ๋๋ค.
# load doc into memory ๋ฌธ์๋ฅผ ๋ฉ๋ชจ๋ฆฌ์ ๋ก๋
def load_doc(filename):
# open the file as read only ํ์ผ์ ์ฝ๊ธฐ์ ์ฉ์ผ๋ก ์ด๊ธฐ
file = open(filename, 'r')
# read all text ๋ชจ๋ ํ
์คํธ๋ฅผ ์ฝ๊ธฐ
text = file.read()
# close the file ํ์ผ ๋ซ๊ธฐ
file.close()
return text
filename = 'Flickr8k_text/Flickr8k.token.txt'
# load descriptions ๋์คํฌ๋ฆฝ์
๋ถ๋ฌ์ค๊ธฐ
doc = load_doc(filename)
๊ฐ ์ฌ์ง์๋ ๊ณ ์ ์ ์๋ณ์๊ฐ ์๊ณ , ์ฌ์ง ํ์ผ์ ์ด๋ฆ๊ณผ ์ค๋ช ํ ์คํธ ํ์ผ์์ ์ฌ์ฉ๋ฉ๋๋ค. ๋ค์์ผ๋ก ์ฌ์ง์ ๋ํ ์ค๋ช ๋ชฉ๋ก์ ์ดํด๋ณด๊ณ , ๊ฐ ์ฌ์ง์ ๋ํ ์ฒซ๋ฒ์งธ ์ค๋ช ์ ์ ์ฅํฉ๋๋ค.
์๋์์๋ load_descriptions() ๋ผ๋ ํจ์๋ฅผ ์ ์ํ์ฌ, ๋ก๋๋ ๋ฌธ์ ํ ์คํธ๊ฐ ์ฃผ์ด์ง ๋ ๋์คํฌ๋ฆฝ์ ์, ์ฌ์ง ์๋ณ์๋ฅผ ๋์ ๋๋ฆฌ ํํ๋ก ๋ฐํํ๋ ๊ณผ์ ์ ๊ฑฐ์น ๊ฒ์ ๋๋ค.
# extract descriptions for images
def load_descriptions(doc):
mapping = dict()
# process lines
for line in doc.split('\n'):
# split line by white space
tokens = line.split()
if len(line) < 2:
continue
# take the first token as the image id, the rest as the description
image_id, image_desc = tokens[0], tokens[1:]
# remove filename from image id
image_id = image_id.split('.')[0]
# convert description tokens back to string
image_desc = ' '.join(image_desc)
# store the first description for each image
if image_id not in mapping:
mapping[image_id] = image_desc
return mapping
# parse descriptions
descriptions = load_descriptions(doc)
print('Loaded: %d ' % len(descriptions))
1-2 ์ฌ์ง ์ค๋น
๋๊ธ