Skip to content

dev-bearabbit/Deep-Learning-in-Julia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

์ค„๋ฆฌ์•„๋ฅผ ํ†ตํ•ด ๋”ฅ๋Ÿฌ๋‹ 100% ์ดํ•ดํ•˜๊ธฐ ํ”„๋กœ์ ํŠธ
(A project for 100% understanding Deep Learning in Julia)

ํ•ด๋‹น ํ”„๋กœ์ ํŠธ๋Š” ์˜ค๋กœ์ง€ ์ค„๋ฆฌ์•„(Julia)๋งŒ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋”ฅ๋Ÿฌ๋‹ ๋ชจ๋ธ์„ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.
This project uses only Julia language to implement deep learning model.

๊ต์œก์šฉ์œผ๋กœ ์ œ์ž‘๋œ ๊ฒƒ์ด๊ธฐ์— ๋”ฅ๋Ÿฌ๋‹ ์›๋ฆฌ์— ๋Œ€ํ•ด ๊ณต๋ถ€ํ•˜์‹ค ๋ถ„๋“ค์—๊ฒŒ ์ถ”์ฒœํ•ฉ๋‹ˆ๋‹ค.
It's designed for education, so I recommend for those who want to study the principles of deep learning.

์ด ํ”„๋กœ์ ํŠธ์—์„œ ์‚ฌ์šฉ๋œ ์ฝ”๋“œ๋“ค์€ ์•„๋ž˜์˜ ์ €์„œ๋ฅผ ์ฐธ๊ณ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
I refered to the book below.

์ œ ๋ธ”๋กœ๊ทธ์˜ Deep Learning in Julia์นดํ…Œ๊ณ ๋ฆฌ์— ๊ตฌํ˜„ ๊ณผ์ •์ด ์—…๋กœ๋“œ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
I uploaded some posts about the project's process on my blog, but they are written only Korean.

P.S. ์ค„๋ฆฌ์•„์˜ ์‚ฌ์šฉ๋ฒ•์ด ๊ถ๊ธˆํ•˜๋‹ค๋ฉด, ์ œ ๋ธ”๋กœ๊ทธ์— ๋ฒˆ์—ญํ•ด๋‘” Think Julia์„ ํ†ตํ•ด ๊ณต๋ถ€ํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ”„๋กœ์ ํŠธ ๋ชฉํ‘œ (The project's goal)

  • ์ค„๋ฆฌ์•„์˜ ์‚ฌ์šฉ๋ฒ•์„ ๋ฐฐ์šด๋‹ค.
    you can learn how to use Julia language

  • ๋”ฅ๋Ÿฌ๋‹์˜ ์ž‘๋™๋ฐฉ์‹์„ ์™„์ „ํžˆ ์ดํ•ดํ•œ๋‹ค.
    you can totally understand deep learning's process.

  • ๋งŒ๋“  ์ฝ”๋“œ๋กœ ๋ชจ๋ธ์„ ๋งŒ๋“ค๊ณ  ํ•™์Šตํ•ด๋ณธ๋‹ค.
    you can make and train model using your own code.

์ฝ”๋“œ ๋ง›๋ณด๊ธฐ (A sneak peek of the project)

๊ฐ„๋‹จํ•˜๊ฒŒ ์†๊ธ€์”จ ์ˆซ์ž๋ฅผ ๋งž์ถ”๋Š” ๋ถ„๋ฅ˜ ๋ชจ๋ธ์„ ๋งŒ๋“ค์–ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
Let's start making model that classify handwritten digits.

์šฐ๋ฆฌ๊ฐ€ ์˜ค๋Š˜ ์‚ฌ์šฉํ•  ๋ชจ๋ธ์— ๋Œ€ํ•œ ์ •๋ณด๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.
Here is the information about model structure and train parameters.

- model structure
Conv(filter_num = 32, filter_size = 3, stride = 1, padding = 0) + ReLU
Max_pool(filter size = 2, stride = 1, padding = 0)
Conv(filter_num = 64, filter_size = 3, stride = 1, padding = 0) + ReLU
Max_pool(filter size = 2, stride = 1, padding = 0)
Conv(filter_num = 64, filter_size = 3, stride = 1, padding = 0) + ReLU
Max_pool(filter size = 2, stride = 1, padding = 0)
Flatten
Dense(node_num = 64) + Relu
Dense(node_num = 10) + softmax

- train parameters
weight initializer = He
optimizer = Adam
batch size = 100
epochs = 1

๋ชจ๋ธ ํ›ˆ๋ จํ•˜๊ธฐ (training the model)

1. ํ”„๋กœ์ ํŠธ์˜ ์ „์ฒด ์ฝ”๋“œ๋ฅผ ๋‹ค์šด๋ฐ›์Šต๋‹ˆ๋‹ค.
1.download the entire code in this project.

ํ”„๋กœ์ ํŠธ ์ƒ๋‹จ์—์„œ ์ง์ ‘ ๋‹ค์šด๋ฐ›์„ ์ˆ˜๋„ ์žˆ๊ณ , git์„ ์‚ฌ์šฉํ•˜์‹ ๋‹ค๋ฉด ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•ด์„œ ๋‹ค์šด๋ฐ›์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
you can download it directly from top of this page, or you can clone it using git.

$ git clone https://github.com/Hyeonji-Ryu/Deep_Learning_in_Julia.git

2. ์ปค๋งจ๋“œ๋ผ์ธ์—์„œ CNN ํด๋”๋กœ ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
2.set a directory path to CNN folder in command line.

$ cd <your path>/Deep_Learning_in_Julia/CNN

3. ์ค„๋ฆฌ์•„ REPL๋ฅผ ์—ด๊ธฐ ์œ„ํ•ด ํ•ด๋‹น ์ปค๋งจ๋“œ๋ผ์ธ์—์„œ Julia๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
3.enter Julia in command line to open Julia REPL.

4.๋งˆ์ง€๋ง‰์œผ๋กœ ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
4.enter the code below.

Julia> include("train_convNet.jl")

5. ์•„๋ž˜์™€ ๊ฐ™์ด ๋กœ์Šค๊ฐ’์„ ๋ฐ”๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
5.you can see loss values in real time.

NO.1: 2.2886466121074425
NO.2: 2.280258799992027
NO.3: 2.2746683599835764
NO.4: 2.2608282595650575
NO.5: 2.243700243712272
NO.6: 2.214588691106391
.
.
NO.595: 0.10943427897500864
NO.596: 0.12955831960259565
NO.597: 0.03989749763491561
NO.598: 0.013439008366053344
NO.599: 0.1109573868949143
NO.600: 0.08915640203576712

6. ํ›ˆ๋ จ์ด ๋๋‚œ ํ›„, ์ž๋™์œผ๋กœ ํ…Œ์ŠคํŠธํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.
6.you can see accuracy of test set automatically.

98.08

ํ›ˆ๋ จ๋œ ๋ชจ๋ธ๋กœ ์ˆซ์ž ์˜ˆ์ธกํ•ด๋ณด๊ธฐ (predicting digit using trained model)

๋ชจ๋ธ์ด ์ œ๋Œ€๋กœ ํ›ˆ๋ จ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ด๋ด…์‹œ๋‹ค.
Let's check that the model is trained well.

๋จผ์ €, ํ›ˆ๋ จ๋ฐ์ดํ„ฐ ์ค‘ ํ•˜๋‚˜๋ฅผ test๋กœ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค.
First, assign one of train set to test.

Julia> test = reshape(train_x[:,:,:,1],28,28,1,1)

๋‹ค์Œ์œผ๋กœ ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ์˜ˆ์ธก ๊ฒฐ๊ณผ๋ฅผ ๋ฐ›์Šต๋‹ˆ๋‹ค.
Next, enter the code below to get result of prediction.

julia> result = argmax(predict(test))
CartesianIndex(1, 6) #[0,1,2,3,4,*5*,6,7,8,9,10]

๋ชจ๋ธ์€ test๊ฐ€ 5๋ผ๊ณ  ์˜ˆ์ธกํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ณผ์—ฐ 5์ธ์ง€ ํ™•์ธํ•ด๋ด…์‹œ๋‹ค.
The model predicted that test is 5. Let's check it.

Julia> train_y[1]
5

๋ชจ๋ธ์ด ์ •ํ™•ํžˆ ์˜ˆ์ธกํ–ˆ์Œ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
You can see that the model predicted it correctly.

About

This project uses only Julia language to implement deep learning model

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages