Please wait ...
-
PortFolio
๐ ๋ชฉ์ฐจ
๐ ๋ชฉ์ฐจ
ํ์ ๋ถ์ 3์์
์ง๋ฌด๋ถ์
์ง๋ฌด ๋ถ์์ ์ํ ์ ๋ณด ์ถ์ฒ
๋ถ์ ํ ์ ๋ฆฌ
์ง๋ฌด ๋ถ์์ ํ๋ฆ
๊ธฐ์
๋ถ์ (Company Analysis)
๊ธฐ์
๋ถ์์ ๊ตฌ์กฐํ
๊ธฐ์
๋ถ์์ ์ํ ์ ๋ณด ์ถ์ฒ
์ฐ์
๋ถ์ (Industry Analysis)
์ฐ์
๋ถ์์ ํต์ฌ ์์
๋ถ์ ํ ์ ๋ฆฌ
์
์ฌ์ง์์
์์ฑ ์ ์ ๊ฒ์ฌํญ
ํผํด์ผ ํ ์
์ฌ์ง์์์ ํน์ง
๋น์ฌ ์์ (ํ์ฌ ์ง์ ์์)
์์ ์์ (์ด๋ ฅ์, CV ๋ฑ)
๊ธฐ๋ณธ ๊ตฌ์ฑ ํญ๋ชฉ ๋ฐ ํต์ฌ
์ฑ์ฅ๊ณผ์
๐ ํต์ฌ ์์ฑ ํฌ์ธํธ
โ ํผํด์ผ ํ ๋ด์ฉ
์ฑ๊ฒฉ์ ์ฅ๋จ์
๐ ํต์ฌ ์์ฑ ํฌ์ธํธ
โ ์ฃผ์์ฌํญ
์ง๋ฌด ๊ฒฝํ
๐ ํต์ฌ ์์ฑ ํฌ์ธํธ
์ง์๋๊ธฐ ๋ฐ ์
์ฌ ํ ํฌ๋ถ
๐ ์์ฑ ํ๋ฆ
๊ฒฝํ์ ๋
ผ๋ฆฌ์ ์ผ๋ก ํ์ด๋ด๋ ์คํ ๋ฆฌํ
๋ง ๊ธฐ๋ฒ
๋ํ ๊ธฐ๋ฒ: STAR
๊ธฐํ ๊ธฐ๋ฒ
โ
์ ์ถ ์ ์ต์ข
์ ๊ฒ์ฌํญ
๐ ์์ฑ ์ ๊ฒ์ฌํญ
๐ ๊ฐ๋
์ฑ์ ๋์ด๋ ๋ฐฉ๋ฒ
๐ ๋ฉด์ ์ง๋ฌธ ๋๋น ์ฒดํฌ๋ฆฌ์คํธ
๐บ ์์ธ์ ํ๋
๐ฃ๏ธ ๋งํ๊ธฐ ์ต๊ด
๐ฏ ์ง๋ฌด ๊ด๋ จ
๐ ์ด์ง ์ฌ์ ๋ต๋ณ
๐ ๊ธฐํ
ํ์ ๋ถ์ 3์์
์ง๋ฌด ๋ถ์: ๋ด๊ฐ ํ ์ผ์ ๋ฌด์์ธ๊ฐ?
๊ธฐ์
๋ถ์: ๋ด๊ฐ ์ผํ ๊ณณ์ ์ด๋ค ๊ณณ์ธ๊ฐ?
์ฐ์
๋ถ์: ๋ด๊ฐ ์ํ ๋ถ์ผ์ ํ์ฌ์ ๋ฏธ๋๋ ์ด๋ ํ๊ฐ?
์ง๋ฌด๋ถ์
์ง๋ฌด ๋ถ์ ๋ฐฉ๋ฒ
์ ํ ์ง๋ฌด์ ๋ํ ๊ตฌ์ฒด์ ์ญํ ๊ณผ ํ์ ์ญ๋ ํ์ธ
๋ด๊ฐ ์ํ ์ ์์๊น?
๋ด๊ฐ ์ข์ํ๋ ์ผ์ ์ํํ๋ ์ง๋ฌด์ธ๊ฐ?
**์ง์ ์ง๋ฌด๊ฐ ํ์ฌ์ ๊ธฐ์ฌํ ์ ์๋ ์ฑ๊ณผ๋ ๋ฌด์์ธ๊ฐ?**
์ง๋ฌด ์ํ์ ์ํด ๋ณธ์ธ์ด ์ค๋นํ ์ญ๋์ ๋ฌด์์ธ๊ฐ?
์ง๋ฌด ์ํ์ ์ํด ๋ณธ์ธ์ด ๊ฐ์ฅ ๋ถ์กฑํ ์ญ๋์ ๋ฌด์์ธ๊ฐ?
๋ถ์กฑํ ์ญ๋์ ๋ณด์์ ์ํด ์ด๋ค ๋
ธ๋ ฅ์ ํ ๊ฒ์ธ๊ฐ?
๊ตฌ์ฒด์ ์ผ๋ก ํ๋ ์ผ -> ํ์ํ KSA -> ์์ ์ด ๋ณด์ ํ KSA -> ๊ทธ๊ฒ์ ๊ทผ๊ฑฐํ ์ฌ๋ก ->
์ง๋ฌด ๋ถ์์ ์ํ ์ ๋ณด ์ถ์ฒ
๊ณ ์ฉ24: ์ทจ์
์ง์ ๋ฐ ์ง์
์ ๋ณด
NCS (๊ตญ๊ฐ์ง๋ฌด๋ฅ๋ ฅํ์ค): ์ง๋ฌด๊ธฐ์ ์ ๋ฐ ์์ธ ์ญํ ๊ฒ์
๊ธฐ์
ํํ์ด์ง: ์ง๋ฌด ์๊ฐ ๋ฐ ์ธ์ฌ์
๋์์ ์ฑ๋ (YouTube): ํ์ง์ ์ธํฐ๋ทฐ ๋ฐ ์ง๋ฌด ๋ธ์ด๋ก๊ทธ
์ทจ์
ํฌํธ ์ฌ์ดํธ: ์ฑ์ฉ๊ณต๊ณ ์ ์ง๋ฌด ์ค๋ช
(JD), ํ์ง์ ๊ด๋ จ ์ ๋ณด
์ง๋ฌด ๊ด๋ จ ์ปค๋ฎค๋ํฐ: ํ์
์ค๋ฌด์๋ค์ ์์ํ ์ด์ผ๊ธฐ
๋ถ์ ํ ์ ๋ฆฌ
ํต์ฌ ์ญ๋ ํ์
: ๋ถ์์ ํตํด ํ์
ํ ํต์ฌ ์ญ๋์ ํฌํธํด๋ฆฌ์ค์ ๋
น์ฌ๋ด์ผ ํ๋ค.
์ฑ๊ณต ๊ฐ๋ฅ์ฑ ์์ธก: ์ง๋ฌด์ ๋ํ ์ดํด๋ฅผ ๋ฐํ์ผ๋ก ์์ ์ ์ฑ๊ณต ๊ฐ๋ฅ์ฑ์ ๊ฐ๋ ํ๋ค.
๋ณด์ ๊ณํ ์๋ฆฝ: ๋ถ์กฑํ ์ ์ ํ์
ํ๊ณ , ์์ผ๋ก์ ์ญ๋ ๊ฐ๋ฐ ๊ณํ์ ์ธ์ด๋ค.
์ง๋ฌด ์ ํฉ์ฑ ์ดํ: ํต์ฌ ์ญ๋์ ์ง์คํ์ฌ ์์ ์ด ์ผ๋ง๋ ์ค๋น๋ ์ธ์ฌ์ธ์ง ๋ณด์ฌ์ค๋ค.
์ง๋ฌด ๋ถ์์ ํ๋ฆ
ํ๋ ์ผ โ ํ์ ์ญ๋(KSA) โ ๋ณด์ ์ญ๋(KSA) โ ๊ฒฝํ์ ๊ทผ๊ฑฐ(์ฌ๋ก) โ ๋ฏธ๋ณด์ ์ญ๋ โ ๋ณด์ ๊ณํ
๊ธฐ์
๋ถ์ (Company Analysis)
Point! โ์๊ฒ ๋์์ต๋๋คโ๋ผ๋ ์๋์ ์ธ ํ๋๋ณด๋ค, โ์ด๋ฌํ ์ ์ ํ์
ํ๊ณ ์ด์ ๋ง์ถฐ OOO์ ์ค๋นํ์ต๋๋คโ ์ ๊ฐ์ด ๋ฅ๋์ ์ธ ์์ธ๋ฅผ ๋ณด์ฌ์ฃผ๋ ๊ฒ์ด ์ค์.
๊ธฐ์
๋ถ์์ ๊ตฌ์กฐํ
๊ธฐ๋ณธ ์ ๋ณด
๋น์ , ๋ฏธ์
, ์ ๋ต: ํ์ฌ๊ฐ ๋์๊ฐ ๋ฐฉํฅ์ ์ดํด. (โ์โ ์ด ๋น์ ์ ์๋ฆฝํ๋์ง, โ์ด๋ป๊ฒโ ์ค์ฒํ๊ณ ์๋์ง ์ฌ๋ก๋ฅผ ํ์
ํ๋ ๊ฒ์ด ์ค์.)
ํ์ฌ ๊ฐ์, ์ฐฝ์
์ด๋
, ๊ฒฝ์ ํ๋: ํ์ฌ์ ๊ทผ๋ณธ์ ์ธ ๊ฐ์น๋ฅผ ํ์
.
์ธ์ฌ์ ๋ฐ ํต์ฌ ๊ฐ์น
์ธ์ฌ์ ํ์ธ: ๊ธฐ์
์ด ์ด๋ค ์ฌ๋์ ์ํ๋์ง ํ์
.
๋๋ง์ ์ ์: ํด๋น ์ธ์ฌ์์ ๋ํ ์์ ๋ง์ ์ ์๋ฅผ ๋ด๋ฆฌ๊ณ , ์ ํ์ํ์ง ์ดํด. (์: โOOO์ด ์ด ๊ธฐ์
์ ๊ฐ์ ์ด๊ธฐ์, ์ด๋ฅผ ๋ฐ์ ์ํฌ ์ ์๋ OOO ์ญ๋์ ๊ฐ์ถ ์ธ์ฌ๊ฐ ํ์ํ๊ตฌ๋.โ)
์ฌ์
ํํฉ
์์ต ๊ตฌ์กฐ: ํ์ฌ๊ฐ ์ด๋ป๊ฒ ๋์ ๋ฒ๋์ง ๋ถ์. (์ฃผ๋ ฅ ์ ํ, ์๋น์ค ๋ฑ)
์ฌ๋ฌด ์ํ: ์ต๊ทผ ๋งค์ถ๊ณผ ์์
์ด์ต์ ์ถ์ด๋ฅผ ํ์ธ.
๋ฏธ๋ ๊ณผ์ ๋ฐ ์ด์
๊ฐ์ ๊ณผ ์ฝ์ (SWOT): ํ์ฌ์ ํ์ฌ ์์น์ ์ ์ฌ๋ ฅ์ ๋ถ์.
์ต์ ์ด์: ์ต๊ทผ ๊ธฐ์
์ด ๋ง์ฃผํ ๊ณผ์ ๋ ๊ธฐํ๋ฅผ ํ์
.
์ ๋
์ฌ ํ์ฉ:
์ฌํด์ ํค์๋: ์ ๋
์ฌ์์ ๊ฐ์กฐํ๋ ํค์๋๋ฅผ ํ์ฉํ์ฌ ์์ ์ ํฌ๋ถ๋ฅผ ์ฐ๊ฒฐ.
๊ณผ๊ฑฐ ์ ๋
์ฌ ๋น๊ต (์ต๊ทผ 3๋
): ํ์ฌ์ ๋ชฉํ๊ฐ ์ด๋ป๊ฒ ๋ณํํด์๋์ง ํ๋ฆ์ ํ์
.
๊ฒฝ์์ฌ ์ ๋
์ฌ ๋น๊ต: ์
๊ณ์ ์ ๋ฐ์ ์ธ ๋ํฅ๊ณผ ํค์๋๋ฅผ ํ์
.
๊ธฐ์
๋ถ์์ ์ํ ์ ๋ณด ์ถ์ฒ
๊ธฐ์
ํํ์ด์ง
ํ์ฌ ์๊ฐ: ์ฐํ, ๊ฒฝ์ ์ด๋
, ์ธ์ฌ์, ๋น์ , ๋ฏธ์
๋ฑ
์ ํ ๋ฐ ์๋น์ค: ๋ธ๋๋ ์๊ฐ ๋ฐ ์์ธ ์ ๋ณด
ํ๋ณด ์ผํฐ/๋ด์ค๋ฃธ: ์ต๊ทผ ์ด์, ๋ณด๋์๋ฃ, ์ฌ๋ด ์์์ง ๋ฑ
์ต๊ทผ ๋ณด๋์๋ฃ
์ฌ์
๋ํฅ: ์ ๊ท ์ฌ์
, ์ฃผ๋ ฅ ์ฌ์
์ ์งํ ์ํฉ
์
๊ณ ํํฉ: ์
๊ณ ๋ด ๊ธฐ์
์ ์์น์ ์ด์
์ฌ์
๋ชฉํ: ์ ๋
์ฌ, ์ธํฐ๋ทฐ ๋ฑ์ ํตํด ๋๋ฌ๋ ๋ชฉํ ํ์ธ
DART (์ ์๊ณต์์์คํ
)
์ฌ์
๋ณด๊ณ ์: ์ฌ์
์ ๊ท๋ชจ, ์ ๋ต, ์ฌ๋ฌด ํํฉ ๋ฑ ๊ฐ์ฅ ์ ๋ขฐ๋ ๋์ ์ ๋ณด
์ฌ๋ฌด์ ํ ๋ถ์: ๋งค์ถ์ก, ์์
์ด์ต, ๋น๊ธฐ์์ด์ต ๋ฑ์ ๋ณํ๋ฅผ ํ์
. (Point! โ๋งค์ถ์ด ์ฌ๋๋คโ์์ ๊ทธ์น์ง ๋ง๊ณ , ์, ์ด๋ป๊ฒ ์ฌ๋๋์ง ์์ธ์ ๋ถ์ํด์ผ ํจ.)
์ฐ์
๋ถ์ (Industry Analysis)
Point! ๋ด๊ฐ ์ โ์ด ์ฐ์
โ์ ์ ํํ๋์ง์ ๋ํ ๋ช
ํํ ๊ธฐ์ค๊ณผ ์ด์ ๋ฅผ ์ ์ํด์ผ ํจ.
์ฐ์
๋ถ์์ ํต์ฌ ์์
์ฐ์
์ ํ ๊ธฐ์ค: ๋ด๊ฐ ์ด ์ฐ์
์ ์ ํํ ์ด์ ๋ ๋ฌด์์ธ๊ฐ?
๊ฒฝ์ ์ฐ์ ์์: ํด๋น ์ฐ์
์์ ๊ฒฝ์ ์ฐ์๋ฅผ ํ๋ณดํ๊ธฐ ์ํด ํ์ํ ๊ฒ์ ๋ฌด์์ธ๊ฐ?
์ต์ ์ด์์ ํธ๋ ๋: ์ต๊ทผ ์ฐ์
๋ํฅ(์: ๋ฐ๋์ฒด ๋ํฅ)์ ์ด๋ ํ๋ฉฐ, ์ง์ ๊ธฐ์
์ ์ด์ ์ด๋ป๊ฒ ๋์ํ๊ณ ์๋๊ฐ?
์ฐ์
์ ํ์์ฑ: ํด๋น ์ฐ์
์ด ์ฌํ๋ ๊ฒฝ์ ์ ์ ํ์ํ์ง ์ดํดํด์ผ ํ๋ค.
๋ถ์ ํ ์ ๋ฆฌ
์ญ๋ ๋งค์นญ: ๋์ ์ญ๋์ ๊ธฐ์
์ ์ธ์ฌ์, ๋น์ , ๊ทธ๋ฆฌ๊ณ ์ฐ์
์ ํ์์ฑ๊ณผ ์ฐ๊ฒฐ.
๊ฐ๋ฐ ๋ฐฉํฅ ์ ์: ํ์ฌ ๋ถ์กฑํ ์ญ๋์ ์ฐ์
์ ๋ฏธ๋์ ์ฐ๊ด ์ง์ด ์ด๋ป๊ฒ ๊ฐ๋ฐํ ์ง ๋ฐฉํฅ์ ์ ์.
ํฌ๋ถ ์ ๋ฆฝ: ๊ธฐ์
์ ๋น์ ๊ณผ ํจ๊ป ์ฑ์ฅํ๋ฉฐ ์ฐ์
์ ๊ธฐ์ฌํ ์ ์๋ ์์ ์ ํฌ๋ถ๋ฅผ ๊ตฌ์ฒด์ ์ผ๋ก ์ ๋ฆฌ.
์
์ฌ์ง์์
๊ฐ๊ฒฐํจ๊ณผ ํต์ฌ: ๋ชจ๋ ๋ด์ฉ์ ํต์ฌ ์์ฃผ๋ก ๊ฐ๊ฒฐํ๊ฒ ์์ฑํฉ๋๋ค. ๋ถํ์ํ ๋ฏธ์ฌ์ฌ๊ตฌ๋ ์ค๋ช
์ ํผํ๊ธฐ.
๊ตฌ์ฒด์ ์ธ ๊ฒฝํ: ์ฑ์ธ์ด ๋ ์ดํ์ ๊ฒฝํ์ ๋ฐํ์ผ๋ก ์์ฑํ์ฌ ์ง๋ฌด ์ญ๋๊ณผ์ ์ฐ๊ด์ฑ์ ๋ณด์ฌ์ค.
๊ท ํ ์๋ ๋ถ๋: ๊ฐ ํญ๋ชฉ์ ๊ธ์ ์๋ฅผ 550~600์ ๋ด์ธ๋ก ๊ท ํ๊ฐ ์๊ฒ ๋ง์ถ๋ ๊ฒ์ด ์ข๋ค.
ํ๋ก์ ํธ ๊ธฐ์ ์: ๊ฒฝ๋ ฅ์ด๋ ํ๋ก์ ํธ๋ฅผ ์์ธํ ๊ธฐ์ ํ ๊ฒฝ์ฐ, ๊ฐ์ฅ ์ค์ํ ๋ด์ฉ๋ง ๋ด์ 10~15 ํ์ด์ง ์ด๋ด๋ก ์ ๋ฆฌ.
์์ฑ ์ ์ ๊ฒ์ฌํญ
ํต์ฌ ๋ถ์: ์ง๋ฌด, ๊ธฐ์
, ์ฐ์
์ ๋ํ ํ์ ๋ถ์์ ๋ง์ณค๋๊ฐ?
๊ฐ์ ์ ๋ฆฌ: ๋์ ์ด๋ค ๊ฐ์ ๊ณผ ๊ฒฝํ์ ๋ด์ธ์ธ ๊ฒ์ธ์ง ๋ช
ํํ ์ ๋ฆฌ๋์๋๊ฐ?
์ง๋ฌด ์ ํฉ์ฑ: ๋์ ๊ฒฝํ๊ณผ ์ญ๋์ด ์ง์ ์ง๋ฌด์ ๋์ ๊ด๋ จ์ฑ์ ๊ฐ์ง๋๊ฐ?
๋งค๋ ฅ ์ดํ: ๋๋ฅผ ์ฐจ๋ณํํ ์ ์๋ ๋งค๋ ฅ ํฌ์ธํธ๋ฅผ ์ด๋ป๊ฒ ์ดํํ ์ง ์ค๋น๋์๋๊ฐ?
ํผํด์ผ ํ ์
์ฌ์ง์์์ ํน์ง
์ดํ ํฌ์ธํธ ๋ถ์ฌ: ์ง์์๋ง์ ๋๋ ทํ ์ฅ์ ์ด๋ ๋งค๋ ฅ์ด ๋ณด์ด์ง ์์.
๋จ์กฐ๋ก์ด ๊ตฌ์ฑ: ํน์ ์๋ ๋ฌธ์ฅ๊ณผ ๊ตฌ์ฑ์ผ๋ก ์ง๋ฃจํ ๋๋.
์ ๋ขฐ์ฑ ๋ถ์กฑ: ๊ฐ๊ด์ ์ผ๋ก ๊ฒ์ฆํ๊ธฐ ์ด๋ ค์ด ๊ฒฝ๋ ฅ์ด๋ ์ญ๋๋ง ๋์ด.
์ฐจ๋ณ์ฑ ์์: ์ด๋ ํ์ฌ์ ์ง์ํด๋ ๋ฌด๋ฐฉํ ์ ๋๋ก ์ผ๋ฐ์ ์ธ ๋ด์ฉ์ผ๋ก ์ฑ์.
์์ธก ๋ถ๊ฐ๋ฅ์ฑ: ์ง์์์ ์ฑํฅ์ด๋ ์ฑ๊ฒฉ์ ์ ํ ํ์
ํ ์ ์๋ค.
๋ถ์คํ ๋ด์ฉ: ๋ถ๋์ ์ฑ์ ์ง๋ง, ๋ด์ฉ์ด ํ์ ํ๊ณ ๊น์ด๊ฐ ์๋ค.
๋น์ฌ ์์ (ํ์ฌ ์ง์ ์์)
ํน์ง: ํ์ฌ๊ฐ ์ง์ ํ ๊ณ ์ ๋ ์์์ผ๋ก, ์ง๋ฌธ ํญ๋ชฉ์ด๋ ํ์ ์์ ํ ์ ์๋ค.
์์ฑ๋ฒ: ์ฃผ์ด์ง ํญ๋ชฉ์ ๋ง์ถฐ ๋ด์ฉ์ ์ถฉ์คํ๊ฒ ์์ฑํ๋ ๊ฒ์ด ์ค์. ๋ชจ๋ ์ง์์๊ฐ ๋์ผํ ๊ธฐ์ค์ผ๋ก ํ๊ฐ.
์์ ์์ (์ด๋ ฅ์, CV ๋ฑ)
ํน์ง: ์ ํด์ง ํ ์์ด ์ง์์๊ฐ ์์ ๋กญ๊ฒ ๊ตฌ์ฑํ๋ ์์.
์์ฑ๋ฒ: ์์ ์๊ฒ ๊ฐ์ฅ ์ ๋ฆฌํ ํญ๋ชฉ์ผ๋ก๋ง ๊ตฌ์ฑํ๊ณ , ๊ณต๋(๋น์นธ)์ ์ ๋ ๋ง๋ค์ง ์๋๋ค.
๊ธฐ๋ณธ ๊ตฌ์ฑ ํญ๋ชฉ ๋ฐ ํต์ฌ
์ฑ์ฅ๊ณผ์ : ๊ฐ์น๊ด๊ณผ ์ ๋
์ด ํ์ฑ๋ ๊ณผ์ ์ ์ฑ์ธ์ ๊ฒฝํ์ผ๋ก ์ฆ๋ช
์ฑ๊ฒฉ์ ์ฅ๋จ์ : ์ง๋ฌด์ ๊ด๋ จ๋ ๊ฐ์ , ๊ทธ๋ฆฌ๊ณ ๋จ์ ์ ๊ทน๋ณตํ๋ ค๋ ๋
ธ๋ ฅ
์ง๋ฌด ๊ฒฝํ: ์ง๋ฌด์ ์ง์ ์ ์ผ๋ก ์ฐ๊ด๋ ๊ฒฝํ๊ณผ ์ด๋ฅผ ํตํด ๋ฐฐ์ด ์ญ๋
์ง์๋๊ธฐ ๋ฐ ์
์ฌ ํ ํฌ๋ถ: ๋๋ ์ ์ด ํ์ฌ, ์ด ์ง๋ฌด์ ์ ํฉํ ์ธ์ฌ์ธ๊ฐ?
์ฑ์ฅ๊ณผ์
โ์ด๋ฆด ์ ์ด์ผ๊ธฐโ๊ฐ ์๋ โ์ฑ์ธ์ผ๋ก์ ๊ฐ์น๊ด์ ํค์์จ ๊ณผ์ โ์ ๋ณด์ฌ์ฃผ๋ ๊ฒ์ด ํต์ฌ.
๐ ํต์ฌ ์์ฑ ํฌ์ธํธ
์ ๋
/๊ธฐ์ค ์ ์: ์ง์์๊ฐ ์ค์ํ๊ฒ ์๊ฐํ๋ฉฐ ์ฑ์ฅ์์ผ์จ ์ ๋
์ด๋ ๊ธฐ์ค์ ์ ์.
๊ตฌ์ฒด์ ์ฌ๋ก: ๊ทธ ์ ๋
์ ์ฅ๊ธฐ๊ฐ ์ค์ฒํด ์จ ์ฑ์ธ ์์ ์ ์ฌ๋ก๋ฅผ ๋ค์ด ์ฆ๋ช
ํ๋ค.
์ญ๋ ์ฐ๊ฒฐ: ํฌ๋ง ์ง๋ฌด์ ํ์ํ ์ฑํฅ์ด๋ ์กฐ์ง ์ตํ ๊ด๋ จ ๊ฐ์ ์ ํค์์จ ๊ฒฝํ์ ์ฐ๊ฒฐํ๋ค.
โ ํผํด์ผ ํ ๋ด์ฉ
โ์ ์ฒ์ ์ผ๋ก~โ, โ์ด๋ฆฐ ์์ ์ ๋~โ ๊ณผ ๊ฐ์ด ๊ณผ๊ฑฐ์๋ง ๋จธ๋ฌด๋ ์์
โ์ฑ์คํฉ๋๋ค. ๊ทธ๋์ ์ง๊ฐ, ๊ฒฐ์์ ํ ์ ์ด ์์ต๋๋ค.โ ์ ๊ฐ์ด ๋น์ฐํ ์ด์ผ๊ธฐ
์ฑ๊ฒฉ์ ์ฅ๋จ์
์ฅ์ ์ ์ง๋ฌด์์ ์ฐ๊ด์ฑ์, ๋จ์ ์ ์์งํจ๊ณผ ๊ฐ์ ์์ง๋ฅผ ๋ณด์ฌ์ฃผ๋ ํญ๋ชฉ.
๐ ํต์ฌ ์์ฑ ํฌ์ธํธ
์ง๋ฌด ์ฐ๊ด์ฑ: ์ง๋ฌด์ ์ง์ ์ ์ผ๋ก ์ฐ๊ด๋๋ ๊ฐ์ ์ ๊ตฌ์ฒด์ ์ธ ๊ฒฝํ๊ณผ ํจ๊ป ์ ์.
๊ฐ์ ๋
ธ๋ ฅ: ๋จ์ ์ ์์งํ๊ฒ ์ธ์ ํ๊ณ , ์ด๋ฅผ ๋ณด์ํ๊ธฐ ์ํ ๋
ธ๋ ฅ์ ๋ฐ๋์ ํจ๊ป ์์ฑ.
ํฉ๊ธ ๋น์จ: ์ฅ์ ๊ณผ ๋จ์ ์ ๋ถ๋ ๋น์จ์ 7:3 ์ ๋๊ฐ ์ด์์ .
โ ์ฃผ์์ฌํญ
โ์ง๋์น๊ฒ ๊ผผ๊ผผํด์ ์๊ฐ์ด ์ค๋ ๊ฑธ๋ฆฝ๋๋ค.โ ์ ๊ฐ์ด ์ฅ์ ๊ฐ์ ๋จ์ ์ ํผํด์ผ ํ๋ค.
์ฅ์ ๊ณผ ๋จ์ ์ ๋ช
ํํ ๋ถ๋ฆฌํด์ ์์ ํ๋ ๊ฒ์ด ์ข๋ค.
์ง๋ฌด ๊ฒฝํ
์ง์ ์ง๋ฌด์ ๋ํ ์ดํด๋์ ์ค๋ฌด ์ญ๋์ ์ง์ ์ ์ผ๋ก ์ดํํ๋ ํญ๋ชฉ.
๐ ํต์ฌ ์์ฑ ํฌ์ธํธ
์ง์ ๊ฒฝํ: ์ธํด, ๊ณ์ฝ์ง, ํ๋ก์ ํธ ๋ฑ ์ง๋ฌด์ ๊ด๋ จ๋ ์ง์ ์ ์ธ ์ค๋ฌด ๊ฒฝํ์ ์ค์ฌ์ผ๋ก ์์ฑ.
์ญํ ๊ณผ ์ฑ๊ณผ: ํ๋ก์ ํธ์์ ์์ ์ด ๋งก์๋ ๊ตฌ์ฒด์ ์ธ ์ญํ , ์ด๋ฅผ ํตํด ํฅ์์ํจ ์ค๋ฌด ์ญ๋, ๊ทธ๋ฆฌ๊ณ ๋ฐฐ์ด ์ ์ ๋ช
ํํ ๊ธฐ์ .
์ง์๋๊ธฐ ๋ฐ ์
์ฌ ํ ํฌ๋ถ
โํ์ฌ-์ง๋ฌด-๋โ์ ์ฐ๊ฒฐ๊ณ ๋ฆฌ๋ฅผ ์ฐพ์, ๋์ ์ฑ์ฅ ๊ณํ์ ๋ณด์ฌ์ฃผ๋ ํญ๋ชฉ.
๐ ์์ฑ ํ๋ฆ
์ฐ์
๋ถ์: ํ์ฌ ์ฐ์
์ ํน์ฑ ๋ฐ ์ด์๋ฅผ ์ธ๊ธ.
๊ธฐ์
๋ถ์: ๊ทธ ์์์ ํ์ฌ๊ฐ ๋์๊ฐ๋ ๋ฐฉํฅ์ ์ฐ๊ฒฐ.
๋์ ์ ํฉ์ฑ: ํด๋น ๋ฐฉํฅ์ ์ํด ๋ด๊ฐ ๊ธฐ์ฌํ ์ ์๋ ๋ถ๋ถ(์ญ๋)์ ๊ฐ์กฐํ๋ฉฐ ์ง์ ์ง๋ฌด์ ํ์์ฑ์ ์ดํ.
๋ฏธ๋ ๊ณํ: ์
์ฌ ํ ๊ตฌ์ฒด์ ์ธ ์
๋ฌด ์ํ ๊ณํ๊ณผ ์ปค๋ฆฌ์ด ์ฑ์ฅ ๊ณํ์ ์ ์.
์์: โ์ต๊ทผ OO ์ฐ์
์ ~๋ผ๋ ๋ํฅ์ ๋ณด์
๋๋ค. ๊ท์ฌ๋ ์ด์ ๋์ํด ~๋ฐฉํฅ์ผ๋ก ๋์๊ฐ๊ณ ์์ผ๋ฉฐ, ์ด๋ฌํ ๋ชฉํ ๋ฌ์ฑ์ ์ํด์ OO ์ญ๋์ด ํ์์ ์
๋๋ค. ์ ๋ OOO ๊ฒฝํ์ ํตํด ํด๋น ์ญ๋์ ๊ธธ๋ ๊ธฐ์, ๊ท์ฌ์์ OOO๋ฅผ ์ํํ๋ฉฐ ํจ๊ป ์ฑ์ฅํ๊ณ ์ ์ง์ํฉ๋๋ค.โ
๊ฒฝํ์ ๋
ผ๋ฆฌ์ ์ผ๋ก ํ์ด๋ด๋ ์คํ ๋ฆฌํ
๋ง ๊ธฐ๋ฒ
๋๊ด์ ๊ตฌ์ฑ: ๊ฒฐ๋ก (๊ฐ์ ํค์๋)์ ๋ฌธ์ฅ ๋งจ ์์ ์ ์ํ์ฌ ์ ๋ฌ๋ ฅ์ ๋์ธ๋ค.
๋ณธ๋ก : ์๋์ ๊ฐ์ ๊ธฐ๋ฒ์ ํ์ฉํ์ฌ ๊ฒฝํ์ ๊ตฌ์ฒด์ ์ผ๋ก ์์ฑ.
๋ํ ๊ธฐ๋ฒ: STAR
S (Situation): ์ธ์ , ์ด๋ค ๊ณ๊ธฐ๋ก ๊ฒฝํ์ ์์ํ๋๊ฐ? (์ํฉ)
T (Task): ์ฃผ์ด์ง ๊ณผ์ ๋ ๋ชฉํ๋ ๋ฌด์์ด์๋๊ฐ? (๊ณผ์
)
A (Action): ๋ชฉํ ๋ฌ์ฑ์ ์ํด ๋ด๊ฐ ์ทจํ ๊ตฌ์ฒด์ ์ธ ํ๋๊ณผ ๋
ธ๋ ฅ์ ๋ฌด์์ด์๋๊ฐ? (ํ๋)
R (Result): ๊ทธ ๊ฒฐ๊ณผ๋ ์ด๋ ํ์ผ๋ฉฐ, ๋ฌด์์ ๋ฐฐ์ฐ๊ณ ๋๊ผ๋๊ฐ? (๊ฒฐ๊ณผ)
๊ธฐํ ๊ธฐ๋ฒ
CAR: Context (์ํฉ), Action (ํ๋), Result (๊ฒฐ๊ณผ)
IPARC: Idea (์์ด๋์ด), Plan (๊ณํ), Action (ํ๋), Result (๊ฒฐ๊ณผ), Change (๋ณํ)
โ
์ ์ถ ์ ์ต์ข
์ ๊ฒ์ฌํญ
์ง๋ถํ ํํ์ด๋ ๋น์ฐํ ๋ง์ ์ฌ์ฉํ์ง ์์๋๊ฐ?
์ค์๋ง, ์์ด, ์ ์กฐ์ด๋ฅผ ์ฌ์ฉํ์ง ์์๋๊ฐ?
์คํ์๋ ๋ฌธ๋ฒ ์ค๋ฅ๋ ์๋๊ฐ?
๐ ์์ฑ ์ ๊ฒ์ฌํญ
๊ฐ์ ๊ฒฝํ์ ์ค๋ณต ์ฌ์ฉํ์ง ์๊ณ , ๊ฐ ํญ๋ชฉ์ ๋ค๋ฅด๊ฒ ๊ตฌ์ฑํ๋๊ฐ?
ํ์ฌ๋ช
์ ์ ํํ ๊ธฐ์ฌํ๋๊ฐ?
ํ์ด์ง ๋ฒํธ์ ํ์ฌ ๋ก๊ณ ๋ฅผ ์ฝ์
ํ๋๊ฐ?
๋ด๊ฐ ์ง์ ์ฝ์์ ๋ โ์ฝ๊ณ ์ถ์ ์
์ฌ์ง์์โ๋ผ๊ณ ๋๊ปด์ง๋๊ฐ? (์ต์ 3๋ฒ ์ด์ ํ์ธ)
๐ ๊ฐ๋
์ฑ์ ๋์ด๋ ๋ฐฉ๋ฒ
๋ฌธ์ฅ์ ๊ธธ์ง ์๊ฒ, ํต์ฌ ์์ฃผ๋ก ์์ฑํ๋ค.
์ ๋, ์ ๊ฐ, ์ ์๋ก ๋ฌธ์ฅ์ ์์ํ์ง ์๋๋ค.
๋จ๋ฝ๊ณผ ๋ฌธ์ฅ ๊ฐ ๊ฐ๊ฒฉ์ ์ ์ ํ ์ฌ์ฉํด ๋์ ์ ๋ค์ด์ค๊ฒ ๊ตฌ์ฑํ๋ค.
๐ ๋ฉด์ ์ง๋ฌธ ๋๋น ์ฒดํฌ๋ฆฌ์คํธ
๐บ ์์ธ์ ํ๋
์์์ ๊ธฐ๋์ง ์๊ธฐ โ ํธํด์ง ๋ฐฉ์ง, ํ๋ฆฌ์ ์ด๊นจ ํด๊ธฐ
๋ค๋ฆฌ๋ ์์ ๋๋น๊น์ง๋ง ๋ฒ๋ฆฌ๊ธฐ
์ง๋ฌธ์ ํ ์ฌ๋์ ๋ณด๋ฉฐ ๋ต๋ณ
7์ด ๋ฏธ๋ง์ ์์ด์ปจํ ์ ์ง
๐ฃ๏ธ ๋งํ๊ธฐ ์ต๊ด
๋ง๋ ํ๋ฆฌ์ง ์๊ธฐ (ํ๋ฒ ์ค์)
์ถ์ธกยท์์ธก ๋ฐ์ธ์ ์ฃผ๊ด์ด ์์ด ๋ณด์ด๋ฏ๋ก ์ฃผ์
1๋ถ ์๊ธฐ์๊ฐ ์ค๋น
์๋ก : โOO ์ง์์ OOO์
๋๋ค.โ
๋ณธ๋ก : ์์ง๋์ด๋ก์์ ์ญ๋, ๋ํ ์ฌ๋ก, ๋ฌ์ฑ ๊ฒฝํ ์ ์
๊ฒฐ๋ก : ์ง์ ์ง๋ฌด์์ ์ฐ๊ฒฐ ๋ฐ ํฌ๋ถ
๐ฏ ์ง๋ฌด ๊ด๋ จ
์ง๋ฌด ์ดํด๋: ์ ๋ต์ด ์์ (์ด๋ก , ์๋ฆฌ, ๊ธฐ์ด ์ง์)
์ง๋ฌด ์ค๋น๋: ์ ๋ต ์์ (์ค๋น ๊ณผ์ ๊ณผ ๊ฒฝํ ์ค์ฌ)
์ง๋ฌด ์ ํฉ๋: ์ ๋ต ์์ (์กฐ์ง๊ณผ์ ์ด์ธ๋ฆผ, ๊ฐ์น๊ด)
๐ ์ด์ง ์ฌ์ ๋ต๋ณ
๋จ์ํ โ์ด์ง ์ด์ โ์๋ง ์ง์คํ์ง ๋ง๊ณ , ๋ฏธ๋ ๋น์ ๊ณผ ์ฐ๊ฒฐ
์ ๋ฌธ ์ง์ ํ์ โ ๊ต์ก ์๊ฐ โ ์ฐ์
๋ํฅยทํ์ฌ ๋น์ ๊ณผ ์ ํฉํ์ฌ ์ง์
์ฃผ์: ์ฌ๋๊ณผ์ ๊ด๊ณ ๋ฌธ์ ๋ก ์ธํ ์ด์ง์ ๋ถ์ ์ ํ๊ฐ
โ ์กฐ์ง์ ๋ค์ํ ๋ถ๋ฅ์ ์ฌ๋๋ค๋ก ๊ตฌ์ฑ๋จ
๐ ๊ธฐํ
์ฐ์ ์์๋ฅผ ์ฌ์ ๋ฆฝํ ์ ์๋ ์ญ๋์ ํค์ ์์ ๊ฐ์กฐ
๋งํ๋ ์ฐ์ต ํ์
None
ยท 2025-08-13
-
Day5
DAY5
โ
Dedicated Processor RegFile
R1 = 0;
R2 = 0;
while(R1 <= 10){
R2 = R2 + R1;
R1 = R1 + 1;
OutPort = R2;
}
โ
๋์๋ฐฉ์
โ
RegFile Asm
โ
์ฝ๋
DataPath.sv
`timescale 1ns / 1ps
module DataPath(
input logic clk,
input logic reset,
input logic RFSrcMuxSel,
input logic [2:0] RAddr1,
input logic [2:0] RAddr2,
input logic [2:0] WAddr,
input logic we,
output logic R1Le10,
input logic OutPortEn,
output logic [7:0] OutPort
);
logic [7:0] AdderResult, RFSrcMuxOut;
logic [7:0] RData1, RData2;
mux_2X1 U_RFSrcMux (
.sel (RFSrcMuxSel),
.x0 (AdderResult),
.x1 (1),
.y (RFSrcMuxOut)
);
RegFile U_RegFile (
.clk (clk),
.RAddr1 (RAddr1),
.RAddr2 (RAddr2),
.WAddr (WAddr),
.we (we),
.WData (RFSrcMuxOut),
.RData1 (RData1),
.RData2 (RData2)
);
comparator U_R1Le10 (
.a (RData1),
.b (8'd10),
.lt (R1Le10)
);
adder U_Adder (
.a (RData1),
.b (RData2),
.sum (AdderResult)
);
register U_OutPort (
.clk (clk),
.reset (reset),
.en (OutPortEn),
.d (RData1),
.q (OutPort)
);
endmodule
module RegFile (
input logic clk,
input logic [2:0] RAddr1,
input logic [2:0] RAddr2,
input logic [2:0] WAddr,
input logic we,
input logic [7:0] WData,
output logic [7:0] RData1,
output logic [7:0] RData2
);
logic [7:0] mem [0:2**3-1]; // 8bit 8๊ฐ (Addr ๊ฐ์)
always_ff @(posedge clk) begin
if(we) begin
mem[WAddr] <= WData;
end
end
assign RData1 = (RAddr1 == 0) ? 8'b0 : mem[RAddr1];
assign RData2 = (RAddr2 == 0) ? 8'b0 : mem[RAddr2];
endmodule
module register (
input logic clk,
input logic reset,
input logic en,
input logic [7:0] d,
output logic [7:0] q
);
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
q <= 0;
end
else begin
if(en) begin
q <= d;
end
end
end
endmodule
module mux_2X1 (
input logic sel,
input logic [7:0] x0,
input logic [7:0] x1,
output logic [7:0] y
);
always_comb begin
y = 8'b0;
case (sel)
1'b0: y = x0;
1'b1: y = x1;
endcase
end
endmodule
module adder (
input logic [7:0] a,
input logic [7:0] b,
output logic [7:0] sum
);
assign sum = a + b;
endmodule
module comparator (
input logic [7:0] a,
input logic [7:0] b,
output logic lt
);
assign lt = a <= b;
endmodule
ControlUnit
-
DedicatedProcessor ALUOP
DedicatedProcessor ALUOP
โ
๊ณผ์
โ๏ธ ์ฝ๋ โ๏ธ
โ๏ธ[DedicatedProcessor ALUOP.sv]
โ
Schematic
โ
์๋ฎฌ๋ ์ด์
โ
๋ถ์
๋ฐ๋ณต๋ณ ๋ ์ง์คํฐ ๊ฐ
1ํ: R1=3, R2=2, R3=3, R4=5 โ Yes
2ํ: R1=7, R2=6, R3=9, R4=15 โ Yes
3ํ: R1=15, R2=14, R3=21, R4=35 โ Yes
4ํ: R1=31, R2=30, R3=45, R4=75 โ Yes
5ํ: R1=63, R2=62, R3=93, R4=155 โ Yes
6ํ: R1=127, R2=126, R3=189, R4=59 โ No โ halt
โก๏ธ ์ฒซ ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (1, 0, 0, 0)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (1 + 1 = 2) โ (1, **2**, 0, 0)
R3 = R2 + R1 (2 + 1 = 3) โ (1, 2, **3**, 0)
R4 = R3 - R1 (3 - 1 = 2) โ (1, 2, 3, **2**)
R1 = R1 | R2 (1 | 2 = 3) โ (**3**, 2, 3, 2)
R4 = R4 & R3 (2 & 3 = 2) โ (3, 2, 3, **2**)
R4 = R2 + R3 (2 + 3 = 5) โ (3, 2, 3, **5**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (5 > 2) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ๋ ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (3, 2, 3, 5)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (3 + 3 = 6) โ (3, **6**, 3, 5)
R3 = R2 + R1 (6 + 3 = 9) โ (3, 6, **9**, 5)
R4 = R3 - R1 (9 - 3 = 6) โ (3, 6, 9, **6**)
R1 = R1 | R2 (3 | 6 = 7) โ (**7**, 6, 9, 6)
R4 = R4 & R3 (6 & 9 = 0) โ (7, 6, 9, **0**)
R4 = R2 + R3 (6 + 9 = 15) โ (7, 6, 9, **15**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (15 > 6) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ์ธ ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (7, 6, 9, 15)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (7 + 7 = 14) โ (7, **14**, 9, 15)
R3 = R2 + R1 (14 + 7 = 21) โ (7, 14, **21**, 15)
R4 = R3 - R1 (21 - 7 = 14) โ (7, 14, 21, **14**)
R1 = R1 | R2 (7 | 14 = 15) โ (**15**, 14, 21, 14)
R4 = R4 & R3 (14 & 21 = 4) โ (15, 14, 21, **4**)
R4 = R2 + R3 (14 + 21 = 35) โ (15, 14, 21, **35**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (35 > 14) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ๋ค ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (15, 14, 21, 35)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (15 + 15 = 30) โ (15, **30**, 21, 35)
R3 = R2 + R1 (30 + 15 = 45) โ (15, 30, **45**, 35)
R4 = R3 - R1 (45 - 15 = 30) โ (15, 30, 45, **30**)
R1 = R1 | R2 (15 | 30 = 31) โ (**31**, 30, 45, 30)
R4 = R4 & R3 (30 & 45 = 12) โ (31, 30, 45, **12**)
R4 = R2 + R3 (30 + 45 = 75) โ (31, 30, 45, **75**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (75 > 30) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ๋ค์ฏ ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (31, 30, 45, 75)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (31 + 31 = 62) โ (31, **62**, 45, 75)
R3 = R2 + R1 (62 + 31 = 93) โ (31, 62, **93**, 75)
R4 = R3 - R1 (93 - 31 = 62) โ (31, 62, 93, **62**)
R1 = R1 | R2 (31 | 62 = 63) โ (**63**, 62, 93, 62)
R4 = R4 & R3 (62 & 93 = 28) โ (63, 62, 93, **28**)
R4 = R2 + R3 (62 + 93 = 155) โ (63, 62, 93, **155**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (155 > 62) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ์ฌ์ฏ ๋ฒ์งธ ๋ฐ๋ณต (๋ง์ง๋ง)
์์ ๊ฐ: (R1, R2, R3, R4) = (63, 62, 93, 155)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (63 + 63 = 126) โ (63, **126**, 93, 155)
R3 = R2 + R1 (126 + 63 = 189) โ (63, 126, **189**, 155)
R4 = R3 - R1 (189 - 63 = 126) โ (63, 126, 189, **126**)
R1 = R1 | R2 (63 | 126 = 127) โ (**127**, 126, 189, 126)
R4 = R4 & R3 (126 & 189 = 120) โ (127, 126, 189, **120**)
R4 = R2 + R3 (126 + 189 = 315)
8-bit Wrapping (์ค๋ฒํ๋ก์ฐ): 8๋นํธ ๋ ์ง์คํฐ๋ 255๊น์ง๋ง ํํ ๊ฐ๋ฅํ๋ฏ๋ก, 315๋ 256์ ๋บ ๋๋จธ์ง ๊ฐ์ธ 59๊ฐ ๋๋ค. (315 - 256 = 59)
R4 ์ต์ข
๊ฐ โ (127, 126, 189, **59**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (59 > 126) โ โ No, ์ค๋จ (Halt)
-
DedicatedProcessor ALUOP
DedicatedProcessor ALUOP
โ
DedicatedProcessor_ALUOP.sv
`timescale 1ns / 1ps
module DedicatedProcessor_ALUOP(
input logic clk,
input logic reset,
output logic [7:0] OutPort
);
logic RFSrcMuxSel;
logic [2:0] RAddr1;
logic [2:0] RAddr2;
logic [2:0] WAddr;
logic [1:0] AluOpMuxSel;
logic we;
logic Lt;
logic OutPortEn;
DataPath U_DataPath (
.clk (clk),
.reset (reset),
.RFSrcMuxSel(RFSrcMuxSel),
.RAddr1 (RAddr1),
.RAddr2 (RAddr2),
.WAddr (WAddr),
.AluOpMuxSel(AluOpMuxSel),
.we (we),
.Lt (Lt),
.OutPortEn (OutPortEn),
.OutPort (OutPort)
);
ControlUnit U_ControlUnit (
.clk (clk),
.reset (reset),
.RFSrcMuxSel(RFSrcMuxSel),
.RAddr1 (RAddr1),
.RAddr2 (RAddr2),
.WAddr (WAddr),
.AluOpMuxSel(AluOpMuxSel),
.we (we),
.Lt (Lt),
.OutPortEn (OutPortEn)
);
endmodule
โ
DataPath.sv
`timescale 1ns / 1ps
module DataPath (
input logic clk,
input logic reset,
input logic RFSrcMuxSel,
input logic [2:0] RAddr1,
input logic [2:0] RAddr2,
input logic [2:0] WAddr,
input logic [1:0] AluOpMuxSel,
input logic we,
output logic Lt,
input logic OutPortEn,
output logic [7:0] OutPort
);
logic [7:0] AdderResult, RFSrcMuxOut;
logic [7:0] RData1, RData2;
mux_2x1 U_RFSrcMux (
.sel(RFSrcMuxSel),
.x0 (AdderResult),
.x1 (1),
.y (RFSrcMuxOut)
);
RegFile U_RegFile (
.clk (clk),
.RAddr1(RAddr1),
.RAddr2(RAddr2),
.WAddr (WAddr),
.we (we),
.WData (RFSrcMuxOut),
.RData1(RData1),
.RData2(RData2)
);
comparator U_comparator (
.a (RData1),
.b (RData2),
.lt (Lt)
);
alu_op U_ALU_OP (
.x0 (RData1),
.x1 (RData2),
.AluOpMuxSel(AluOpMuxSel),
.y (AdderResult)
);
register U_OutPort (
.clk (clk),
.reset(reset),
.en (OutPortEn),
.d (RData1),
.q (OutPort)
);
endmodule
โ
alu_op ์ถ๊ฐ
module alu_op (
input logic [7:0] x0,
input logic [7:0] x1,
input logic [1:0] AluOpMuxSel,
output logic [7:0] y
);
always_comb begin
y = 8'b00;
case (AluOpMuxSel)
2'b00: begin
y = x0 + x1;
end
2'b01: begin
y = x0 - x1;
end
2'b10: begin
y = x0 & x1;
end
2'b11: begin
y = x0 | x1;
end
endcase
end
endmodule
โ
ControlUnit
`timescale 1ns / 1ps
module ControlUnit (
input logic clk,
input logic reset,
output logic RFSrcMuxSel,
output logic [2:0] RAddr1,
output logic [2:0] RAddr2,
output logic [2:0] WAddr,
output logic [1:0] AluOpMuxSel,
output logic we,
input logic Lt,
output logic OutPortEn
);
typedef enum {
S0,
S1,
S2,
S3,
S4,
S5,
S6,
S7,
S8,
S9,
S10,
S11,
S12,
S13
} state_e;
state_e state, next_state;
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
state <= S0;
end
else begin
state <= next_state;
end
end
always_comb begin
next_state = state;
RFSrcMuxSel = 0;
RAddr1 = 0;
RAddr2 = 0;
WAddr = 0;
AluOpMuxSel = 0;
we = 0;
OutPortEn = 0;
case (state)
S0:begin // R1 = 1
RFSrcMuxSel = 1;
RAddr1 = 0;
RAddr2 = 0;
WAddr = 1;
AluOpMuxSel = 0;
we = 1;
OutPortEn = 0;
next_state = S1;
end
S1:begin // R2 = 0
RFSrcMuxSel = 0;
RAddr1 = 0;
RAddr2 = 0;
WAddr = 3'h2;
AluOpMuxSel = 0;
we = 1;
OutPortEn = 0;
next_state = S2;
end
S2:begin // R3 = 0
RFSrcMuxSel = 0;
RAddr1 = 0;
RAddr2 = 0;
WAddr = 3'h3;
AluOpMuxSel = 0;
we = 1;
OutPortEn = 0;
next_state = S3;
end
S3:begin // R4 = 0
RFSrcMuxSel = 0;
RAddr1 = 0;
RAddr2 = 0;
WAddr = 3'h4;
AluOpMuxSel = 0;
we = 1;
OutPortEn = 0;
next_state = S4;
end
S4:begin // R2 = R1 + R1
RFSrcMuxSel = 0;
RAddr1 = 1;
RAddr2 = 1;
WAddr = 3'h2;
AluOpMuxSel = 0;
we = 1;
OutPortEn = 0;
next_state = S5;
end
S5:begin // R3 = R2 + R1
RFSrcMuxSel = 0;
RAddr1 = 3'h2;
RAddr2 = 1;
WAddr = 3'h3;
AluOpMuxSel = 0;
we = 1;
OutPortEn = 0;
next_state = S6;
end
S6:begin // R4 = R3 - R1
RFSrcMuxSel = 0;
RAddr1 = 3'h3;
RAddr2 = 1;
WAddr = 3'h4;
AluOpMuxSel = 1;
we = 1;
OutPortEn = 0;
next_state = S7;
end
S7:begin // R1 = R1 | R2
RFSrcMuxSel = 0;
RAddr1 = 3'h1;
RAddr2 = 3'h2;
WAddr = 3'h1;
AluOpMuxSel = 2'h3;
we = 1;
OutPortEn = 0;
next_state = S8;
end
S8:begin // R4 < R2
RFSrcMuxSel = 0;
RAddr1 = 3'h4;
RAddr2 = 3'h2;
WAddr = 0;
AluOpMuxSel = 0;
we = 0;
OutPortEn = 0;
if(Lt) next_state = S6;
else next_state = S9;
end
S9:begin // R4 = R4 & R3
RFSrcMuxSel = 0;
RAddr1 = 3'h4;
RAddr2 = 3'h3;
WAddr = 3'h4;
AluOpMuxSel = 2'h2;
we = 1;
OutPortEn = 0;
next_state = S10;
end
S10:begin // R4 = R2 + R3
RFSrcMuxSel = 0;
RAddr1 = 3'h2;
RAddr2 = 3'h3;
WAddr = 3'h4;
AluOpMuxSel = 2'h0;
we = 1;
OutPortEn = 0;
next_state = S11;
end
S11:begin // R4 > R2
RFSrcMuxSel = 0;
RAddr1 = 3'h4;
RAddr2 = 3'h2;
WAddr = 0;
AluOpMuxSel = 0;
we = 0;
OutPortEn = 0;
if(Lt) next_state = S12;
else next_state = S4;
end
S12:begin // OutPut
RFSrcMuxSel = 0;
RAddr1 = 3'h4;
RAddr2 = 0;
WAddr = 0;
AluOpMuxSel = 0;
we = 0;
OutPortEn = 1;
next_state = S13;
end
S13:begin // halt
RFSrcMuxSel = 0;
RAddr1 = 0;
RAddr2 = 0;
WAddr = 0;
AluOpMuxSel = 0;
we = 0;
OutPortEn = 0;
next_state = S13;
end
endcase
end
endmodule
-
-
DedicatedProcessor Adder
DedicatedProcessor Adder
โ
๊ณผ์
โ๏ธ ์ฝ๋ โ๏ธ
โ๏ธ[DedicatedProcessor ALUOP.sv]
โ
Schematic
โ
์๋ฎฌ๋ ์ด์
โ
๋ถ์
๋ฐ๋ณต๋ณ ๋ ์ง์คํฐ ๊ฐ
1ํ: R1=3, R2=2, R3=3, R4=5 โ Yes
2ํ: R1=7, R2=6, R3=9, R4=15 โ Yes
3ํ: R1=15, R2=14, R3=21, R4=35 โ Yes
4ํ: R1=31, R2=30, R3=45, R4=75 โ Yes
5ํ: R1=63, R2=62, R3=93, R4=155 โ Yes
6ํ: R1=127, R2=126, R3=189, R4=59 โ No โ halt
โก๏ธ ์ฒซ ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (1, 0, 0, 0)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (1 + 1 = 2) โ (1, **2**, 0, 0)
R3 = R2 + R1 (2 + 1 = 3) โ (1, 2, **3**, 0)
R4 = R3 - R1 (3 - 1 = 2) โ (1, 2, 3, **2**)
R1 = R1 | R2 (1 | 2 = 3) โ (**3**, 2, 3, 2)
R4 = R4 & R3 (2 & 3 = 2) โ (3, 2, 3, **2**)
R4 = R2 + R3 (2 + 3 = 5) โ (3, 2, 3, **5**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (5 > 2) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ๋ ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (3, 2, 3, 5)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (3 + 3 = 6) โ (3, **6**, 3, 5)
R3 = R2 + R1 (6 + 3 = 9) โ (3, 6, **9**, 5)
R4 = R3 - R1 (9 - 3 = 6) โ (3, 6, 9, **6**)
R1 = R1 | R2 (3 | 6 = 7) โ (**7**, 6, 9, 6)
R4 = R4 & R3 (6 & 9 = 0) โ (7, 6, 9, **0**)
R4 = R2 + R3 (6 + 9 = 15) โ (7, 6, 9, **15**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (15 > 6) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ์ธ ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (7, 6, 9, 15)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (7 + 7 = 14) โ (7, **14**, 9, 15)
R3 = R2 + R1 (14 + 7 = 21) โ (7, 14, **21**, 15)
R4 = R3 - R1 (21 - 7 = 14) โ (7, 14, 21, **14**)
R1 = R1 | R2 (7 | 14 = 15) โ (**15**, 14, 21, 14)
R4 = R4 & R3 (14 & 21 = 4) โ (15, 14, 21, **4**)
R4 = R2 + R3 (14 + 21 = 35) โ (15, 14, 21, **35**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (35 > 14) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ๋ค ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (15, 14, 21, 35)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (15 + 15 = 30) โ (15, **30**, 21, 35)
R3 = R2 + R1 (30 + 15 = 45) โ (15, 30, **45**, 35)
R4 = R3 - R1 (45 - 15 = 30) โ (15, 30, 45, **30**)
R1 = R1 | R2 (15 | 30 = 31) โ (**31**, 30, 45, 30)
R4 = R4 & R3 (30 & 45 = 12) โ (31, 30, 45, **12**)
R4 = R2 + R3 (30 + 45 = 75) โ (31, 30, 45, **75**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (75 > 30) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ๋ค์ฏ ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (31, 30, 45, 75)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (31 + 31 = 62) โ (31, **62**, 45, 75)
R3 = R2 + R1 (62 + 31 = 93) โ (31, 62, **93**, 75)
R4 = R3 - R1 (93 - 31 = 62) โ (31, 62, 93, **62**)
R1 = R1 | R2 (31 | 62 = 63) โ (**63**, 62, 93, 62)
R4 = R4 & R3 (62 & 93 = 28) โ (63, 62, 93, **28**)
R4 = R2 + R3 (62 + 93 = 155) โ (63, 62, 93, **155**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (155 > 62) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ์ฌ์ฏ ๋ฒ์งธ ๋ฐ๋ณต (๋ง์ง๋ง)
์์ ๊ฐ: (R1, R2, R3, R4) = (63, 62, 93, 155)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (63 + 63 = 126) โ (63, **126**, 93, 155)
R3 = R2 + R1 (126 + 63 = 189) โ (63, 126, **189**, 155)
R4 = R3 - R1 (189 - 63 = 126) โ (63, 126, 189, **126**)
R1 = R1 | R2 (63 | 126 = 127) โ (**127**, 126, 189, 126)
R4 = R4 & R3 (126 & 189 = 120) โ (127, 126, 189, **120**)
R4 = R2 + R3 (126 + 189 = 315)
8-bit Wrapping (์ค๋ฒํ๋ก์ฐ): 8๋นํธ ๋ ์ง์คํฐ๋ 255๊น์ง๋ง ํํ ๊ฐ๋ฅํ๋ฏ๋ก, 315๋ 256์ ๋บ ๋๋จธ์ง ๊ฐ์ธ 59๊ฐ ๋๋ค. (315 - 256 = 59)
R4 ์ต์ข
๊ฐ โ (127, 126, 189, **59**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (59 > 126) โ โ No, ์ค๋จ (Halt)
-
DedicatedProcessor Counter
DedicatedProcessor Counter
โ
๊ณผ์
โ๏ธ ์ฝ๋ โ๏ธ
โ๏ธ[DedicatedProcessor ALUOP.sv]
โ
Schematic
โ
์๋ฎฌ๋ ์ด์
โ
๋ถ์
๋ฐ๋ณต๋ณ ๋ ์ง์คํฐ ๊ฐ
1ํ: R1=3, R2=2, R3=3, R4=5 โ Yes
2ํ: R1=7, R2=6, R3=9, R4=15 โ Yes
3ํ: R1=15, R2=14, R3=21, R4=35 โ Yes
4ํ: R1=31, R2=30, R3=45, R4=75 โ Yes
5ํ: R1=63, R2=62, R3=93, R4=155 โ Yes
6ํ: R1=127, R2=126, R3=189, R4=59 โ No โ halt
โก๏ธ ์ฒซ ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (1, 0, 0, 0)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (1 + 1 = 2) โ (1, **2**, 0, 0)
R3 = R2 + R1 (2 + 1 = 3) โ (1, 2, **3**, 0)
R4 = R3 - R1 (3 - 1 = 2) โ (1, 2, 3, **2**)
R1 = R1 | R2 (1 | 2 = 3) โ (**3**, 2, 3, 2)
R4 = R4 & R3 (2 & 3 = 2) โ (3, 2, 3, **2**)
R4 = R2 + R3 (2 + 3 = 5) โ (3, 2, 3, **5**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (5 > 2) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ๋ ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (3, 2, 3, 5)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (3 + 3 = 6) โ (3, **6**, 3, 5)
R3 = R2 + R1 (6 + 3 = 9) โ (3, 6, **9**, 5)
R4 = R3 - R1 (9 - 3 = 6) โ (3, 6, 9, **6**)
R1 = R1 | R2 (3 | 6 = 7) โ (**7**, 6, 9, 6)
R4 = R4 & R3 (6 & 9 = 0) โ (7, 6, 9, **0**)
R4 = R2 + R3 (6 + 9 = 15) โ (7, 6, 9, **15**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (15 > 6) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ์ธ ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (7, 6, 9, 15)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (7 + 7 = 14) โ (7, **14**, 9, 15)
R3 = R2 + R1 (14 + 7 = 21) โ (7, 14, **21**, 15)
R4 = R3 - R1 (21 - 7 = 14) โ (7, 14, 21, **14**)
R1 = R1 | R2 (7 | 14 = 15) โ (**15**, 14, 21, 14)
R4 = R4 & R3 (14 & 21 = 4) โ (15, 14, 21, **4**)
R4 = R2 + R3 (14 + 21 = 35) โ (15, 14, 21, **35**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (35 > 14) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ๋ค ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (15, 14, 21, 35)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (15 + 15 = 30) โ (15, **30**, 21, 35)
R3 = R2 + R1 (30 + 15 = 45) โ (15, 30, **45**, 35)
R4 = R3 - R1 (45 - 15 = 30) โ (15, 30, 45, **30**)
R1 = R1 | R2 (15 | 30 = 31) โ (**31**, 30, 45, 30)
R4 = R4 & R3 (30 & 45 = 12) โ (31, 30, 45, **12**)
R4 = R2 + R3 (30 + 45 = 75) โ (31, 30, 45, **75**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (75 > 30) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ๋ค์ฏ ๋ฒ์งธ ๋ฐ๋ณต
์์ ๊ฐ: (R1, R2, R3, R4) = (31, 30, 45, 75)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (31 + 31 = 62) โ (31, **62**, 45, 75)
R3 = R2 + R1 (62 + 31 = 93) โ (31, 62, **93**, 75)
R4 = R3 - R1 (93 - 31 = 62) โ (31, 62, 93, **62**)
R1 = R1 | R2 (31 | 62 = 63) โ (**63**, 62, 93, 62)
R4 = R4 & R3 (62 & 93 = 28) โ (63, 62, 93, **28**)
R4 = R2 + R3 (62 + 93 = 155) โ (63, 62, 93, **155**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (155 > 62) โ โ
Yes, ๊ณ์ ์งํ
โก๏ธ ์ฌ์ฏ ๋ฒ์งธ ๋ฐ๋ณต (๋ง์ง๋ง)
์์ ๊ฐ: (R1, R2, R3, R4) = (63, 62, 93, 155)
**๊ณ์ฐ ์์**
R2 = R1 + R1 (63 + 63 = 126) โ (63, **126**, 93, 155)
R3 = R2 + R1 (126 + 63 = 189) โ (63, 126, **189**, 155)
R4 = R3 - R1 (189 - 63 = 126) โ (63, 126, 189, **126**)
R1 = R1 | R2 (63 | 126 = 127) โ (**127**, 126, 189, 126)
R4 = R4 & R3 (126 & 189 = 120) โ (127, 126, 189, **120**)
R4 = R2 + R3 (126 + 189 = 315)
8-bit Wrapping (์ค๋ฒํ๋ก์ฐ): 8๋นํธ ๋ ์ง์คํฐ๋ 255๊น์ง๋ง ํํ ๊ฐ๋ฅํ๋ฏ๋ก, 315๋ 256์ ๋บ ๋๋จธ์ง ๊ฐ์ธ 59๊ฐ ๋๋ค. (315 - 256 = 59)
R4 ์ต์ข
๊ฐ โ (127, 126, 189, **59**)
์กฐ๊ฑด ํ์ธ: R4 > R2 (59 > 126) โ โ No, ์ค๋จ (Halt)
-
DedicatedProcessor Adder
DedicatedProcessor Adder
โ
top.sv
`timescale 1ns / 1ps
module top(
input logic clk,
input logic reset,
output logic [3:0] fndCom,
output logic [7:0] fndFont
);
logic [ 7:0] OutPort;
logic clk_10hz;
clk_divider U_CLK_DIV (
.clk (clk),
.reset (reset),
.clk_10hz (clk_10hz)
);
DedicatedProcessor_Adder U_DedicatedProcessor_Adder (
.clk (clk_10hz),
.reset (reset),
.OutPort (OutPort)
);
fndController U_fndController (
.clk (clk),
.reset (reset),
.number (OutPort),
.fndCom (fndCom),
.fndFont (fndFont)
);
endmodule
module clk_divider (
input logic clk,
input logic reset,
output logic clk_10hz
);
logic [$clog2(10_000_000)-1:0] div_counter;
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
div_counter <= 0;
clk_10hz <= 0;
end
else begin
if(div_counter == 10_000_000 - 1)begin
div_counter <= 0;
clk_10hz <= 1;
end
else begin
div_counter <= div_counter + 1;
clk_10hz <= 0;
end
end
end
endmodule
โ
DedicatedProcessor_Adder.sv
`timescale 1ns / 1ps
module DedicatedProcessor_Adder(
input logic clk,
input logic reset,
output logic [ 7:0] OutPort
);
logic SumSrcMuxSel;
logic ISrcMuxSel;
logic AdderSrcMuxSel;
logic SumEn;
logic IEn;
logic ILe10;
logic OutPortEn;
DataPath U_DataPath (
.clk (clk),
.reset (reset),
.SumSrcMuxSel (SumSrcMuxSel),
.ISrcMuxSel (ISrcMuxSel),
.AdderSrcMuxSel (AdderSrcMuxSel),
.SumEn (SumEn),
.IEn (IEn),
.ILe10 (ILe10),
.OutPortEn (OutPortEn),
.OutPort (OutPort)
);
ControlUnit U_ControlUnit (
.clk (clk),
.reset (reset),
.ILe10 (ILe10),
.SumSrcMuxSel (SumSrcMuxSel),
.ISrcMuxSel (ISrcMuxSel),
.AdderSrcMuxSel (AdderSrcMuxSel),
.SumEn (SumEn),
.IEn (IEn),
.OutPortEn (OutPortEn)
);
endmodule
โ
DataPath.sv
`timescale 1ns / 1ps
module DataPath(
input logic clk,
input logic reset,
input logic SumSrcMuxSel,
input logic ISrcMuxSel,
input logic AdderSrcMuxSel,
input logic SumEn,
input logic IEn,
output logic ILe10,
input logic OutPortEn,
output logic [7:0] OutPort
);
logic [7:0] SumSrcMuxOut, ISrcMuxOut;
logic [7:0] SumRegOut, IRegOut;
logic [7:0] AdderResult, AdderSrcMuxOut;
mux_2X1 U_SumSrcMux (
.sel (SumSrcMuxSel),
.x0 (0),
.x1 (AdderResult),
.y (SumSrcMuxOut)
);
mux_2X1 U_ISrcMux (
.sel (ISrcMuxSel),
.x0 (0),
.x1 (AdderResult),
.y (ISrcMuxOut)
);
register U_SUM_REG (
.clk (clk),
.reset (reset),
.en (SumEn),
.d (SumSrcMuxOut),
.q (SumRegOut)
);
register U_I_Reg (
.clk (clk),
.reset (reset),
.en (IEn),
.d (ISrcMuxOut),
.q (IRegOut)
);
comparator U_ILe10 (
.a (IRegOut),
.b (8'd10),
.lt (ILe10)
);
mux_2X1 U_AdderSrcMux (
.sel (AdderSrcMuxSel),
.x0 (SumRegOut),
.x1 (1),
.y (AdderSrcMuxOut)
);
adder U_Adder (
.a (AdderSrcMuxOut),
.b (IRegOut),
.sum (AdderResult)
);
register U_OutPort (
.clk (clk),
.reset (reset),
.en (OutPortEn),
.d (SumRegOut),
.q (OutPort)
);
endmodule
โ
ControlUnit.sv
`timescale 1ns / 1ps
module ControlUnit(
input logic clk,
input logic reset,
input logic ILe10,
output logic SumSrcMuxSel,
output logic ISrcMuxSel,
output logic AdderSrcMuxSel,
output logic SumEn,
output logic IEn,
output logic OutPortEn
);
typedef enum {
S0,
S1,
S2,
S3,
S4,
S5
} state_e;
state_e state, next_state;
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
state <= S0;
end
else begin
state <= next_state;
end
end
always_comb begin
next_state = state;
SumSrcMuxSel = 0;
ISrcMuxSel = 0;
SumEn = 0;
IEn = 0;
AdderSrcMuxSel = 0;
OutPortEn = 0;
case (state)
S0:begin
SumSrcMuxSel = 0;
ISrcMuxSel = 0;
SumEn = 1;
IEn = 1;
AdderSrcMuxSel = 0;
OutPortEn = 0;
next_state = S1;
end
S1:begin
SumSrcMuxSel = 0;
ISrcMuxSel = 0;
SumEn = 0;
IEn = 0;
AdderSrcMuxSel = 0;
OutPortEn = 0;
if(ILe10) next_state = S2;
else next_state = S5;
end
S2:begin
SumSrcMuxSel = 1;
ISrcMuxSel = 1;
SumEn = 1;
IEn = 0;
AdderSrcMuxSel = 0;
OutPortEn = 0;
next_state = S3;
end
S3:begin
SumSrcMuxSel = 1;
ISrcMuxSel = 1;
SumEn = 0;
IEn = 1;
AdderSrcMuxSel = 1;
OutPortEn = 0;
next_state = S4;
end
S4:begin
SumSrcMuxSel = 1;
ISrcMuxSel = 1;
SumEn = 0;
IEn = 0;
AdderSrcMuxSel = 0;
OutPortEn = 1;
next_state = S1;
end
S5:begin
SumSrcMuxSel = 1;
ISrcMuxSel = 1;
SumEn = 0;
IEn = 0;
AdderSrcMuxSel = 0;
OutPortEn = 0;
next_state = S5;
end
endcase
end
endmodule
-
DedicatedProcessor Counter
DedicatedProcessor Counter
โ
DedicatedProcessor Counter
`timescale 1ns / 1ps
module DedicatedProcessor_Counter(
input logic clk,
input logic reset,
output logic [7:0] OutBuffer
);
logic ASrcMuxsel, AEn, OutBufEn, ALt10;
logic [$clog2(100_000_000 / 10)-1:0] div_counter;
logic clk_10hz;
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
div_counter <= 0;
end
else begin
if(div_counter == 10_000_000 - 1) begin
div_counter <= 0;
clk_10hz <= 1'b1;
end
else begin
div_counter <= div_counter + 1;
clk_10hz <= 0;
end
end
end
DataPath U_DataPath (
.clk (clk_10hz),
.*
);
ControlUnit U_ControlUnit (
.clk (clk_10hz),
.*
);
endmodule
module DataPath(
input logic clk,
input logic reset,
input logic ASrcMuxsel,
input logic AEn,
output logic ALt10,
input logic OutBufEn,
output logic [7:0] OutBuffer
);
logic [7:0] AdderResult, ASrcMuxOut, ARegOut;
mux_2X1 U_ASrcMux (
.sel (ASrcMuxsel),
.x0 (8'h0),
.x1 (AdderResult),
.y (ASrcMuxOut)
);
register U_Register (
.clk (clk),
.reset (reset),
.en (AEn),
.d (ASrcMuxOut),
.q (ARegOut)
);
register U_OutReg (
.clk (clk),
.reset (reset),
.en (OutBufEn),
.d (ARegOut),
.q (OutBuffer)
);
comparator U_Comparator(
.a (ARegOut),
.b (8'd10),
.lt (ALt10)
);
adder U_Adder (
.a (ARegOut),
.b (8'd1),
.sum (AdderResult)
);
/*
OutBuf U_OutBuf (
.en (OutBufEn),
.x (ARegOut),
.y (OutBuffer)
);
*/
endmodule
module register (
input logic clk,
input logic reset,
input logic en,
input logic [7:0] d,
output logic [7:0] q
);
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
q <= 0;
end
else begin
if(en) begin
q <= d;
end
end
end
endmodule
module mux_2X1 (
input logic sel,
input logic [7:0] x0,
input logic [7:0] x1,
output logic [7:0] y
);
always_comb begin
y = 8'b0;
case (sel)
1'b0: y = x0;
1'b1: y = x1;
endcase
end
endmodule
module adder (
input logic [7:0] a,
input logic [7:0] b,
output logic [7:0] sum
);
assign sum = a + b;
endmodule
module comparator (
input logic [7:0] a,
input logic [7:0] b,
output logic lt
);
assign lt = a < b;
endmodule
module OutBuf (
input logic en,
input logic [7:0] x,
output logic [7:0] y
);
assign y = en ? x : 8'bx;
endmodule
module ControlUnit(
input logic clk,
input logic reset,
input logic ALt10,
output logic ASrcMuxsel,
output logic AEn,
output logic OutBufEn
);
typedef enum {
S0,
S1,
S2,
S3,
S4
} state_e;
state_e state, next_state;
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
state <= S0;
end
else begin
state <= next_state;
end
end
always_comb begin
next_state = state;
ASrcMuxsel = 0;
AEn = 0;
OutBufEn = 0;
case (state)
S0:begin
ASrcMuxsel = 0;
AEn = 1;
OutBufEn = 0;
next_state = S1;
end
S1:begin
ASrcMuxsel = 1;
AEn = 0;
OutBufEn = 0;
if(ALt10) next_state = S2;
else next_state = S4;
end
S2:begin
ASrcMuxsel = 1;
AEn = 0;
OutBufEn = 1;
next_state = S3;
end
S3:begin
ASrcMuxsel = 1;
AEn = 1;
OutBufEn = 0;
next_state = S1;
end
S4:begin
ASrcMuxsel = 1;
AEn = 0;
OutBufEn = 0;
next_state = S4;
end
endcase
end
endmodule
-
Day3
DAY3
โ
UART (Universal Asynchronous Receiver/Transmitter)
1. ๋น๋๊ธฐ ํต์ ์ ์ ์
๋๊ธฐ(Synchronous)
์ก์์ ์ฅ์น๊ฐ ๋์ผํ ํด๋ก ์ ํธ๋ฅผ ๊ณต์
๋ฐ์ดํฐ์ ํด๋ก์ด ํจ๊ป ์ ์ก๋จ
์: SPI, I2C
๋น๋๊ธฐ(Asynchronous)
์ก์์ ์ฅ์น๊ฐ ํด๋ก ์ ํธ๋ฅผ ๊ณต์ ํ์ง ์์
๊ฐ์ ๋ด๋ถ ํ์ด๋จธ๋ก ๋นํธ ํ์ด๋ฐ์ ๋ง์ถค
์: UART
2. UART๊ฐ ๋น๋๊ธฐ์ธ ์ด์
ํด๋ก ๋ผ์ธ์ด ์์
UART๋ TX์ RX ๋ ์ ๋ง ์ฌ์ฉ
ํด๋ก ์ ํธ ์์ด ๋ฐ์ดํฐ๋ง ์ ์ก
Start/Stop ๋นํธ๋ก ๋๊ธฐํ
๋ฐ์ดํฐ ํ๋ ์ ์์: Start bit(0)
๋ฐ์ดํฐ ํ๋ ์ ์ข
๋ฃ: Stop bit(1)
์์ ์ธก์ Start bit ๊ฐ์ง ํ ๋ด๋ถ ํ์ด๋จธ๋ก ๋นํธ ์ํ๋ง
Baud Rate๋ก ์๊ฐ ๋๊ธฐํ
์๋, bps, ์ฃผํ์, ์๊ฐ
์ ํด๋์ ์๊ฐ๋ง๋ค ๋ฐ์ดํฐ๋ฅผ ์ฃผ๊ณ ๋ฐ์
์ก์ ์ธก๊ณผ ์์ ์ธก์ด ๋์ผํ baud rate๋ก ์ฝ์
ํด๋ก์ด ์์ผ๋ฏ๋ก, ์ค์ฐจ ๋ฒ์ ๋ด์์๋ง ์ ์ ์์ ๊ฐ๋ฅ
3. ๋์ ์๋ฆฌ
Idle ์ํ
๋ผ์ธ์ ๊ธฐ๋ณธ์ ์ผ๋ก HIGH(1) ์ํ
Start Bit
ํต์ ์์ ์ 1๋นํธ ๊ธธ์ด์ LOW(0) ์ ํธ ์ ์ก
Data Bits
LSB๋ถํฐ ์์ฐจ์ ์ผ๋ก ์ ์ก (์ผ๋ฐ์ ์ผ๋ก 8๋นํธ)
Parity Bit (์ต์
)
๋ฐ์ดํฐ ์ ์ก ์ค ์ค๋ฅ ๊ฒ์ถ์ฉ (Even, Odd)
๋ฐ์ดํฐ์ 1์ ๊ฐ์๊ฐ ์ง์, ํ์์ ๋ง์ถฐ์ ๋์
์ ์ฐ๋ ์ด์ ๋โ
Stop Bit
1๋นํธ ๊ธธ์ด์ HIGH(1) ์ ํธ๋ก ์ ์ก ์ข
๋ฃ ํ์
์์ ์ธก
์คํํธ ๋นํธ๋ฅผ ๊ฐ์ง ํ ์ ํด์ง baud rate์ ๋ง์ถฐ ๋นํธ ์ํ๋ง
Frame
1~5๋ฒ๊น์ง์ ๊ณผ์ ์ 1ํ๋ ์
โ
SPI (Universal Asynchronous Receiver/Transmitter)
โ
๋น๊ต (UART vs SPI vs I2C)
๊ตฌ๋ถ
UART
SPI
I2C
๋๊ธฐ๋ฐฉ์
๋น๋๊ธฐ
๋๊ธฐ
๋๊ธฐ
๊ด๊ณ ์
1:1
1:N
N:N
์ ๊ฐ์
2๊ฐ (TX, RX)
4๊ฐ (MISO, MOSI, SCK, CS)
2๊ฐ (SCL, SDA)
์๋
์ค๊ฐ (bps~Mbps)
๋งค์ฐ ๋น ๋ฆ (์์ญ Mbps)
์ค๊ฐ (100k~3.4Mbps)
์ฅ์
๊ฐ๋จ, ์ ์ ๋ ฅ
๋น ๋ฆ, ํ๋ํ๋ ์ค
๋ค์ค ์ฅ์น ์ฐ๊ฒฐ ์ฉ์ด
-
UART
DAY2
โ
๋ฒํผ ๊ตฌ์กฐ
๋ฒํผ์ ๋๋ฅผ ๋, ๋
ธ์ด์ฆ๋ ์ง๋์ ์ํด ์งง์ ์๊ฐ ๋ด์ ON/OFF๊ฐ ๋ฐ๋ณต๋จ
์ด ํ์์ ๋ฐ์ด์ค(Bounce) ๋ผ๊ณ ํ๋ฉฐ, ๋๋ฐ์ด์ฑ(Debounce) ์ฒ๋ฆฌ๊ฐ ํ์
โ
Shift Register๋ฅผ ์ด์ฉํ ๋๋ฐ์ด์ฑ
๐ก Shift Register ์ญํ
๋ฒํผ ์
๋ ฅ(in_data)์ 8ํด๋ญ ๋์ ์ํํธ ์ ์ฅ
sh_reg ๊ฐ์ด ์ ๋ถ 1์ด๋ฉด, ๋ฒํผ์ด ์์ ์ ์ผ๋ก ๋๋ฆผ ์ํ๋ผ๊ณ ํ๋จ
โ
shift_register ๋ชจ๋ ์ฝ๋
module shift_register (
input logic clk,
input logic reset,
input logic in_data,
output logic [7:0] out_data
);
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
out_data <= 0;
end
else begin
out_data <= {in_data, out_data[7:1]}; // right shift
//out_data <= {out_data[6:0], in_data}; // left shift
end
end
endmodule
โ
์ฃ์ง ๊ฒ์ถ๊ธฐ (Edge Detector)
๐ ๊ฐ์
๋๋ฐ์ด์ฑ๋ ๋ฒํผ ์
๋ ฅ(debounce)์ ๋ณํ๋ฅผ ๊ฐ์งํ์ฌ
์์น ์ฃ์ง(rising_edge)
ํ๊ฐ ์ฃ์ง(falling_edge)
๋๋ ๋ ๋ค(both_edge)๋ฅผ ๊ฒ์ถํ๋ ํ๋ก
โ
๋์ ์๋ฆฌ
edge_reg[1] โ ์ด์ ์ํ
edge_reg[0] โ ํ์ฌ ์ํ
๋ณํ ์กฐ๊ฑด
- ์์น ์ฃ์ง: ์ด์ 0 โ ํ์ฌ 1
- ํ๊ฐ ์ฃ์ง: ์ด์ 1 โ ํ์ฌ 0
- ๋ ๋ค: ๋ ์ค ํ๋๋ผ๋ ๋ฐ์ ์
assign debounce = &sh_reg;
//assign out_button = debounce;
logic [1:0] edge_reg;
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
edge_reg <= 0;
end
else begin
edge_reg[0] <= debounce;
edge_reg[1] <= edge_reg[0];
end
end
assign rising_edge = edge_reg[0] & ~edge_reg[1];
assign falling_edge = ~edge_reg[0] & edge_reg[1];
assign both_edge = rising_edge | falling_edge;
โ
์ ์ฒด ๊ตฌ์กฐ (Button Detector)
`timescale 1ns / 1ps
module button_detector(
input logic clk,
input logic reset,
input logic in_button,
output logic rising_edge,
output logic falling_edge,
output logic both_edge
);
logic clk_1khz;
logic debounce;
logic [7:0] sh_reg;
logic [$clog2(100000)-1:0] div_counter;
always_ff @(posedge clk or posedge reset) begin
if(reset)begin
div_counter <= 0;
clk_1khz <= 0;
end
else begin
if(div_counter == 100000 - 1)begin
clk_1khz <= 1;
div_counter <= 0;
end
else begin
div_counter <= div_counter + 1;
clk_1khz <= 0;
end
end
end
shift_register u_shift_register(
.clk (clk_1khz),
.reset (reset),
.in_data (in_button),
.out_data (sh_reg)
);
assign debounce = &sh_reg;
//assign out_button = debounce;
logic [1:0] edge_reg;
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
edge_reg <= 0;
end
else begin
edge_reg[0] <= debounce;
edge_reg[1] <= edge_reg[0];
end
end
assign rising_edge = edge_reg[0] & ~edge_reg[1];
assign falling_edge = ~edge_reg[0] & edge_reg[1];
assign both_edge = rising_edge | falling_edge;
endmodule
module shift_register (
input logic clk,
input logic reset,
input logic in_data,
output logic [7:0] out_data
);
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
out_data <= 0;
end
else begin
out_data <= {in_data, out_data[7:1]}; // right shift
//out_data <= {out_data[6:0], in_data}; // left shift
end
end
endmodule
โ
๊ฒ์ฆ (Test Bench)
ํด๋์ค ์ ์ (transaction)
rand bit button : ๋๋ค ์์ฑ 1๋นํธ ๋ฒํผ ๊ฐ
function bit run_random() : ํ์ฌ button ๊ฐ์ ๋ฐํ
class transaction;
rand bit button;
function bit run_random();
return button;
endfunction
endclass
์ด๊ธฐํ
clk = 0, reset = 1
10ns ํ reset = 0
in_button = 0์ผ๋ก ์ด๊ธฐํ, 20ns ๋๊ธฐ
๋ฒํผ ๋๋ฆ (Push)
in_button = 1๋ก ๋ณ๊ฒฝ
60ํ ๋ฐ๋ณต:
tr.randomize()๋ก ๋ฒํผ ๊ฐ ๋๋ค ์์ฑ
in_button์ ๋๋ค ๊ฐ ์ ์ฉ
1ns ๋๊ธฐ
in_button = 1๋ก ๊ณ ์ , 150ns ๋๊ธฐ
// push button
in_button = 1;
for(int i= 0; i < 60; i++)begin
tr.randomize();
in_button = tr.run_random();
#1;
end
in_button = 1;
#150;
๋ฒํผ ๋์ (Release)
in_button = 0์ผ๋ก ๋ณ๊ฒฝ
30ํ ๋ฐ๋ณต:
๋๋ค ๋ฒํผ ๊ฐ ์์ฑ ๋ฐ ์ ์ฉ
1ns ๋๊ธฐ
in_button = 0๋ก ๊ณ ์ , 100ns ๋๊ธฐ
in_button = 0;
for(int i= 0; i < 30; i++)begin
tr.randomize();
in_button = tr.run_random();
#1;
end
in_button = 0;
#100;
$finish;
โ
์ฃผ์ ํน์ง
๋ฒํผ ์
๋ ฅ ๋ฐ์ด์ค(Bounce) ํจ๊ณผ๋ฅผ ๋๋ค ํจํด์ผ๋ก ๊ตฌํ
์์น/ํ๊ฐ/์์ชฝ ์์ง ๊ฒ์ถ ๊ธฐ๋ฅ ๊ฒ์ฆ
ํด๋์ค ๊ธฐ๋ฐ ๋๋ค ์
๋ ฅ ์์ฑ์ผ๋ก ํ
์คํธ ํ์ฅ์ฑ ํ๋ณด
-
Day2
DAY2
โ
์กฐํฉ๋
ผ๋ฆฌํ๋ก vs ์์ฐจ๋
ผ๋ฆฌํ๋ก
ํญ๋ชฉ
์กฐํฉ๋
ผ๋ฆฌํ๋ก
์์ฐจ๋
ผ๋ฆฌํ๋ก
๋์ ๊ธฐ์ค
ํ์ฌ ์
๋ ฅ์๋ง ์์กด
ํ์ฌ ์
๋ ฅ + ๊ณผ๊ฑฐ ์ํ(๋ ์ง์คํฐ ๋ฑ)
ํด๋ก ์ฌ์ฉ ์ฌ๋ถ
ํด๋ก ์ฌ์ฉ ์ ํจ
ํด๋ก ์ฌ์ฉ (๋๊ธฐ์ ์ค๊ณ)
๋ฉ๋ชจ๋ฆฌ ๊ธฐ๋ฅ
์์
์์ (์ํ ์ ์ฅ ๊ฐ๋ฅ)
์์
AND, OR, MUX ๋ฑ
FSM, ๋ ์ง์คํฐ, ์นด์ดํฐ, ๋ฉ๋ชจ๋ฆฌ ๋ฑ
๐ก ์กฐํฉ ๋
ผ๋ฆฌ๋ ๋น ๋ฅด์ง๋ง ํ์ด๋ฐ ์ ์ด๊ฐ ์ด๋ ต๊ณ ๊ธ๋ฆฌ์น(glitch) ๋ฐ์ ๊ฐ๋ฅ์ฑ ์์.
๐ก ์์ฐจ ๋
ผ๋ฆฌ๋ ๋๊ธฐ์์ผ๋ก ์์ ์ ์ด๊ณ ์ ์ด๊ฐ ์ฌ์.
โ
Latch ์ Flip-Flop
Latch
ํด๋ก ์ ํธ ์์ด ๋์
์
๋ ฅ ์ ํธ์ ๋ฏผ๊ฐํ๊ฒ ๋ฐ์
๋ฉ๋ชจ๋ฆฌ ๊ธฐ๋ฅ ์์
Flip-Flop
ํด๋ก ์ฃ์ง(์์น/ํ๊ฐ)์ ๋ฐ์
์ฃ์ง ํธ๋ฆฌ๊ฑฐ ๋ฐฉ์์ผ๋ก ๋์
๋ ์์ ์ ์ธ ๋ฉ๋ชจ๋ฆฌ ์์
โ
SR Latch
Q์ /Q๋ ํญ์ ๋ฐ๋์ฌ์ผ ํจ.
์ํ ์ค๋ช
:
S
R
Q(next)
์ค๋ช
0
0
์ ์ง
์ด์ ์ํ ์ ์ง
0
1
0
Reset ์ํ
1
0
1
Set ์ํ
1
1
๋ถ์์
๊ธ์ง ์ํ (๋ฐ์ง ๊ฐ๋ฅ)
โ
D Latch
์
๋ ฅ์ ๋จ์ผํํ์ฌ S= D, R = Dโ ํํ๋ก ๊ตฌ์ฑ
Gate ์ ํธ๊ฐ enable ์ญํ
ํด๋ก์ ๋ฏผ๊ฐ (๋ ๋ฒจ ํธ๋ฆฌ๊ฑฐ ๋ฐฉ์)
โ
Gated D Latch & D Flip-Flop
Gated D Latch: Gate ์ ํธ๊ฐ high์ผ ๋๋ง ์
๋ ฅ ํ์ฉ
D Flip-Flop (Master-Slave ๊ตฌ์กฐ)
Master: ํด๋ก Low์ผ ๋ ์
๋ ฅ ์ ์ฅ
Slave: ํด๋ก High์ผ ๋ ์ถ๋ ฅ ์ ๋ฌ
์์น์ฃ์ง ๋๋ ํ๊ฐ์ฃ์ง์์๋ง ์ถ๋ ฅ ๋ณํ (์ฃ์ง ํธ๋ฆฌ๊ฑฐ)
โ
๋ฉํ์คํ
์ด๋ธ(Metastable)
ํด๋ก ์ฃ์ง ์์ ์ ์
๋ ฅ(D)์ด ๋ณํ๋ฉด ์ถ๋ ฅ์ด ์ผ์ ์๊ฐ ๋์ ๋ถ์์ ์ํ์ ๋น ์ง ์ ์์
์ด๋ฅผ ๋ฉํ์คํ
์ด๋ธ ํ์์ด๋ผ ํจ
์ค์ Timing Spec
ํญ๋ชฉ
์ค๋ช
Setup Time
ํด๋ก ์ฃ์ง ์ด์ ์ D ์
๋ ฅ์ด ์์ ์ ์ผ๋ก ์ ์ง๋์ด์ผ ํ๋ ์ต์ ์๊ฐ
Hold Time
ํด๋ก ์ฃ์ง ์ดํ์๋ D ์
๋ ฅ์ด ์ ์ง๋์ด์ผ ํ๋ ์ต์ ์๊ฐ
โ
Synchronizer
๋น๋๊ธฐ ์
๋ ฅ์ ๋๊ธฐํํ๋ ๊ตฌ์กฐ
D Flip-Flop 2๊ฐ ์ด์ ์ง๋ ฌ ์ฐ๊ฒฐ
์ฒซ ๋ฒ์งธ F/F: ์ ํธ ์์
๋ ๋ฒ์งธ F/F: ์์ ๋ ์ถ๋ ฅ ์์ฑ
๋ฉํ์คํ
์ด๋ธ ๋ฐฉ์ง๋ฅผ ์ํ ๋ํ์ ์ค๊ณ ๊ธฐ๋ฒ
โ
์ ํ ์ง์ฐ ์๊ฐ (Propagation Delay)
ํด๋ก โ ์ถ๋ ฅ๊น์ง ๊ฑธ๋ฆฌ๋ ์๊ฐ
์กฐํฉ ํ๋ก์ ๊น์ด์ ๋น๋ก
์: ๊ณฑ์
์ฐ์ฐ์ด ๋ง์ FFT ํ๋ก๋ ๋ ์ง์คํฐ ์ฝ์
ํ์
๐ ๋ฐ์ดํฐ์ํธ์์๋ clock-to-Q delay, t_pd, t_co ๋ฑ์ผ๋ก ๋ช
์๋จ
โ
๊ธ๋ฆฌ์น(Glitch)
์กฐํฉ ๋
ผ๋ฆฌ์์ ์
๋ ฅ์ด ๋์์ ๋ณํ์ง ์์ผ๋ฉด, ์ ํ ์ง์ฐ ์ฐจ์ด๋ก ์ธํด ์ผ์์ ์ธ ์ค๋ฅ ์ถ๋ ฅ ๋ฐ์ ๊ฐ๋ฅ
ํด๋ก ์ฃ์ง ์ง์ ๊ธ๋ฆฌ์น ๋ฐ์ ์ ์์คํ
์ค๋์ ๊ฐ๋ฅ์ฑ ์์
โ ๋ณต์กํ ์กฐํฉ ๋
ผ๋ฆฌ๋ ํผํ๊ณ , ์์ฐจ ํ๋ก๋ก ๋๋์ด ์ค๊ณํ๋ ๊ฒ์ด ์์ ํจ
โ
ํ์ดํ๋ผ์ด๋ ๊ธฐ๋ฒ
์ฐ์ฐ ์ค๊ฐ์ ๋ ์ง์คํฐ ์ฝ์
์ผ๋ก ํด๋ก ์ฃผ๊ธฐ๋ฅผ ๋ถํ
๋ณต์กํ ์ฐ์ฐ์ ์ฌ๋ฌ ํด๋ก ์ฌ์ดํด์ ๋๋์ด ์ฒ๋ฆฌ ๊ฐ๋ฅ
์กฐํฉ ๋
ผ๋ฆฌ ๊ธธ์ด๋ฅผ ์ค์ฌ ๊ธ๋ฆฌ์น ๋ฐฉ์ง ๋ฐ ํด๋ก ์ฌ์ ํ๋ณด
โ
AMBA APB ์์
AMBA APB ํ๋กํ ์ฝ๋ ๋ฉํ์คํ
์ด๋ธ๊ณผ ํด๋ก ๋๋ฉ์ธ ์ด์๋ฅผ ๊ณ ๋ คํ์ฌ ์ค๊ณ๋จ
๋๊ธฐํ ๊ตฌ์กฐ ๋ฐ์ ํ์
โ
๋ณด์ ๋ฐ ์ถ๊ฐ ์ค๋ช
ํ์ด๋ฐ ๋ถ์์ FPGA/ASIC ์ค๊ณ์ ํต์ฌ
Setup/Hold violation์ ๊ธฐ๋ฅ์ ๋ฌธ์ ์ ๋ฐ
CDC (Clock Domain Crossing) ์ค๊ณ์์๋ synchronizer ํ์
๊ธ๋ฆฌ์น๋ฅผ ์ค์ด๊ธฐ ์ํ ๋ฐฉ๋ฒ
์
๋ ฅ ์ ํธ ๋๊ธฐํ
๋ ์ง์คํฐ ์ฝ์
(ํ์ด๋ฐ ์ฌ์ ํ๋ณด)
์์ฐจ ๋
ผ๋ฆฌ ์ค๊ณ์์์ ํต์ฌ ์์น
ํญ์ ํด๋ก ๊ฒฝ๊ณ ๊ธฐ์ค์ผ๋ก ์ํ ๋ณํ ์ค๊ณ
์กฐํฉ ๋
ผ๋ฆฌ๋ ์ต์ํ
ํ์ด๋ฐ ๋ถ์์ FPGA/ASIC ์ค๊ณ์ ํต์ฌ ์์
Setup / Hold ํ์ด๋ฐ ์๋ฐ์ด ๋ฐ์ํ๋ฉด ํ๋ก ๋์์ด ๋น์ ์์ ์ผ๋ก ๋ ์ ์์
ํ์ด๋ฐ ์ ์ฝ ์กฐ๊ฑด์ ๋ง์กฑํ๋๋ก ์ค๊ณํ๊ณ , STA(Static Timing Analysis) ํ์ ์ํ
CDC (Clock Domain Crossing) ์ค๊ณ
์๋ก ๋ค๋ฅธ ํด๋ก ๋๋ฉ์ธ์ ์ค๊ฐ ๋ ๋ฉํ์คํ
์ด๋ธ ์ํ
ํด๊ฒฐ ๋ฐฉ๋ฒ:
2๋จ ์ด์ D Flip-Flop ์ง๋ ฌ ์ฐ๊ฒฐ (Synchronizer)
Handshake ๋๋ FIFO ๊ตฌ์กฐ ์ฌ์ฉ
๊ธ๋ฆฌ์น(Glitch) ์ค์ด๊ธฐ ์ํ ๋ฐฉ๋ฒ
์
๋ ฅ ์ ํธ๋ ๋ฐ๋์ ํด๋ก ๋๋ฉ์ธ์ ๋๊ธฐํ
์กฐํฉ ๋
ผ๋ฆฌ ๊ธธ์ด๊ฐ ๊ธธ ๊ฒฝ์ฐ ์ค๊ฐ์ ๋ ์ง์คํฐ ์ฝ์
ํ์ฌ ์์ ํ
ํ๋์ ํด๋ก ์ฌ์ดํด ๋ด์ ์ฐ์ฐ์ด ๋๋๋๋ก ์ค๊ณ
์์ฐจ ๋
ผ๋ฆฌ ์ค๊ณ ํต์ฌ ์์น
๋ชจ๋ ์ํ ๋ณํ๋ ํด๋ก ์ฃ์ง ๊ธฐ์ค์ผ๋ก ๊ฒฐ์ ๋์ด์ผ ํจ
์กฐํฉ ๋
ผ๋ฆฌ๋ ์ต์ํํ์ฌ ํ์ด๋ฐ ๋ณต์ก๋๋ฅผ ์ค์ด๊ณ , ์ ์ง/ํ์ฅ ๊ฐ๋ฅํ ์ค๊ณ ์งํฅ
-
Button Detector
DAY2
โ
๋ฒํผ ๊ตฌ์กฐ
๋ฒํผ์ ๋๋ฅผ ๋, ๋
ธ์ด์ฆ๋ ์ง๋์ ์ํด ์งง์ ์๊ฐ ๋ด์ ON/OFF๊ฐ ๋ฐ๋ณต๋จ
์ด ํ์์ ๋ฐ์ด์ค(Bounce) ๋ผ๊ณ ํ๋ฉฐ, ๋๋ฐ์ด์ฑ(Debounce) ์ฒ๋ฆฌ๊ฐ ํ์
โ
Shift Register๋ฅผ ์ด์ฉํ ๋๋ฐ์ด์ฑ
๐ก Shift Register ์ญํ
๋ฒํผ ์
๋ ฅ(in_data)์ 8ํด๋ญ ๋์ ์ํํธ ์ ์ฅ
sh_reg ๊ฐ์ด ์ ๋ถ 1์ด๋ฉด, ๋ฒํผ์ด ์์ ์ ์ผ๋ก ๋๋ฆผ ์ํ๋ผ๊ณ ํ๋จ
โ
shift_register ๋ชจ๋ ์ฝ๋
module shift_register (
input logic clk,
input logic reset,
input logic in_data,
output logic [7:0] out_data
);
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
out_data <= 0;
end
else begin
out_data <= {in_data, out_data[7:1]}; // right shift
//out_data <= {out_data[6:0], in_data}; // left shift
end
end
endmodule
โ
์ฃ์ง ๊ฒ์ถ๊ธฐ (Edge Detector)
๐ ๊ฐ์
๋๋ฐ์ด์ฑ๋ ๋ฒํผ ์
๋ ฅ(debounce)์ ๋ณํ๋ฅผ ๊ฐ์งํ์ฌ
์์น ์ฃ์ง(rising_edge)
ํ๊ฐ ์ฃ์ง(falling_edge)
๋๋ ๋ ๋ค(both_edge)๋ฅผ ๊ฒ์ถํ๋ ํ๋ก
โ
๋์ ์๋ฆฌ
edge_reg[1] โ ์ด์ ์ํ
edge_reg[0] โ ํ์ฌ ์ํ
๋ณํ ์กฐ๊ฑด
- ์์น ์ฃ์ง: ์ด์ 0 โ ํ์ฌ 1
- ํ๊ฐ ์ฃ์ง: ์ด์ 1 โ ํ์ฌ 0
- ๋ ๋ค: ๋ ์ค ํ๋๋ผ๋ ๋ฐ์ ์
assign debounce = &sh_reg;
//assign out_button = debounce;
logic [1:0] edge_reg;
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
edge_reg <= 0;
end
else begin
edge_reg[0] <= debounce;
edge_reg[1] <= edge_reg[0];
end
end
assign rising_edge = edge_reg[0] & ~edge_reg[1];
assign falling_edge = ~edge_reg[0] & edge_reg[1];
assign both_edge = rising_edge | falling_edge;
โ
์ ์ฒด ๊ตฌ์กฐ (Button Detector)
`timescale 1ns / 1ps
module button_detector(
input logic clk,
input logic reset,
input logic in_button,
output logic rising_edge,
output logic falling_edge,
output logic both_edge
);
logic clk_1khz;
logic debounce;
logic [7:0] sh_reg;
logic [$clog2(100000)-1:0] div_counter;
always_ff @(posedge clk or posedge reset) begin
if(reset)begin
div_counter <= 0;
clk_1khz <= 0;
end
else begin
if(div_counter == 100000 - 1)begin
clk_1khz <= 1;
div_counter <= 0;
end
else begin
div_counter <= div_counter + 1;
clk_1khz <= 0;
end
end
end
shift_register u_shift_register(
.clk (clk_1khz),
.reset (reset),
.in_data (in_button),
.out_data (sh_reg)
);
assign debounce = &sh_reg;
//assign out_button = debounce;
logic [1:0] edge_reg;
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
edge_reg <= 0;
end
else begin
edge_reg[0] <= debounce;
edge_reg[1] <= edge_reg[0];
end
end
assign rising_edge = edge_reg[0] & ~edge_reg[1];
assign falling_edge = ~edge_reg[0] & edge_reg[1];
assign both_edge = rising_edge | falling_edge;
endmodule
module shift_register (
input logic clk,
input logic reset,
input logic in_data,
output logic [7:0] out_data
);
always_ff @(posedge clk or posedge reset) begin
if(reset) begin
out_data <= 0;
end
else begin
out_data <= {in_data, out_data[7:1]}; // right shift
//out_data <= {out_data[6:0], in_data}; // left shift
end
end
endmodule
โ
๊ฒ์ฆ (Test Bench)
ํด๋์ค ์ ์ (transaction)
rand bit button : ๋๋ค ์์ฑ 1๋นํธ ๋ฒํผ ๊ฐ
function bit run_random() : ํ์ฌ button ๊ฐ์ ๋ฐํ
class transaction;
rand bit button;
function bit run_random();
return button;
endfunction
endclass
์ด๊ธฐํ
clk = 0, reset = 1
10ns ํ reset = 0
in_button = 0์ผ๋ก ์ด๊ธฐํ, 20ns ๋๊ธฐ
๋ฒํผ ๋๋ฆ (Push)
in_button = 1๋ก ๋ณ๊ฒฝ
60ํ ๋ฐ๋ณต:
tr.randomize()๋ก ๋ฒํผ ๊ฐ ๋๋ค ์์ฑ
in_button์ ๋๋ค ๊ฐ ์ ์ฉ
1ns ๋๊ธฐ
in_button = 1๋ก ๊ณ ์ , 150ns ๋๊ธฐ
// push button
in_button = 1;
for(int i= 0; i < 60; i++)begin
tr.randomize();
in_button = tr.run_random();
#1;
end
in_button = 1;
#150;
๋ฒํผ ๋์ (Release)
in_button = 0์ผ๋ก ๋ณ๊ฒฝ
30ํ ๋ฐ๋ณต:
๋๋ค ๋ฒํผ ๊ฐ ์์ฑ ๋ฐ ์ ์ฉ
1ns ๋๊ธฐ
in_button = 0๋ก ๊ณ ์ , 100ns ๋๊ธฐ
in_button = 0;
for(int i= 0; i < 30; i++)begin
tr.randomize();
in_button = tr.run_random();
#1;
end
in_button = 0;
#100;
$finish;
โ
์ฃผ์ ํน์ง
๋ฒํผ ์
๋ ฅ ๋ฐ์ด์ค(Bounce) ํจ๊ณผ๋ฅผ ๋๋ค ํจํด์ผ๋ก ๊ตฌํ
์์น/ํ๊ฐ/์์ชฝ ์์ง ๊ฒ์ถ ๊ธฐ๋ฅ ๊ฒ์ฆ
ํด๋์ค ๊ธฐ๋ฐ ๋๋ค ์
๋ ฅ ์์ฑ์ผ๋ก ํ
์คํธ ํ์ฅ์ฑ ํ๋ณด
-
-
-
-
Day6: Convolutional Neural Network
์ด๋ฏธ์ง ๋ถ๋ฅ
์ด๋ฏธ์ง ๋ถ๋ฅ๋ ์ปดํจํฐ๊ฐ ์ฌ๋์ฒ๋ผ ์๊ฐ์ ์ผ๋ก ์ฌ๋ฌผ์ ์ธ์ํ๊ณ ๋ถ๋ฅํ๋ Computer Vision ๋ถ์ผ์ ํต์ฌ ์์
์ ํด๋นํ๋ค.
CNN(ํฉ์ฑ๊ณฑ ์ ๊ฒฝ๋ง)์ ๊ธฐ์กด ์ ๊ฒฝ๋ง๋ณด๋ค ์ ๊ตํ ๋ถ์์ด ๊ฐ๋ฅํ๋ฉฐ, ๊น์ ์ธต์ ํตํด ์ด๋ฏธ์ง์ ํน์ง์ ๊ณ ๋ํ๋ ํํฐ๋ก ์ถ์ถํ๋ค.
๋ถ๋ฅ ์ ํ
์ด์ง ๋ถ๋ฅ(Binary): ๋ ๊ฐ์ ํด๋์ค(์: ์ ์/๋น์ ์) ์ค ํ๋๋ก ๋ถ๋ฅํ๋ค.
๋ค์ค ํด๋์ค(Multiclass): ์ธ ๊ฐ ์ด์์ ํด๋์ค ์ค ํ๋๋ก ๋ถ๋ฅํ๋ค(์: ๊ณ ์์ด/๊ฐ/ํ ๋ผ).
๋ค์ค ๋ผ๋ฒจ(Multilabel): ํ ์ด๋ฏธ์ง๊ฐ ์ฌ๋ฌ ๋ผ๋ฒจ์ ๋์์ ๊ฐ์ง ์ ์๋ค.
๊ณ์ธต์ ๋ถ๋ฅ(Hierarchical): ํด๋์ค๊ฐ ๊ณ์ธต ๊ตฌ์กฐ๋ก ์กฐ์ง๋์ด ์์-ํ์ ๊ฐ๋
์ ๊ตฌ๋ถํ๋ค.
ํต์ฌ ๋จ๊ณ
๋ฐ์ดํฐ ์์ง: ์ถฉ๋ถํ ์์ ์ด๋ฏธ์ง์ ๋ผ๋ฒจ์ ํ๋ณดํ๋ค.
ํน์ง ์ถ์ถ: ์ด๋ฏธ์ง์์ ์๋ฏธ ์๋ ํน์ง(์ฃ์ง, ์์, ์ง๊ฐ ๋ฑ)์ ์ถ์ถํ๋ค.
๋ถ๋ฅ: ์ถ์ถ๋ ํน์ง์ ๋ฐํ์ผ๋ก ์ด๋ฏธ์ง๋ฅผ ์ฌ๋ฐ๋ฅธ ํด๋์ค์ ํ ๋นํ๋ค.
์ ์ดํ์ต(Transfer Learning):
์ฌ์ ํ์ต๋ ๋ชจ๋ธ์ ๊ฐ์ค์น๋ฅผ ์ฌ์ฌ์ฉํด ์ ์ ๋ฐ์ดํฐ๋ก๋ ๋์ ์ฑ๋ฅ์ ๋ผ ์ ์๋ค.
CNN ๊ตฌ์ฑ์์
๊ตฌ์ฑ์์
์ญํ ๋ฐ ์ค๋ช
์
๋ ฅ์ธต(Input Layer)
์๋ณธ ์ด๋ฏธ์ง์ ํฝ์
๋ฐ์ดํฐ๋ฅผ ์
๋ ฅ๋ฐ๋๋ค. ์ด๋ฏธ์ง์ ํฌ๊ธฐ(์: 224x224x3)๊ฐ ์
๋ ฅ ํฌ๊ธฐ๋ฅผ ๊ฒฐ์ ํ๋ค.
ํฉ์ฑ๊ณฑ์ธต(Convolutional Layer)
์ฌ๋ฌ ๊ฐ์ ํํฐ(์ปค๋)๋ฅผ ์ด๋ฏธ์ง์ ์ฌ๋ผ์ด๋ฉํ๋ฉฐ ์ง์ญ์ ํน์ง(์ฃ์ง, ํจํด ๋ฑ)์ ์ถ์ถํ๋ค. ๊ฐ ํํฐ๋ ํน์ฑ ๋งต์ ๋ง๋ ๋ค.
ํ์ฑํ ํจ์(Activation Function)
์ฃผ๋ก ReLU๋ฅผ ์ฌ์ฉํ๋ค. ์์ ๊ฐ์ 0์ผ๋ก ๋ฐ๊ฟ์ฃผ๊ณ , ๋น์ ํ์ฑ์ ๋ถ์ฌํด ๋ณต์กํ ํจํด ํ์ต์ด ๊ฐ๋ฅํ๊ฒ ํ๋ค.
ํ๋ง์ธต(Pooling Layer)
ํน์ฑ ๋งต์ ๊ณต๊ฐ์ ํฌ๊ธฐ๋ฅผ ์ค์ฌ ๊ณ์ฐ๋์ ๊ฐ์์ํค๊ณ ๊ณผ์ ํฉ์ ๋ฐฉ์งํ๋ค. Max pooling(์ต๋๊ฐ ์ถ์ถ)์ด ๋ํ์ ์ด๋ค.
์์ ์ฐ๊ฒฐ์ธต(Fully Connected Layer)
์ถ์ถ๋ ํน์ง์ 1์ฐจ์ ๋ฒกํฐ๋ก ๋ณํ(flatten)ํ ํ, ๋ชจ๋ ๋ด๋ฐ์ด ์๋ก ์ฐ๊ฒฐ๋์ด ์ต์ข
๋ถ๋ฅ๋ฅผ ์งํํ๋ค.
์ถ๋ ฅ์ธต(Output Layer)
ํด๋์ค๋ณ ํ๋ฅ ๊ฐ์ ์ถ๋ ฅํ๋ค. ๋ค์ค ํด๋์ค ๋ถ๋ฅ์์๋ Softmax ํจ์๋ก ํ๋ฅ ๊ฐ์ ์ ๊ทํํ๋ค.
๋๋กญ์์(Dropout, ์ ํ์ )
์ผ๋ถ ๋ด๋ฐ์ ๋ฌด์์๋ก ๋นํ์ฑํํด ๊ณผ์ ํฉ์ ๋ฐฉ์งํ๋ ์ ๊ทํ ๊ธฐ๋ฒ์ด๋ค.
ํฉ์ฑ๊ณฑ(Convolution) ์ฐ์ฐ
์
๋ ฅ ์ด๋ฏธ์ง์ ์์ ํํฐ(์: 3x3)๋ฅผ ์ฌ๋ผ์ด๋ฉํ๋ฉฐ ๊ณฑ์
ยทํฉ์ฐ์ ๋ฐ๋ณตํด ํน์ง ๋งต์ ์์ฑํ๋ค.
ํํฐ์ ๊ฐ์๋งํผ ์ฌ๋ฌ ํน์ง ๋งต์ด ๋ง๋ค์ด์ง๋ฉฐ, ๊ฐ ํํฐ๋ ์ฃ์ง, ์ง๊ฐ ๋ฑ ํน์ ํจํด์ ๋ฐ์ํ๋ค.
ํํฐ์ ์ด๋ ๊ฐ๊ฒฉ์ stride, ๊ฒฝ๊ณ ์ฒ๋ฆฌ๋ฅผ ์ํ ํจ๋ฉ(padding) ๋ฑ๋ ์ฃผ์ ํ๋ผ๋ฏธํฐ์ ํด๋นํ๋ค.
ํ๋ง(Pooling) ์ฐ์ฐ
MaxPooling(์ต๋๊ฐ), AveragePooling(ํ๊ท ๊ฐ) ๋ฑ์ด ์์ผ๋ฉฐ, ๊ณต๊ฐ ์ ๋ณด๋ฅผ ์์ฝํด ์ฐ์ฐ๋์ ์ค์ด๊ณ , ์์น ๋ณํ์ ๊ฐ์ธํ ํน์ง์ ํ์ตํ๋ค.
GlobalAveragePooling์ ์ ์ฒด ๋งต์ ํ๊ท ๊ฐ๋ง ๋จ๊ฒจ FC์ธต ์ ์ ์ฐจ์์ ํฌ๊ฒ ์ค์ผ ์ ์๋ค.
Flatten & FC Layer
ํฉ์ฑ๊ณฑยทํ๋ง์ ๋ฐ๋ณตํ ํ, ๊ฒฐ๊ณผ๋ฅผ 1์ฐจ์ ๋ฒกํฐ๋ก ๋ณํ(flatten)ํ์ฌ ์์ ์ฐ๊ฒฐ์ธต์ ์
๋ ฅํ๋ค.
FC์ธต์ ์ ํต์ ์ธ ์ ๊ฒฝ๋ง์ฒ๋ผ ๋ชจ๋ ๋ด๋ฐ์ด ์๋ก ์ฐ๊ฒฐ๋์ด ์ต์ข
๋ถ๋ฅ๋ฅผ ๋ด๋นํ๋ค.
์ด๋ฏธ์ง ํ์ต๊ณผ์
๋ฐ์ดํฐ ์ค๋น ๋ฐ ์ ์ฒ๋ฆฌ
์ด๋ฏธ์ง ์์ง ๋ฐ ๋ผ๋ฒจ๋ง:
์ถฉ๋ถํ ์์ ์ด๋ฏธ์ง๋ฅผ ์์งํ๊ณ , ๊ฐ ์ด๋ฏธ์ง์ ๋ผ๋ฒจ(์ ๋ต)์ ๋ถ์ฌํ๋ค.
๋ฐ์ดํฐ ์ฆ๊ฐ(Data Augmentation):
ํ์ , ๋ค์ง๊ธฐ, ๋ฐ๊ธฐ ์กฐ์ , ํ๋/์ถ์ ๋ฑ์ผ๋ก ๋ฐ์ดํฐ ๋ค์์ฑ์ ํ๋ณดํ๊ณ ๊ณผ์ ํฉ์ ๋ฐฉ์งํ๋ค.
์ ๊ทํ ๋ฐ ๋ฆฌ์ฌ์ด์ฆ:
ํฝ์
๊ฐ์ 0~1 ๋ฒ์๋ก ์ ๊ทํํ๊ณ , ๋ชจ๋ธ ์
๋ ฅ ํฌ๊ธฐ์ ๋ง๊ฒ ๋ฆฌ์ฌ์ด์ฆํ๋ค.
ImageDataGenerator
Keras ๋ฑ์์ ์ ๊ณตํ๋ ImageDataGenerator๋ฅผ ํ์ฉํ๋ฉด, ์ค์๊ฐ์ผ๋ก ๋ฐ์ดํฐ ์ฆ๊ฐ ๋ฐ ์ ์ฒ๋ฆฌ๋ฅผ ์๋ํํ ์ ์๋ค.
flow_from_directory: ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ๋ณ๋ก ์ด๋ฏธ์ง๋ฅผ ๋ถ๋ฌ์ค๊ณ ์๋ ๋ผ๋ฒจ๋งํ๋ค.
flow_from_dataframe: DataFrame์์ ๊ฒฝ๋ก์ ๋ผ๋ฒจ์ ์ฝ์ด ๋ฐฐ์น ๋จ์๋ก ๋ถ๋ฌ์จ๋ค.
ํน์ง ์ถ์ถ ๋ฐ ๋ชจ๋ธ ํ์ต
ํฉ์ฑ๊ณฑ/ํ๋ง/ํ์ฑํ:
CNN์ ์ฌ๋ฌ ์ธต์ ๊ฑฐ์น๋ฉฐ ์ด๋ฏธ์ง๋ก๋ถํฐ ์ ์ ๋ ์ถ์์ ์ธ ํน์ง์ ์๋์ผ๋ก ์ถ์ถํ๋ค.
์์ ์ฐ๊ฒฐ์ธต:
์ถ์ถ๋ ํน์ง์ ๋ฐํ์ผ๋ก ์ต์ข
์ ์ผ๋ก ํด๋์ค๋ณ ํ๋ฅ ์ ์ฐ์ถํ๋ค.
ํ๊ฐ ๋ฐ ๊ฒ์ฆ
๊ฒ์ฆ ๋ฐ์ดํฐ์
ํ์ฉ:
ํ์ต์ ์ฌ์ฉํ์ง ์์ ๋ณ๋์ ๋ฐ์ดํฐ๋ก ๋ชจ๋ธ ์ฑ๋ฅ์ ํ๊ฐํ๋ค.
์ฑ๋ฅ ๊ฐ์ :
ํ์์ ํ์ดํผํ๋ผ๋ฏธํฐ๋ฅผ ์กฐ์ ํ๊ฑฐ๋ ๋ฐ์ดํฐ ์ฆ๊ฐ, ๋ ์ด์ด ์ถ๊ฐ ๋ฑ์ผ๋ก ์ฑ๋ฅ์ ๊ฐ์ ํ๋ค.
ํ
์คํธ ๋ฐ ๋ฐฐํฌ
์ค์ ํ๊ฒฝ์์ ๋ฏธ์ง์ ์ด๋ฏธ์ง๋ฅผ ๋ถ๋ฅํ์ฌ ๋ชจ๋ธ์ ์ค์ ์ฑ๋ฅ์ ๊ฒ์ฆํ๋ค.
CNN ์ํคํ
์ฒ
์ํคํ
์ฒ
์ฃผ์ ํน์ง ๋ฐ ๊ตฌ์กฐ
LeNet-5
1998๋
์ ์ ์๋์์ผ๋ฉฐ, 2๊ฐ์ ํฉ์ฑ๊ณฑ+ํ๋ง์ธต๊ณผ 3๊ฐ์ ์์ ์ฐ๊ฒฐ์ธต์ผ๋ก ๊ตฌ์ฑ๋๋ค. ์ํ ์ด๋ฏธ์ง(28x28, MNIST ๋ฑ) ๋ถ๋ฅ์ ์ ํฉํ๋ค.
AlexNet
2012๋
ILSVRC์์ ์ฐ์นํ์์ผ๋ฉฐ, 5๊ฐ์ ํฉ์ฑ๊ณฑ์ธต+3๊ฐ์ ์์ ์ฐ๊ฒฐ์ธต, ReLU ํ์ฑํ ํจ์ ๋์
, ๋๊ท๋ชจ ์ด๋ฏธ์ง(224x224) ๋ถ๋ฅ์ ์ฌ์ฉ๋๋ค.
VGG-16
13๊ฐ์ ํฉ์ฑ๊ณฑ์ธต+3๊ฐ์ ์์ ์ฐ๊ฒฐ์ธต, ๋ชจ๋ ํฉ์ฑ๊ณฑ ์ปค๋ ํฌ๊ธฐ๋ฅผ 3x3์ผ๋ก ํต์ผํ์ฌ ๊น์ ๊ตฌ์กฐ(16์ธต)๋ก ์ผ๊ด๋ ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง๋ค.
ResNet
2015๋
ILSVRC์์ ์ฐ์นํ์์ผ๋ฉฐ, 50~152๊ฐ ์ธต์ ์ด์ฌ์ธต ๊ตฌ์กฐ์ ์์ฐจ ์ฐ๊ฒฐ(residual connection)๋ก ํ์ต ํจ์จ์ ๊ทน๋ํํ๋ค.
Inception
๋ค์ํ ํฌ๊ธฐ์ ํํฐ๋ฅผ ๋ณ๋ ฌ๋ก ์ ์ฉ(Inception ๋ชจ๋), 1x1 ํฉ์ฑ๊ณฑ์ผ๋ก ์ฐ์ฐ๋์ ๊ฐ์์ํค๊ณ GlobalAveragePooling์ ์ฌ์ฉํ๋ค.
MobileNet
๋ชจ๋ฐ์ผ/์๋ฒ ๋๋ ํ๊ฒฝ์ ์ต์ ํ๋ ๊ฒฝ๋ํ ๊ตฌ์กฐ๋ก ์ค์๊ฐ ๋ถ๋ฅ๊ฐ ๊ฐ๋ฅํ๋ค.
์ ์ดํ์ต(Transfer Learning) ํ์ฉ
์ต์ ์ค๋ฌด์์๋ ์ฌ์ ํ์ต๋ CNN ๋ชจ๋ธ์ ๊ฐ์ ธ์ ์ถ๋ ฅ์ธต๋ง ๊ต์ฒดํ๊ฑฐ๋ ์ผ๋ถ ์ธต๋ง ๋ฏธ์ธ์กฐ์ (Fine-tuning)ํ์ฌ ์ ์ ๋ฐ์ดํฐ๋ก๋ ์ข์ ์ฑ๋ฅ์ ์ป๋๋ค.
๊ณตํต ๊ตฌ์กฐ
์
๋ ฅ โ [ํฉ์ฑ๊ณฑ โ ํ์ฑํ โ ํ๋ง] ร N โ (ํ์์ ๋๋กญ์์) โ ์์ ์ฐ๊ฒฐ์ธต โ ์ถ๋ ฅ(Softmax) ์์ผ๋ก ์งํํ๋ค.
ํน์ง
ํน์ง ์ถ์ถ๋ถ(Feature Extractor):
์ฌ๋ฌ ํฉ์ฑ๊ณฑ/ํ๋ง์ธต์ด ๋ฐ๋ณต๋์ด ์ด๋ฏธ์ง์ ์ ์์ค(์ฃ์ง)๋ถํฐ ๊ณ ์์ค(๊ฐ์ฒด)๊น์ง ํน์ง์ ์ถ์ถํ๋ค.
๋ถ๋ฅ๋ถ(Classifier):
์์ ์ฐ๊ฒฐ์ธต์์ ์ถ์ถ๋ ํน์ง์ ๋ฐํ์ผ๋ก ํด๋์ค๋ณ ํ๋ฅ ์ ์ฐ์ถํ๋ค.
์ ๋ฆฌ
์ด๋ฏธ์ง ๋ถ๋ฅ๋ ์ด๋ฏธ์ง๋ฅผ ํด๋์ค๋ณ๋ก ์๋ ๋ถ๋ฅํ๋ ์์
์ด๋ฉฐ, CNN์ ์ด๋ฅผ ์ํ ๋ํ์ ๋ฅ๋ฌ๋ ๋ชจ๋ธ์ด๋ค.
CNN์ ์
๋ ฅ์ธต, ํฉ์ฑ๊ณฑ์ธต, ํ์ฑํํจ์, ํ๋ง์ธต, ์์ ์ฐ๊ฒฐ์ธต, ์ถ๋ ฅ์ธต ๋ฑ์ผ๋ก ๊ตฌ์ฑ๋๋ฉฐ, ๊ฐ ์ธต์ด ๊ณ์ธต์ ์ผ๋ก ์์ฌ ํน์ง์ ์ถ์ถํ๊ณ ๋ถ๋ฅ๋ฅผ ์ํํ๋ค.
ํ์ต๊ณผ์ ์ ๋ฐ์ดํฐ ์ค๋น, ์ ์ฒ๋ฆฌ, ๋ชจ๋ธ ํ์ต, ํ๊ฐ, ํ
์คํธ ์์ผ๋ก ์งํํ๋ค.
๋ํ์ ์ธ CNN ์ํคํ
์ฒ๋ก๋ LeNet, AlexNet, VGG, ResNet, Inception, MobileNet ๋ฑ์ด ์์ผ๋ฉฐ, ๊ฐ๊ฐ์ ๊ตฌ์กฐ์ ํน์ง์ด ๋ค๋ฅด๋ค.
์ค์ต
ํ์ต ๋ชฉํ
CNN์ ๊ธฐ๋ณธ ๊ฐ๋
๊ณผ ์ด๋ฏธ์ง ๋ถ๋ฅ์์์ ์ญํ ์ ์ดํดํ๋ค.
CNN์ ์ฃผ์ ๊ตฌ์ฑ์์(์
๋ ฅ์ธต, ํฉ์ฑ๊ณฑ์ธต, ํ์ฑํ ํจ์, ํ๋ง์ธต, ์์ ์ฐ๊ฒฐ์ธต ๋ฑ)๋ฅผ ์ค๋ช
ํ ์ ์๋ค.
์ด๋ฏธ์ง ํ์ต๊ณผ์ (๋ฐ์ดํฐ ์ค๋น, ์ ์ฒ๋ฆฌ, ๋ชจ๋ธ ํ์ต, ํ๊ฐ, ํ
์คํธ)์ ์ดํดํ๋ค.
ํ์ต๊ณก์ ์ ํด์ํ๊ณ ์ค๋ฒํผํ
๋ฌธ์ ๋ฅผ ์ธ์ํ๋ฉฐ, ๊ฐ์ ๋ฐฉ๋ฒ์ ์ต๋ํ๋ค.
๋ฅ๋ฌ๋ ๋ชจ๋ธ์ ํ์ดํผํ๋ผ๋ฏธํฐ ํ๋๊ณผ ์ ์ดํ์ต ํ์ฉ๋ฒ์ ์ดํดํ๋ค.
CNN Layer ๊ตฌํ
CNN ๋ชจ๋ธ ๋์์ธ
from tensorflow.keras import models, layers
model = models.Sequential()
# (32, 32, 3) => (30, 30, 32)
model.add(layers.Conv2D(filters=32, kernel_size=(3, 3), activation='relu', input_shape=(32, 32, 3)))
# (30, 30, 32) => (15, 15, 32)
model.add(layers.MaxPool2D(pool_size=(2, 2)))
# (15, 15, 32) => (13, 13, 64)
model.add(layers.Conv2D(filters=64, kernel_size=(3, 3), activation='relu'))
# (13, 13, 64) => (6, 6, 64)
model.add(layers.MaxPool2D(pool_size=(2, 2)))
# (6, 6, 64) => (4, 4, 64)
model.add(layers.Conv2D(filters=64, kernel_size=(3, 3), activation='relu'))
# 3D๋ฅผ 1D๋ก ๋ณํ
model.add(layers.Flatten())
# Classification : Fully Connected Layer ์ถ๊ฐ
model.add(layers.Dense(units=64, activation='relu'))
model.add(layers.Dense(units=10, activation='softmax'))
# ๋ชจ๋ธ์ ํ์ต ์ ๋ณด ์ค์
model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])
# ๋ชจ๋ธ ํ์ต
history = model.fit(x=train_x, y=train_y, epochs=20, batch_size=256, verbose=2, validation_split=0.2)
Accuracy
Loss
ํ์ต๊ณก์ ํด์ ๋ฐ ์ค๋ฒํผํ
๊ฐ์ ๋ฐฉ์
1. ๊ทธ๋ํ ํด์
Training Accuracy/Loss
ํ์ต ์ ํ๋๋ ๊พธ์คํ ์์นํ์ฌ 0.9(90%)์ ๊ทผ์ ํ๋ค.
ํ์ต ์์ค(loss)์ ๊พธ์คํ ๊ฐ์ํด 0.4 ์ดํ๋ก ๋จ์ด์ง๋ค.
Validation Accuracy/Loss
๊ฒ์ฆ ์ ํ๋๋ 0.8(80%) ๋ถ๊ทผ์์ ๋ ์ด์ ์ค๋ฅด์ง ์๊ณ , ์ํฌํฌ๊ฐ ์งํ๋ ์๋ก ์์น์ด ๋ฉ์ถ๊ฑฐ๋ ์ฝ๊ฐ ํ๋ฝ/๋ณ๋ํ๋ค.
๊ฒ์ฆ ์์ค์ 0.7~0.8 ์ ์์ ๋ณ๋ํ๋ฉฐ, ์คํ๋ ค ์ํฌํฌ๊ฐ ๋์๋ก ์ฌ๋ผ๊ฐ๊ธฐ๋ ํ๋ค.
2. ์์ธ ๋ถ์
์ค๋ฒํผํ
(overfitting) ํ์.
์ค๋ฒํผํ
์ด๋?
๋ชจ๋ธ์ด ํ์ต ๋ฐ์ดํฐ์๋ ๋งค์ฐ ์ ๋ง์ง๋ง, ์๋ก์ด ๋ฐ์ดํฐ(๊ฒ์ฆ/ํ
์คํธ)์๋ ์ผ๋ฐํ๊ฐ ์ ์ ๋๋ ์ํ.
๊ตฌ์ฒด์ ์ ํธ
ํ์ต ์์ค์ ๊ณ์ ๊ฐ์(=ํ์ต ๋ฐ์ดํฐ์ ์ ์ ๋ ์ ๋ง์ถค)
๊ฒ์ฆ ์์ค์ ์ด๋ ์๊ฐ๋ถํฐ ๋ ์ด์ ๊ฐ์ํ์ง ์๊ณ , ์คํ๋ ค ์ฆ๊ฐํ๊ฑฐ๋ ๋ถ์์ ํ๊ฒ ๋ณ๋
ํ์ต ์ ํ๋์ ๊ฒ์ฆ ์ ํ๋์ ์ฐจ์ด๊ฐ ์ ์ ์ปค์ง
3. ์ ์ด๋ฐ ํ์์ด ์๊ธฐ๋?
๋ชจ๋ธ์ด ๋๋ฌด ๋ณต์กํ๊ฑฐ๋ ํ๋ผ๋ฏธํฐ๊ฐ ๋ง์ ๋
ํ์ต ๋ฐ์ดํฐ์ ๋นํด ๊ฒ์ฆ ๋ฐ์ดํฐ์ ๋ถํฌ๊ฐ ๋ค๋ฅผ ๋
๋ฐ์ดํฐ๊ฐ ์ถฉ๋ถํ ๋ค์ํ์ง ์๊ฑฐ๋, ๋ฐ์ดํฐ ์ฆ๊ฐ์ด ๋ถ์กฑํ ๋
๋๋กญ์์, ์ ๊ทํ ๋ฑ ์ผ๋ฐํ ๊ธฐ๋ฒ์ด ๋ถ์กฑํ ๋
์ํฌํฌ ์๊ฐ ๋๋ฌด ๋ง์ ๋ถํ์ํ๊ฒ ์ค๋ ํ์ตํ ๋
4. ์ด๋ฐ ๊ฒฝ์ฐ ์ด๋ป๊ฒ ํด์ผ ํ๋?
Early Stopping(์กฐ๊ธฐ ์ข
๋ฃ) ์ฌ์ฉ:
๊ฒ์ฆ ์์ค์ด ๋ ์ด์ ๊ฐ์ํ์ง ์์ผ๋ฉด ํ์ต์ ๋ฉ์ถ๋ค.
๋๋กญ์์(Dropout)ยท์ ๊ทํ(BatchNorm) ์ถ๊ฐ:
๋ชจ๋ธ์ด ์ผ๋ถ ๋ด๋ฐ์ ์์กดํ์ง ์๋๋ก ํ๊ณ , ํ์ต์ ์์ ํํ๋ค.
๋ฐ์ดํฐ ์ฆ๊ฐ(Data Augmentation):
ํ์ต ๋ฐ์ดํฐ๋ฅผ ํ์ , ์ด๋, ๋
ธ์ด์ฆ ์ถ๊ฐ ๋ฑ์ผ๋ก ๋ค์ํ๊ฒ ๋ง๋ ๋ค.
๋ชจ๋ธ ๋จ์ํ:
์ธต ์๋ ํ๋ผ๋ฏธํฐ ์๋ฅผ ์ค์ฌ ๋ณต์ก๋๋ฅผ ๋ฎ์ถ๋ค.
ํ์ต๋ฅ (learning rate) ์กฐ์ :
๋๋ฌด ๋์ผ๋ฉด ๋ถ์์ , ๋๋ฌด ๋ฎ์ผ๋ฉด ๊ณผ์ ํฉ์ผ๋ก ์ด์ด์ง ์ ์๋ค.
๋ ๋ง์ ๋ฐ์ดํฐ ํ๋ณด:
๊ฐ๋ฅํ๋ค๋ฉด ๋ฐ์ดํฐ์
์ ํค์ด๋ค.
5. ์ฐธ๊ณ : ์ ์์ ์ธ ํ์ต๊ณก์ ์?
ํ์ตยท๊ฒ์ฆ ์์ค์ด ๋ชจ๋ ์ ์ง์ ์ผ๋ก ๊ฐ์
ํ์ตยท๊ฒ์ฆ ์ ํ๋๊ฐ ๋ชจ๋ ์ ์ง์ ์ผ๋ก ์ฆ๊ฐ
๋ ๊ณก์ ๊ฐ์ ์ฐจ์ด๊ฐ ํฌ์ง ์์
(์ฐจ์ด๊ฐ ํฌ๋ฉด ์ค๋ฒํผํ
, ๋ ๋ค ๋ฎ์ผ๋ฉด ์ธ๋ํผํ
)
๊ฒฐ๋ก
ํ์ฌ ํ์ต๊ณก์ ์ ๋ชจ๋ธ์ด ํ์ต ๋ฐ์ดํฐ์๋ ๊ณผํ๊ฒ ๋ง์ถ๊ณ , ์๋ก์ด ๋ฐ์ดํฐ์๋ ์ผ๋ฐํํ์ง ๋ชปํ๋ ์ ํ์ ์ธ ์ค๋ฒํผํ
์ํ๋ค.
CNN ๋ชจ๋ธ ๊ฐ์
๋๋กญ์์(Dropout)ยท์ ๊ทํ(BatchNorm) ์ถ๊ฐ:
ํ์ต๋ฅ (learning rate) ์กฐ์ :
from tensorflow.keras import models, layers
model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
model.add(BatchNormalization())
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(BatchNormalization())
model.add(layers.MaxPool2D((2, 2)))
model.add(Dropout(0.5))
model.add(layers.Conv2D(128, (3, 3), activation='relu'))
model.add(BatchNormalization())
model.add(layers.MaxPool2D((2, 2)))
model.add(Dropout(0.5))
model.add(layers.Flatten())
model.add(layers.Dense(256, activation='relu'))
model.add(Dropout(0.5))
model.add(layers.Dense(10, activation='softmax'))
model.compile(optimizer=Adam(learning_rate=0.0002), loss='categorical_crossentropy', metrics=['accuracy'])
history = model.fit(x=train_x, y=train_y, epochs=50, batch_size=128, validation_split=0.2, verbose=2)
Accuracy
Loss
๊ฒฐ๋ก
์ด๋ฒ ํ์ต์ ํตํด ํฉ์ฑ๊ณฑ ์ ๊ฒฝ๋ง(CNN)์ ๊ตฌ์กฐ์ ์๋ฆฌ๋ฅผ ์ดํดํ๊ณ , ์ค์ ์ด๋ฏธ์ง ๋ถ๋ฅ ๋ฌธ์ ์ ์ ์ฉํด๋ด์ผ๋ก์จ ๋ฅ๋ฌ๋ ๊ธฐ๋ฐ ์ปดํจํฐ ๋น์ ์ ํต์ฌ ๊ฐ๋
์ ์ตํ๋ค.
CNN์ ๋ค์ํ ๊ตฌ์ฑ์์์ ๋ํ ์ํคํ
์ฒ์ ํน์ง, ๋ฐ์ดํฐ ์ ์ฒ๋ฆฌ์ ์ ๊ทํ, ์ค๋ฒํผํ
๋ฐฉ์ง ๊ธฐ๋ฒ ๋ฑ ์ค์ ์ ์ธ ๋ด์ฉ์ ํ์ตํจ์ผ๋ก์จ,
์ด๋ฏธ์ง ๋ถ๋ฅ ๋ชจ๋ธ์ ์ฑ๋ฅ์ ํจ๊ณผ์ ์ผ๋ก ํฅ์์ํค๋ ๋ฐฉ๋ฒ์ ์ต๋ํ ์ ์์๋ค.
ํฅํ์๋ ์ ์ดํ์ต, ๋ฐ์ดํฐ ์ฆ๊ฐ, ํ์ดํผํ๋ผ๋ฏธํฐ ํ๋ ๋ฑ ๊ณ ๊ธ ๊ธฐ๋ฒ์ ์ ๊ทน์ ์ผ๋ก ํ์ฉํ์ฌ,
๋ ๋์ ์ฑ๋ฅ๊ณผ ์ค์ ์ ์ฉ ๋ฅ๋ ฅ์ ๊ฐ์ถ ๋ฅ๋ฌ๋ ๋ชจ๋ธ์ ์ค๊ณยทํ์ฉํ ์ ์์ ๊ฒ์ด๋ค.
-
Day5: Neural Network Model
Activate function
Learning Analysis
Optimization Techniques
LAB
Mnist ์ค์ต
1. ์ฐจ์ด์
ํญ๋ชฉ
์ ๊ฒฝ๋ง ๊ตฌ์กฐ
์ ๊ฒฝ๋งโ๊ตฌ์กฐ
๋ชจ๋ธ ๊ตฌ์กฐ
4๊ฐ Dense ๊ณ์ธต(512โ256โ128โ10), Dropout 3ํ
1๊ฐ Dense ๊ณ์ธต(10)
ํ์ฑํ ํจ์
relu(์๋์ธต), softmax(์ถ๋ ฅ์ธต)
softmax(์ถ๋ ฅ์ธต)
Dropout ์ฌ์ฉ
์์(0.3 ๋น์จ, 3ํ)
์์
Optimizer
Adam(learning_rate=0.0003)
SGD(๊ธฐ๋ณธ๊ฐ)
Epoch ์
35
30
Batch Size
128
64
๋ชจ๋ธ ๋ณต์ก๋
๋์
๋งค์ฐ ๋จ์(๋ก์ง์คํฑ ํ๊ท์ ์ ์ฌ)
2. ๋ชจ๋ธ ๊ตฌ์กฐ ๋ฐ ๋ณต์ก๋
์ ๊ฒฝ๋งโ๊ตฌ์กฐ: ์๋์ธต ์์ด ์
๋ ฅ(784์ฐจ์)์์ ๋ฐ๋ก 10๊ฐ ์ ๋์ softmax ์ถ๋ ฅ์ธต์ผ๋ก ์ฐ๊ฒฐ๋ ๋งค์ฐ ๋จ์ํ ๊ตฌ์กฐ. ์ด๋ ๋ค์ค ํด๋์ค ๋ก์ง์คํฑ ํ๊ท์ ๋์ผ.
์ ๊ฒฝ๋ง ๊ตฌ์กฐ: 3๊ฐ์ ์๋์ธต(512, 256, 128 ์ ๋)๊ณผ Dropout(0.3) ๋ ์ด์ด๋ฅผ ํฌํจํด, ์ฌ์ธต ์ ๊ฒฝ๋ง ๊ตฌ์กฐ. ์ถ๋ ฅ์ธต์ 10๊ฐ ์ ๋์ softmax.
์ ๊ฒฝ๋งโ๊ตฌ์กฐ
md = Sequential()
md.add(Dense(10, activation = 'softmax', input_shape = (28*28,)))
์ ๊ฒฝ๋ง ๊ตฌ์กฐ
md = Sequential()
md.add(Dense(512, activation='relu', input_shape=(28*28,)))
md.add(Dropout(0.3))
md.add(Dense(256, activation='relu'))
md.add(Dropout(0.3))
md.add(Dense(128, activation='relu'))
md.add(Dropout(0.3))
md.add(Dense(10, activation='softmax'))
3. ์ ๊ทํ(Dropout) ์ ์ฉ ์ ๋ฌด
op_mnist.py๋ ๊ณผ์ ํฉ ๋ฐฉ์ง๋ฅผ ์ํด Dropout ๋ ์ด์ด๋ฅผ 3๋ฒ ์ฌ์ฉ.
mnist.py๋ Dropout ๋ ์ด์ด โ
4. Optimizer ๋ฐ ํ์ดํผํ๋ผ๋ฏธํฐ ์ค์
์ ๊ฒฝ๋งโ๊ตฌ์กฐ
md.compile(loss='sparse_categorical_crossentropy', optimizer = 'sgd', metrics=['acc'])
hist = md.fit(train_x2, train_y, epochs = 30, batch_size = 64, validation_split = 0.2)
์ ๊ฒฝ๋ง ๊ตฌ์กฐ
md.compile(loss='sparse_categorical_crossentropy', optimizer=Adam(learning_rate=0.0003), metrics=['acc'])
hist = md.fit(train_x2, train_y, epochs = 35, batch_size = 128, validation_split = 0.2)
5. ๊ฒฐ๊ณผ ๋น๊ต
์ ๊ฒฝ๋งโ ๊ตฌ์กฐ
์ ๊ฒฝ๋ง ๊ตฌ์กฐ
์ ๊ฒฝ๋งโ ๊ตฌ์กฐ
์ ๊ฒฝ๋ง ๊ตฌ์กฐ
์ ๊ฒฝ๋งโ ๊ตฌ์กฐ
์ ๊ฒฝ๋ง ๊ตฌ์กฐ
6. ๊ฒฐ๋ก
- ์ ๊ฒฝ๋งโ๊ตฌ์กฐ๋ ๋จ์ผ์ธต ์ ๊ฒฝ๋ง(๋ก์ง์คํฑ ํ๊ท) ๊ตฌ์กฐ๋ก, ๊ตฌํ์ด ๊ฐ๋จํ๊ณ ๋น ๋ฅด์ง๋ง, ๋ณต์กํ ๋ฐ์ดํฐ ํํ๋ ฅ์ ๋จ์ด์ง๋ค.
- ์ ๊ฒฝ๋ง ๊ตฌ์กฐ๋ ์ฌ์ธต ์ ๊ฒฝ๋ง(MLP) ๊ตฌ์กฐ์ Dropout๊ณผ Adam ์ตํฐ๋ง์ด์ ๋ฅผ ์ ์ฉํด, ๋ณต์กํ ํจํด ํ์ต๊ณผ ๊ณผ์ ํฉ ๋ฐฉ์ง์ ์ค์ ์ ๋ ์ฝ๋.
- ๋ ์ฝ๋์ ์ฐจ์ด๋ ๋ชจ๋ธ ๊ตฌ์กฐ(์ฌ์ธต vs. ๋จ์ธต), ์ ๊ทํ ์ ์ฉ, ์ตํฐ๋ง์ด์ ์ข
๋ฅ, ํ์ต ํ๋ผ๋ฏธํฐ ๋ฑ์์ ๋๋ ทํ๊ฒ ๋ํ๋๋ค.
Cifar-10 ์ค์ต
1. ์ฐจ์ด์
ํญ๋ชฉ
์ ๊ฒฝ๋ง ๊ตฌ์กฐ
์ ๊ฒฝ๋งโ๊ตฌ์กฐ
๋ชจ๋ธ ๊ตฌ์กฐ
4๊ฐ Dense ๊ณ์ธต(512โ256โ128โ10), Dropout 3ํ
1๊ฐ Dense ๊ณ์ธต(10)
ํ์ฑํ ํจ์
relu(์๋์ธต), softmax(์ถ๋ ฅ์ธต)
softmax(์ถ๋ ฅ์ธต)
Dropout ์ฌ์ฉ
์์(0.3 ๋น์จ, 3ํ)
์์
Optimizer
Adam(learning_rate=0.0003)
SGD(๊ธฐ๋ณธ๊ฐ)
Epoch ์
35
30
Batch Size
128
64
๋ชจ๋ธ ๋ณต์ก๋
๋์
๋งค์ฐ ๋จ์(๋ก์ง์คํฑ ํ๊ท์ ์ ์ฌ)
2. ๋ชจ๋ธ ๊ตฌ์กฐ ๋ฐ ๋ณต์ก๋
์ ๊ฒฝ๋งโ๊ตฌ์กฐ: ์๋์ธต ์์ด ์
๋ ฅ(784์ฐจ์)์์ ๋ฐ๋ก 10๊ฐ ์ ๋์ softmax ์ถ๋ ฅ์ธต์ผ๋ก ์ฐ๊ฒฐ๋ ๋งค์ฐ ๋จ์ํ ๊ตฌ์กฐ. ์ด๋ ๋ค์ค ํด๋์ค ๋ก์ง์คํฑ ํ๊ท์ ๋์ผ.
์ ๊ฒฝ๋ง ๊ตฌ์กฐ: 3๊ฐ์ ์๋์ธต(512, 256, 128 ์ ๋)๊ณผ Dropout(0.3) ๋ ์ด์ด๋ฅผ ํฌํจํด, ์ฌ์ธต ์ ๊ฒฝ๋ง ๊ตฌ์กฐ. ์ถ๋ ฅ์ธต์ 10๊ฐ ์ ๋์ softmax.
์ ๊ฒฝ๋งโ๊ตฌ์กฐ
md = Sequential()
md.add(Dense(10, activation = 'softmax', input_shape = (32*32*3,)))
์ ๊ฒฝ๋ง ๊ตฌ์กฐ
md = Sequential()
md.add(Dense(512, activation='relu', input_shape=(3072,)))
md.add(Dropout(0.3))
md.add(Dense(256, activation='relu'))
md.add(Dropout(0.3))
md.add(Dense(128, activation='relu'))
md.add(Dropout(0.3))
md.add(Dense(10, activation='softmax'))
3. ์ ๊ทํ(Dropout) ์ ์ฉ ์ ๋ฌด
์ ๊ฒฝ๋ง ๊ตฌ์กฐ(op_cifar_10.py): ๊ณผ์ ํฉ ๋ฐฉ์ง๋ฅผ ์ํด Dropout ๋ ์ด์ด๋ฅผ 3๋ฒ ์ฌ์ฉ.
์ ๊ฒฝ๋งโ๊ตฌ์กฐ(cifar_10.py): Dropout ๋ ์ด์ด๊ฐ ์๋ค.
4. Optimizer ๋ฐ ํ์ดํผํ๋ผ๋ฏธํฐ ์ค์
์ ๊ฒฝ๋งโ๊ตฌ์กฐ
md.compile(loss='sparse_categorical_crossentropy', optimizer = 'sgd', metrics=['acc'])
hist = md.fit(train_x2, train_y, epochs = 30, batch_size = 64, validation_split = 0.2)
์ ๊ฒฝ๋ง ๊ตฌ์กฐ
md.compile(loss='sparse_categorical_crossentropy', optimizer=Adam(learning_rate=0.0003), metrics=['acc'])
hist = md.fit(train_x2, train_y, epochs = 35, batch_size = 128, validation_split = 0.2)
5. ๊ฒฐ๊ณผ ๋น๊ต
์ ๊ฒฝ๋งโ ๊ตฌ์กฐ
์ ๊ฒฝ๋ง ๊ตฌ์กฐ
์ ๊ฒฝ๋งโ ๊ตฌ์กฐ
์ ๊ฒฝ๋ง ๊ตฌ์กฐ
์ ๊ฒฝ๋งโ ๊ตฌ์กฐ
์ ๊ฒฝ๋ง ๊ตฌ์กฐ
6. ๊ฒฐ๋ก
์ ๊ฒฝ๋งโ๊ตฌ์กฐ๋ ๋จ์ผ์ธต ์ ๊ฒฝ๋ง(๋ก์ง์คํฑ ํ๊ท) ๊ตฌ์กฐ๋ก, ๊ตฌํ์ด ๊ฐ๋จํ๊ณ ๋น ๋ฅด์ง๋ง, ๋ณต์กํ ๋ฐ์ดํฐ ํํ๋ ฅ์ ๋จ์ด์ง๋ค.
์ ๊ฒฝ๋ง ๊ตฌ์กฐ๋ ์ฌ์ธต ์ ๊ฒฝ๋ง(MLP) ๊ตฌ์กฐ์ Dropout๊ณผ Adam ์ตํฐ๋ง์ด์ ๋ฅผ ์ ์ฉํด, ๋ณต์กํ ํจํด ํ์ต๊ณผ ๊ณผ์ ํฉ ๋ฐฉ์ง.
๋ ์ฝ๋์ ์ฐจ์ด๋ ๋ชจ๋ธ ๊ตฌ์กฐ(์ฌ์ธต vs. ๋จ์ธต), ์ ๊ทํ ์ ์ฉ, ์ตํฐ๋ง์ด์ ์ข
๋ฅ, ํ์ต ํ๋ผ๋ฏธํฐ ๋ฑ.
-
Day5: Linear Model
(Mnist, Cifar_10) Dataset
1. ๋ฐ์ดํฐ์
๋ฐ ์ฝ๋ ๊ฐ์
โ Mnist ๋ฐ์ดํฐ์
์ด๋?
์์ผ๋ก ์ด ์ซ์(0~9)๋ฅผ ์ธ์ํ๋ ๋จธ์ ๋ฌ๋ ๋ฐ ๋ฅ๋ฌ๋ ๋ชจ๋ธ์ ์ฑ๋ฅ ํ๊ฐ๋ฅผ ์ํด ๋๋ฆฌ ์ฌ์ฉ๋๋ ๋ํ์ ์ธ ์ด๋ฏธ์ง ๋ฐ์ดํฐ์
์ด๋ค.
์ด 70,000๊ฐ์ ํ๋ฐฑ(๊ทธ๋ ์ด์ค์ผ์ผ) ์ด๋ฏธ์ง๋ก ์ด๋ฃจ์ด์ ธ ์์ผ๋ฉฐ, 60,000๊ฐ๋ ํ์ต์ฉ, 10,000๊ฐ๋ ํ
์คํธ์ฉ์ด๋ค. ๊ฐ ์ด๋ฏธ์ง๋ 28x28 ํฝ์
ํฌ๊ธฐ์ ์ ์ฌ๊ฐํ ํํ์ด๋ค.
โ Cifar_10 ๋ฐ์ดํฐ์
์ด๋?
์ปดํจํฐ ๋น์ ๋ถ์ผ์์ ์ด๋ฏธ์ง ๋ถ๋ฅ ๋ชจ๋ธ์ ์ฑ๋ฅ์ ํ๊ฐํ๊ธฐ ์ํด ๋๋ฆฌ ์ฌ์ฉ๋๋ ์ปฌ๋ฌ ์ด๋ฏธ์ง ๋ฐ์ดํฐ์
์ด๋ค.
์ด 60,000๊ฐ์ ์ปฌ๋ฌ(RGB, 3์ฑ๋) ์ด๋ฏธ์ง๋ก ์ด๋ฃจ์ด์ ธ ์์ผ๋ฉฐ, 50,000๊ฐ๋ ํ์ต์ฉ, 10,000๊ฐ๋ ํ
์คํธ์ฉ์ด๋ค. ๊ฐ ์ด๋ฏธ์ง๋ 32x32 ํฝ์
ํฌ๊ธฐ์ด๋ค.
2. ๋ฐ์ดํฐ ์ ์ฒ๋ฆฌ ๋ฐ ๋ชจ๋ธ ๊ตฌ์กฐ
Mnist ๋ฐ์ดํฐ์
๋ฐ์ดํฐ: (60000, 28, 28) ํฌ๊ธฐ์ ํ๋ฐฑ ์ด๋ฏธ์ง, ๋ผ๋ฒจ(0~9)
์ ์ฒ๋ฆฌ: ์ด๋ฏธ์ง๋ฅผ 1์ฐจ์(784)์ผ๋ก ๋ณํ ํ 0~1 ์ ๊ทํ
๋ชจ๋ธ:
์
๋ ฅ: Dense(3072)
์ถ๋ ฅ์ธต: Dense(10, softmax) (์๋์ธต ์์)
์์คํจ์: sparse_categorical_crossentropy
์ต์ ํ: SGD
ํ๊ฐ: ์ ํ๋(acc)
# Mnist ๋ฐ์ดํฐ ์ ์ฒ๋ฆฌ
train_x1 = train_x.reshape(60000, -1) # 1์ฐจ์ ๋ฐฐ์ด
test_x1 = test_x.reshape(10000, -1) # 1์ฐจ์ ๋ฐฐ์ด
train_x2 = train_x1/255
test_x2 = test_x1/255
print(train_x2.shape) # (60000, 784)
print(test_x2.shape) # (10000, 784)
md = Sequential()
md.add(Dense(10, activation = 'softmax', input_shape = (28*28,)))
md.summary()
md.compile(loss='sparse_categorical_crossentropy', optimizer = 'sgd', metrics=['acc'])
hist = md.fit(train_x2, train_y, epochs = 30, batch_size = 64, validation_split = 0.2)
Cifar_10 ๋ฐ์ดํฐ์
๋ฐ์ดํฐ: (50000, 32, 32, 3) ํฌ๊ธฐ์ ์ปฌ๋ฌ ์ด๋ฏธ์ง, ๋ผ๋ฒจ(0~9)
์ ์ฒ๋ฆฌ: ์ด๋ฏธ์ง๋ฅผ 1์ฐจ์(3072)์ผ๋ก ๋ณํ ํ 0~1 ์ ๊ทํ
๋ชจ๋ธ:
์
๋ ฅ: Dense(3072)
์ถ๋ ฅ์ธต: Dense(10, softmax) (์๋์ธต ์์)
์์คํจ์: sparse_categorical_crossentropy
์ต์ ํ: SGD
ํ๊ฐ: ์ ํ๋(acc)
# Cifar_10 ๋ฐ์ดํฐ ์ ์ฒ๋ฆฌ
train_x1 = train_x.reshape(50000, -1) # 1์ฐจ์ ๋ฐฐ์ด
test_x1 = test_x.reshape(10000, -1) # 1์ฐจ์ ๋ฐฐ์ด
train_x2 = train_x1/255
test_x2 = test_x1/255
print(train_x2.shape) #(50000, 3072)
print(test_x2.shape) #(10000, 3072)
md = Sequential()
md.add(Dense(10, activation = 'softmax', input_shape = (32*32*3,)))
md.summary()
md.compile(loss='sparse_categorical_crossentropy', optimizer = 'sgd', metrics=['acc'])
hist = md.fit(train_x2, train_y, epochs = 30, batch_size = 128, validation_split = 0.2)
3. ์ฝ๋ ์คํ ๋ฐ ๊ฒฐ๊ณผ ์๊ฐํ
Mnist ๋ฐ์ดํฐ์
Cifar_10 ๋ฐ์ดํฐ์
4. ๋ ์ฝ๋์ ์ฃผ์ ์ฐจ์ด์
ํญ๋ชฉ
MNIST ์ฝ๋
CIFAR-10 ์ฝ๋
๋ฐ์ดํฐ ํ์
ํ๋ฐฑ(1์ฑ๋), 28x28
์ปฌ๋ฌ(3์ฑ๋), 32x32
์
๋ ฅ ์ฐจ์
784
3072
๋ชจ๋ธ ๊ตฌ์กฐ
์๋์ธต โ
์๋์ธต โ
๋์ด๋
์๋์ ์ผ๋ก ์ฌ์
์๋์ ์ผ๋ก ์ด๋ ค์
๋ถ๋ฅ ๋์
์๊ธ์จ ์ซ์(0~9)
10๊ฐ์ง ์ฌ๋ฌผ
์ฑ๋ฅ ๊ธฐ๋์น
๋์ ์ ํ๋ ๋ฌ์ฑ ์ฉ์ด
๋จ์ ๋ชจ๋ธ๋ก๋ ๋ฎ์ ์ ํ๋
๋ฐ์ดํฐ ๋ณต์ก์ฑ: CIFAR-10์ ์์, ๋ฐฐ๊ฒฝ, ํํ๊ฐ ๋ค์ํด ๋จ์ ์ ๊ฒฝ๋ง์ผ๋ก๋ ๋ถ๋ฅ๊ฐ ์ด๋ ต๊ณ , MNIST๋ ๋จ์ํ ํ๋ฐฑ ์ซ์ ์ด๋ฏธ์ง๋ผ ๊ธฐ๋ณธ ์ ๊ฒฝ๋ง๋ ๋์ ์ฑ๋ฅ์ ๋ณด์.
5. CIFAR-10 ์ ํ๋ ํฅ์์ ์ํ ํ์ดํผํ๋ผ๋ฏธํฐ ์กฐ์ ๋ฐฉ๋ฒ
1. ์๋์ธต ์ถ๊ฐ ๋ฐ ํฌ๊ธฐ ์กฐ์ : Dense ๋ ์ด์ด(์๋์ธต)๋ฅผ ์ถ๊ฐํ๊ณ , ๋
ธ๋ ์๋ฅผ ๋๋ฆฌ๋ฉด ๋ ๋ณต์กํ ํจํด์ ํ์ต
์๋์ธต์ด ์๋ ๊ตฌ์กฐ์ Dense(100, activation=โsoftmaxโ)๋ก ํ๋ฉด 100๊ฐ์ ํด๋์ค์ ๋ํ ํ๋ฅ ์ ๋ด๋๊ธฐ ๋๋ฌธ์, 10๊ฐ ํด๋์ค ๋ถ๋ฅ ๋ฌธ์ ์์๋ ์ฌ๋ฐ๋ฅธ ๊ฒฐ๊ณผ โ
2. ํ์ฑํ ํจ์ ๋ณ๊ฒฝ: ์๋์ธต์ relu ๋ฑ ๋น์ ํ ํ์ฑํ ํจ์๋ฅผ ์ ์ฉํด ๋ชจ๋ธ ํํ๋ ฅ์ ๋์ผ ์ ์๋ค.
3. ๋ฐฐ์น ์ฌ์ด์ฆ(batch size) ๋ณ๊ฒฝ: ์์ ๋ฐฐ์น๋ ๋ ๋น ๋ฅธ ์
๋ฐ์ดํธ, ํฐ ๋ฐฐ์น๋ ๋ ์์ ์ ์ธ ํ์ต์ ์ ๋
4. ์ํฌํฌ ์ ์กฐ์ : ๋ ์ค๋ ํ์ต์ํค๋ฉด ์ฑ๋ฅ์ด ์ค๋ฅผ ์ ์์ผ๋, ๊ณผ์ ํฉ์ ์ฃผ์
๊ณผ์ ํฉ์ ๋ชจ๋ธ์ด ํ์ต ๋ฐ์ดํฐ์ ๋
ธ์ด์ฆ๋ ์ธ๋ถ์ ์ธ ํจํด๊น์ง ์ง๋์น๊ฒ ํ์ตํ์ฌ, ์๋ก์ด ๋ฐ์ดํฐ(ํ
์คํธ ๋ฐ์ดํฐ)์ ๋ํ ์ผ๋ฐํ ์ฑ๋ฅ์ด ๋จ์ด์ง๋ ํ์.
๊ณผ์ ํฉ๋ ๋ชจ๋ธ์ ํ์ต ๋ฐ์ดํฐ์์๋ ๋์ ์ ํ๋๋ฅผ ๋ณด์ด์ง๋ง, ํ
์คํธ ๋ฐ์ดํฐ์์๋ ์ฑ๋ฅ์ด ๊ธ๊ฒฉํ ๋จ์ด์ง๋ค.
โ๊ณผ์ ํฉ ๋ฐฉ์ง๋ฒ
์กฐ๊ธฐ ์ข
๋ฃ(Early Stopping): ๊ฒ์ฆ ๋ฐ์ดํฐ์ ์ฑ๋ฅ์ด ๋ ์ด์ ๊ฐ์ ๋์ง ์์ผ๋ฉด ํ์ต ์ค๋จ.
์ ๊ทํ(Regularization): L1, L2 ์ ๊ทํ, ๋๋กญ์์(Dropout) ๋ฑ์ ์ฌ์ฉํด ๋ชจ๋ธ ๋ณต์ก๋ ์ ์ด.
๋ฐ์ดํฐ ์ฆ๊ฐ(Data Augmentation): ํ์ต ๋ฐ์ดํฐ๋ฅผ ์ธ์์ ์ผ๋ก ๋๋ ค ๋ชจ๋ธ์ด ๋ ์ผ๋ฐํ๋๋๋ก ํ๋ค.
์ ์ ํ ์ํฌํฌ ์ ์ค์ : ๊ฒ์ฆ ์ฑ๋ฅ์ด ์ต๊ณ ์ผ ๋ ํ์ต์ ๋ฉ์ถ๋ ๊ฒ์ด ์ด์์ ์ด๋ค.
6. ๊ฒฐ๋ก
์ ํ๋๊ฐ ๋๋ฌด ๋ฎ์ ๊ฒ์ ๋ชจ๋ธ ๊ตฌ์กฐ์ ํ๊ณ ๋๋ฌธ์ด๋ค. ํ์ดํผํ๋ผ๋ฏธํฐ ์กฐ์ ๋ง์ผ๋ก๋ ๊ทผ๋ณธ์ ์ธ ํด๊ฒฐ์ด ์ด๋ ต๋ค. ์๋์ธต์ ์ถ๊ฐํ๊ฑฐ๋ CNN์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ๋ค.
-
-
Day4: Deep Learning
Compare Perceptron, Multi Layer perceptron XOR Gate
1. ๋คํธ์ํฌ ๊ตฌ์กฐ์ ์ฐจ์ด
Perceptron
- Single layer : ์
๋ ฅ์ธต๊ณผ ์ถ๋ ฅ์ธต๋ง ์กด์ฌํ๋ฉฐ, ์
๋ ฅ๊ฐ์ ๊ฐ์ค์น์ ๋ฐ์ด์ด์ค๋ฅผ ๋ํ ๋ค ๋ฐ๋ก ์ถ๋ ฅ
self.weights = np.zeros(input_size)
self.bias = 0
- ํ์ฑํ ํจ์: ๊ณ๋จํจ์์ ๊ฐ์ ๋จ์ํ ํจ์๋ฅผ ์ฌ์ฉํ๋ค.
Multi Layer Perceptron
- Multi layer : ์
๋ ฅ์ธต, ์๋์ธต, ์ถ๋ ฅ์ธต์ผ๋ก ๊ตฌ์ฑ๋๋ค.
self.w1 = np.random.randn(input_size, hidden_size)
self.b1 = np.zeros(hidden_size)
self.w2 = np.random.randn(hidden_size, output_size)
self.b2 = np.zeros(output_size)
- ํ์ฑํ ํจ์: sigmoid, tanh ๋ฑ ์ฐ์์ ์ด๊ณ ๋ฏธ๋ถ ๊ฐ๋ฅํ ํจ์ ์ฌ์ฉ. ๊ฐ ์ธต๋ง๋ค ์ ์ฉํ๋ค.
2. ์์ ํ ์ฐ์ฐ์ ์ฐจ์ด
Perceptron
- ์
๋ ฅ์ธต -> ์ถ๋ ฅ์ธต
linear_output = np.dot(x, self.weights) + self.bias
return self.activation(linear_output)
Multi Layer Perceptron
- ์
๋ ฅ์ธต -> ์๋์ธต -> ์ถ๋ ฅ์ธต
self.z1 = np.dot(x, self.w1) + self.b1
self.a1 = sigmoid(self.z1)
self.z2 = np.dot(self.a1, self.w2) + self.b2
self.a2 = sigmoid(self.z2)
return self.a2
3. ๊ฐ์ค์น ์
๋ฐ์ดํธ ๋ฐฉ์์ ์ฐจ์ด
Perceptron
- ๋จ์ ์
๋ฐ์ดํธ
update = self.lr * (target - prediction)
self.weights += update * x1
self.bias += update
Multi Layer Perceptron
- ์ญ์ ํ(Backpropagation) ์ฌ์ฉ
์ถ๋ ฅ์ธต ์ค์ฐจ๋ฅผ ์๋์ธต๊น์ง ์ ํํ์ฌ ๋ชจ๋ ๊ฐ์ค์น/๋ฐ์ด์ด์ค๋ฅผ ๋ฏธ๋ถ๊ฐ(gradient)์ผ๋ก ์
๋ฐ์ดํธํ๋ค
# ์ถ๋ ฅ์ธต ์ค์ฐจ
error_output = self.a2 - y
delta2 = error_output * sigmoid_diff(self.z2)
# ์๋์ธต ์ค์ฐจ
error_hidden = np.dot(self.w2, delta2)
delta1 = error_hidden * sigmoid_diff(self.z1)
# ๊ฐ์ค์น ์
๋ฐ์ดํธ
self.w2 -= self.lr * np.outer(self.a1, delta2)
self.b2 -= self.lr * delta2
self.w1 -= self.lr * np.outer(x, delta1)
self.b1 -= self.lr * delta1
4. ๋ฌธ์ ํด๊ฒฐ ๋ฅ๋ ฅ์ ์ฐจ์ด
Perceptron
- ํผ์
ํธ๋ก : XOR์ฒ๋ผ ์ ํ์ ์ผ๋ก ๊ตฌ๋ถ ๋ถ๊ฐ๋ฅํ ๋ฌธ์ ๋ ์ ๋ ํ ์ ์์. ๋จ์ผ ์ง์ (ํน์ ํ๋ฉด)๋ง์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ๋๋๋ค.
Multi Layer Perceptron
- MLP: ์๋์ธต์ ๋น์ ํ ๋ณํ ๋๋ถ์ XOR ๋ฑ ๋ณต์กํ ํจํด๋ ํ์ต ๊ฐ๋ฅ. ์ค์ ๋ก MLP ์ฝ๋๋ XOR ๋ฌธ์ ๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ํด๊ฒฐํ ์ ์์
5. ์ฝ๋ ์์
Perceptron
์ถ๋ ฅ์ธต ์ค์ฐจ๋ง ์ฌ์ฉ
class Perceptron:
def __init__(self, input_size, ...):
self.weights = np.zeros(input_size)
self.bias = 0
def predict(self, x):
return self.activation(np.dot(x, self.weights) + self.bias)
def train(self, X, y):
Multi Layer Perceptron
์ฌ๋ฌ ์ธต ์์ ํ
์ญ์ ํ๋ก ๋ชจ๋ ์ธต ๊ฐ์ค์น ์
๋ฐ์ดํธ
class MLP:
def __init__(self, input_size, hidden_size, output_size, ...):
self.w1 = np.random.randn(input_size, hidden_size)
self.b1 = np.zeros(hidden_size)
self.w2 = np.random.randn(hidden_size, output_size)
self.b2 = np.zeros(output_size)
def forward(self, x):
def backward(self, x, y):
6. ์์ฝ
๊ตฌ๋ถ
ํผ์
ํธ๋ก
MLP
์ธต ๊ตฌ์กฐ
์
๋ ฅ-์ถ๋ ฅ(๋จ์ผ์ธต)
์
๋ ฅ-์๋-์ถ๋ ฅ(๋ค์ธต)
๊ฐ์ค์น/๋ฐ์ด์ด์ค
1๊ฐ(์
๋ ฅโ์ถ๋ ฅ)
2์ธํธ(์
๋ ฅโ์๋, ์๋โ์ถ๋ ฅ)
์์ ํ
ํ ๋ฒ์ ์ ํ ์ฐ์ฐ+ํ์ฑํ
์ฌ๋ฌ ์ธต์ ์ ํ ์ฐ์ฐ+๋น์ ํ ํ์ฑํ ๋ฐ๋ณต
ํ์ต ๋ฐฉ์
์ถ๋ ฅ์ธต ์ค์ฐจ๋ก ๋จ์ ์
๋ฐ์ดํธ
์ญ์ ํ๋ก ๋ชจ๋ ์ธต์ ๊ฐ์ค์น/๋ฐ์ด์ด์ค ์
๋ฐ์ดํธ
ํ์ฑํ ํจ์
๊ณ๋จํจ์/์๊ทธ๋ชจ์ด๋(๋จ์)
์๊ทธ๋ชจ์ด๋/ํ์ ํธ ๋ฑ(๋น์ ํ, ๋ฏธ๋ถ ๊ฐ๋ฅ)
๋ฌธ์ ํด๊ฒฐ๋ ฅ
์ ํ ๋ฌธ์ ๋ง ํด๊ฒฐ(XOR ๋ถ๊ฐ)
๋น์ ํ ๋ฌธ์ (XOR ๋ฑ) ํด๊ฒฐ ๊ฐ๋ฅ
-
Day3: Perceptron_MLP
#
๐ Perceptron์ด๋?
1957๋
ํ๋ญํฌ ๋ก์ ๋ธ๋ผํธ๊ฐ ๊ณ ์ํ ์ต์ด์ ์ธ๊ณต์ ๊ฒฝ๋ง ๋ชจ๋ธ ์ค ํ๋.
์๋ฌผํ์ ๋ด๋ฐ์ ์ํ์ ์ผ๋ก ๋ชจ๋ธ๋งํ ์ธ๊ณต ๋ด๋ฐ์ผ๋ก, ์ฌ๋ฌ ์
๋ ฅ ์ ํธ๋ฅผ ๋ฐ์ ๊ฐ๊ฐ์ ๊ฐ์ค์น๋ฅผ ๊ณฑํ ํ ์ด๋ฅผ ํฉ์ฐํ์ฌ, ํ์ฑํ ํจ์๋ฅผ ํตํด ๋จ์ผ ์ ํธ๋ฅผ ์ถ๋ ฅํ๋ค.
ํผ์
ํธ๋ก ์ ์ถ๋ ฅ์ ์ ํธ ์ ๋ฌด (1 ๋๋ 0)๋ก ํํ๋๊ณ , ์ด์ง ๋ถ๋ฅ ๋ฌธ์ ํด๊ฒฐ์ ํจ๊ณผ์ ์ด๋ค.
๐ Perceptron AND_GATE ์ค์ต
๐ AND ๊ฒ์ดํธ ๋ชจ๋ธ ํ๋ จ ํ ๊ฒฐ๊ณผ ํ์ธ
import numpy as np
import matplotlib.pyplot as plt
class Perceptron:
def __init__(self, input_size, lr=0.1, epochs=10):
self.weights = np.zeros(input_size)
self.bias = 0
self.lr = lr
self.epochs = epochs
self.errors = []
def activation(self, x):
return np.where(x >= 0, 1, 0)
def predict(self, x):
linear_output = np.dot(x, self.weights) + self.bias
return self.activation(linear_output)
def train(self, X, y):
for epoch in range(self.epochs):
total_error = 0
for x1, target in zip(X, y):
prediction = self.predict(x1)
update = self.lr * (target - prediction)
self.weights += update * x1
self.bias += update
total_error += int(update != 0)
self.errors.append(total_error)
print(f"Epoch {epoch+1}/{self.epochs}, Errors: {total_error}")
# AND ๊ฒ์ดํธ ๋ฐ์ดํฐ
X_and = np.array([[0,0],[0,1],[1,0],[1,1]])
y_and = np.array([0,0,0,1])
# ํผ์
ํธ๋ก ๋ชจ๋ธ ํ๋ จ
ppn_and = Perceptron(input_size=2)
ppn_and.train(X_and, y_and)
# ์์ธก ๊ฒฐ๊ณผ ํ์ธ
print("\nAND Gate Test:")
for x in X_and:
print(f"Input: {x}, Predicted Output: {ppn_and.predict(x)}")
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
๐ AND ๊ฒ์ดํธ ๊ฒฐ์ ๊ฒฝ๊ณ ์๊ฐํ
from matplotlib.colors import ListedColormap
def plot_decision_boundary(X, y, model):
cmap_light = ListedColormap(['#FFAAAA', '#AAAAFF'])
cmap_bold = ListedColormap(['#FF0000', '#0000FF'])
h = .02 # mesh grid ๊ฐ๊ฒฉ
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(y_min, y_max, h))
Z = model.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.figure(figsize=(8, 6))
plt.contourf(xx, yy, Z, cmap=cmap_light)
# ์ค์ ๋ฐ์ดํฐ ํฌ์ธํธ ํ์
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold,
edgecolor='k', s=100, marker='o')
plt.xlabel('Input 1')
plt.ylabel('Input 2')
plt.title('Perceptron Decision Boundary')
plt.show()
# AND ๊ฒ์ดํธ ๊ฒฐ์ ๊ฒฝ๊ณ ์๊ฐํ
plot_decision_boundary(X_and, y_and, ppn_and)
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
๐ ์ค๋ฅ ์๊ฐํ
plt.figure(figsize=(8, 5))
plt.plot(range(1, len(ppn_and.errors) + 1), ppn_and.errors, marker='o')
plt.xlabel('Epochs')
plt.ylabel('Number of Errors')
plt.title('Perceptron Learning Error Over Epochs (AND Gate)')
plt.grid(True)
plt.show()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
๐ Perceptron OR_GATE ์ค์ต
๐ OR ๊ฒ์ดํธ ๋ชจ๋ธ ํ๋ จ ํ ๊ฒฐ๊ณผ ํ์ธ
import numpy as np
import matplotlib.pyplot as plt
class Perceptron:
def __init__(self, input_size, lr=0.1, epochs=10):
self.weights = np.zeros(input_size)
self.bias = 0
self.lr = lr
self.epochs = epochs
self.errors = []
def activation(self, x):
return np.where(x >= 0, 1, 0)
def predict(self, x):
linear_output = np.dot(x, self.weights) + self.bias
return self.activation(linear_output)
def train(self, X, y):
for epoch in range(self.epochs):
total_error = 0
for x1, target in zip(X, y):
prediction = self.predict(x1)
update = self.lr * (target - prediction)
self.weights += update * x1
self.bias += update
total_error += int(update != 0)
self.errors.append(total_error)
print(f"Epoch {epoch+1}/{self.epochs}, Errors: {total_error}")
# OR ๊ฒ์ดํธ ๋ฐ์ดํฐ
X_or = np.array([[0,0],[0,1],[1,0],[1,1]])
y_or = np.array([0,1,1,1])
# ํผ์
ํธ๋ก ๋ชจ๋ธ ํ๋ จ
ppn_or = Perceptron(input_size=2)
ppn_or.train(X_or, y_or)
# ์์ธก ๊ฒฐ๊ณผ ํ์ธ
print("\nOR Gate Test:")
for x in X_or:
print(f"Input: {x}, Predicted Output: {ppn_or.predict(x)}")
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
๐ OR ๊ฒ์ดํธ ๊ฒฐ์ ๊ฒฝ๊ณ ์๊ฐํ
from matplotlib.colors import ListedColormap
def plot_decision_boundary(X, y, model):
cmap_light = ListedColormap(['#FFAAAA', '#AAAAFF'])
cmap_bold = ListedColormap(['#FF0000', '#0000FF'])
h = .02 # mesh grid ๊ฐ๊ฒฉ
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(y_min, y_max, h))
Z = model.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.figure(figsize=(8, 6))
plt.contourf(xx, yy, Z, cmap=cmap_light)
# ์ค์ ๋ฐ์ดํฐ ํฌ์ธํธ ํ์
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold,
edgecolor='k', s=100, marker='o')
plt.xlabel('Input 1')
plt.ylabel('Input 2')
plt.title('Perceptron Decision Boundary')
plt.show()
# OR ๊ฒ์ดํธ ๊ฒฐ์ ๊ฒฝ๊ณ ์๊ฐํ
plot_decision_boundary(X_or, y_or, ppn_or)
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
๐ ์ค๋ฅ ์๊ฐํ
plt.figure(figsize=(8, 5))
plt.plot(range(1, len(ppn_or.errors) + 1), ppn_or.errors, marker='o')
plt.xlabel('Epochs')
plt.ylabel('Number of Errors')
plt.title('Perceptron Learning Error Over Epochs (OR Gate)')
plt.grid(True)
plt.show()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
๐ Perceptron NAND_GATE ์ค์ต
๐ NAND ๊ฒ์ดํธ ๋ชจ๋ธ ํ๋ จ ํ ๊ฒฐ๊ณผ ํ์ธ
import numpy as np
import matplotlib.pyplot as plt
class Perceptron:
def __init__(self, input_size, lr=0.1, epochs=10):
self.weights = np.zeros(input_size)
self.bias = 0
self.lr = lr
self.epochs = epochs
self.errors = []
def activation(self, x):
return np.where(x >= 0, 1, 0)
def predict(self, x):
linear_output = np.dot(x, self.weights) + self.bias
return self.activation(linear_output)
def train(self, X, y):
for epoch in range(self.epochs):
total_error = 0
for x1, target in zip(X, y):
prediction = self.predict(x1)
update = self.lr * (target - prediction)
self.weights += update * x1
self.bias += update
total_error += int(update != 0)
self.errors.append(total_error)
print(f"Epoch {epoch+1}/{self.epochs}, Errors: {total_error}")
# NAND ๊ฒ์ดํธ ๋ฐ์ดํฐ
X_nand = np.array([[0,0],[0,1],[1,0],[1,1]])
y_nand = np.array([1,1,1,0])
# ํผ์
ํธ๋ก ๋ชจ๋ธ ํ๋ จ
ppn_nand = Perceptron(input_size=2)
ppn_nand.train(X_nand, y_nand)
# ์์ธก ๊ฒฐ๊ณผ ํ์ธ
print("\nNAND Gate Test:")
for x in X_nand:
print(f"Input: {x}, Predicted Output: {ppn_nand.predict(x)}")
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
๐ NAND ๊ฒ์ดํธ ๊ฒฐ์ ๊ฒฝ๊ณ ์๊ฐํ
from matplotlib.colors import ListedColormap
def plot_decision_boundary(X, y, model):
cmap_light = ListedColormap(['#FFAAAA', '#AAAAFF'])
cmap_bold = ListedColormap(['#FF0000', '#0000FF'])
h = .02 # mesh grid ๊ฐ๊ฒฉ
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(y_min, y_max, h))
Z = model.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.figure(figsize=(8, 6))
plt.contourf(xx, yy, Z, cmap=cmap_light)
# ์ค์ ๋ฐ์ดํฐ ํฌ์ธํธ ํ์
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold,
edgecolor='k', s=100, marker='o')
plt.xlabel('Input 1')
plt.ylabel('Input 2')
plt.title('Perceptron Decision Boundary')
plt.show()
# NAND ๊ฒ์ดํธ ๊ฒฐ์ ๊ฒฝ๊ณ ์๊ฐํ
plot_decision_boundary(X_nand, y_nand, ppn_nand)
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
๐ ์ค๋ฅ ์๊ฐํ
plt.figure(figsize=(8, 5))
plt.plot(range(1, len(ppn_or.errors) + 1), ppn_or.errors, marker='o')
plt.xlabel('Epochs')
plt.ylabel('Number of Errors')
plt.title('Perceptron Learning Error Over Epochs (OR Gate)')
plt.grid(True)
plt.show()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
๐ Perceptron XOR_GATE ์ค์ต
๐ XOR ๊ฒ์ดํธ ๋ชจ๋ธ ํ๋ จ ํ ๊ฒฐ๊ณผ ํ์ธ
import numpy as np
import matplotlib.pyplot as plt
class Perceptron:
def __init__(self, input_size, lr=0.1, epochs=10):
self.weights = np.zeros(input_size)
self.bias = 0
self.lr = lr
self.epochs = epochs
self.errors = []
def activation(self, x):
return np.where(x >= 0, 1, 0)
def predict(self, x):
linear_output = np.dot(x, self.weights) + self.bias
return self.activation(linear_output)
def train(self, X, y):
for epoch in range(self.epochs):
total_error = 0
for x1, target in zip(X, y):
prediction = self.predict(x1)
update = self.lr * (target - prediction)
self.weights += update * x1
self.bias += update
total_error += int(update != 0)
self.errors.append(total_error)
print(f"Epoch {epoch+1}/{self.epochs}, Errors: {total_error}")
# XOR ๊ฒ์ดํธ ๋ฐ์ดํฐ
X_xor = np.array([[0,0],[0,1],[1,0],[1,1]])
y_xor = np.array([0,1,1,0])
# ํผ์
ํธ๋ก ๋ชจ๋ธ ํ๋ จ
ppn_xor = Perceptron(input_size=2)
ppn_xor.train(X_xor, y_xor)
# ์์ธก ๊ฒฐ๊ณผ ํ์ธ
print("\nXOR Gate Test:")
for x in X_xor:
print(f"Input: {x}, Predicted Output: {ppn_xor.predict(x)}")
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
๐ XOR ๊ฒ์ดํธ ๊ฒฐ์ ๊ฒฝ๊ณ ์๊ฐํ
from matplotlib.colors import ListedColormap
def plot_decision_boundary(X, y, model):
cmap_light = ListedColormap(['#FFAAAA', '#AAAAFF'])
cmap_bold = ListedColormap(['#FF0000', '#0000FF'])
h = .02 # mesh grid ๊ฐ๊ฒฉ
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(y_min, y_max, h))
Z = model.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.figure(figsize=(8, 6))
plt.contourf(xx, yy, Z, cmap=cmap_light)
# ์ค์ ๋ฐ์ดํฐ ํฌ์ธํธ ํ์
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold,
edgecolor='k', s=100, marker='o')
plt.xlabel('Input 1')
plt.ylabel('Input 2')
plt.title('Perceptron Decision Boundary')
plt.show()
# XOR ๊ฒ์ดํธ ๊ฒฐ์ ๊ฒฝ๊ณ ์๊ฐํ
plot_decision_boundary(X_xor, y_xor, ppn_xor)
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
๐ ์ค๋ฅ ์๊ฐํ
plt.figure(figsize=(8, 5))
plt.plot(range(1, len(ppn_or.errors) + 1), ppn_or.errors, marker='o')
plt.xlabel('Epochs')
plt.ylabel('Number of Errors')
plt.title('Perceptron Learning Error Over Epochs (OR Gate)')
plt.grid(True)
plt.show()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
๐จ ๋จ์ธต Perceptron์ ํ๊ณ์
XOR GATE๋ ํผ์
ํธ๋ก ์ผ๋ก ํ์ต์ด ๋์ง ์๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์๋ค.
ํผ์
ํธ๋ก ์ ์ง์ ํ๋๋ก โ์ โ๋ฅผ ๋๋ ์ ์์ด์ผ ํ์ต์ด ๋๋ค.
ํ์ง๋ง XOR์ ์ง์ ํ๋๋ก๋ ์ ๋ โ์ โ๋ฅผ ๋๋ ์ ์๋ค.
-
Basic Operation
๐ ํ์ต๋ชฉํ
OpenCV(Open Source Computer Vision Library)๋ฅผ ํ์ฉํ์ฌ ์ด๋ฏธ์ง/๋น๋์ค ์ฒ๋ฆฌํ๊ธฐ
1. ์ด๋ฏธ์ง Read & Write
๐ ์ด๋ฏธ์ง ํ์ผ ์ค๋น
import numpy as np
import cv2
img = cv2.imread("image.jpg")
cv2.namedWindow("image", cv2.WINDOW_NORMAL)
print(img.shape)
cv2.imshow("image", img)
cv2.waitKey(0)
cv2.imwrite("output.png", img)
cv2.destroyAllWindows()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
2. ์์ ์ฑ๋ ๋ถ๋ฆฌ์ ์๊ณต๊ฐ ๋ณํ
๐ ์ด๋ฏธ์ง ํ์ผ ์ค๋น
import numpy as np
import cv2
color = cv2.imread("strawberry.jpg", cv2.IMREAD_COLOR)
print(color.shape)
height, width, channels = color.shape
cv2.imshow("Original Image", color)
r,g,b = cv2.split(color)
rgb_split = np.concatenate((r,g,b), axis=1)
cv2.imshow("RGB Channels", rgb_split)
hsv = cv2.cvtColor(color, cv2.COLOR_RGB2HSV)
h,s,v = cv2.split(hsv)
hsv_split = np.concatenate((h,s,v),axis=1)
cv2.imshow("Split HSV", hsv_split)
cv2.waitKey(0)
cv2.imwrite("hsv2rgb_split.png", hsv_split)
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
3. ์ด๋ฏธ์ง ์ผ๋ถ ์์ญ ์๋ฅด๊ธฐ, ํฌ๊ธฐ ๋ฐ๊พธ๊ธฐ, ํ์ ํ๊ธฐ
๐ ์ด๋ฏธ์ง ํ์ผ ์ค๋น
import numpy as np
import cv2
img = cv2.imread("image.jpg")
print(img.shape) # 0,100
cropped = img[0:220, 185:385] #220, 200, 3
print(cropped.shape)
resized = cv2.resize(cropped, (400,200))
print(resized.shape)
rotated_90 = cv2.rotate(resized, cv2.ROTATE_90_CLOCKWISE)
#rotated_180 = cv2.rotate(image, cv2.ROTATE_180)
#rotated_270 = cv2.rotate(image, cv2.ROTATE_90_COUNTERCLOCKWISE)
cv2.imshow("Origin", img)
cv2.imshow("Cropped image", cropped)
cv2.imshow("Resized image", resized)
cv2.imshow("Rotated 90 image", rotated_90)
cv2.waitKey(0)
cv2.destroyAllWindows()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
cropped
resized
rotated_90
4. ์๋ณธ ์์ ๋ฐ์ ์ํค๊ธฐ
๐ ์ด๋ฏธ์ง ํ์ผ ์ค๋น
import numpy as np
import cv2
src = cv2.imread("output.png", cv2.IMREAD_COLOR)
dst = cv2.bitwise_not(src)
cv2.imshow("src", src)
cv2.imshow("dst", dst)
cv2.waitKey()
cv2.destroyAllWindows()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
5. ์๊ณ๊ฐ ๊ธฐ์ค์ผ๋ก ์ด์งํ์ํค๊ธฐ
๐ ์ด๋ฏธ์ง ํ์ผ ์ค๋น
import cv2
src = cv2.imread("image.jpg", cv2.IMREAD_COLOR)
gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
ret, dst = cv2.threshold(gray, 100, 255, cv2.THRESH_BINARY)
cv2.imshow("dst", dst)
cv2.waitKey()
cv2.destroyAllWindows()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
6. ์ด๋ฏธ์ง ํ๋ฆฌ๊ฒ(๋ธ๋ฌ) ์ฒ๋ฆฌ
๐ ์ด๋ฏธ์ง ํ์ผ ์ค๋น
import cv2
src = cv2.imread("image.jpg", cv2.IMREAD_COLOR)
dst = cv2.blur(src, (9, 9), anchor=(-1, -1), borderType=cv2.BORDER_DEFAULT)
cv2.imshow("dst", dst)
cv2.waitKey()
cv2.destroyAllWindows()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
7. ์ธ ๊ฐ์ง ๋ํ์ ์ธ ์ฃ์ง(๊ฒฝ๊ณ) ๊ฒ์ถ ์๊ณ ๋ฆฌ์ฆ
๐ ์ด๋ฏธ์ง ํ์ผ ์ค๋น
import cv2
src = cv2.imread("image.jpg", cv2.IMREAD_COLOR)
gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
sobel = cv2.Sobel(gray, cv2.CV_8U, 1, 0, 3)
cv2.imshow("sobel", sobel)
laplacian = cv2.Laplacian(gray, cv2.CV_8U, ksize=3)
cv2.imshow("laplacian", laplacian)
canny = cv2.Canny(gray, 100, 200)
cv2.imshow("canny", canny)
cv2.waitKey()
cv2.destroyAllWindows()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
sobel
laplacian
canny
8. ์ปฌ๋ฌ ์ด๋ฏธ์ง์ BGR(Blue, Green, Red) ์ฑ๋์ ๋ถ๋ฆฌ ํ ์ฑ๋ ์์๋ฅผ ๋ฐ๊ฟ์ ์ด๋ฏธ์ง ํฉ์น๊ธฐ
๐ ์ด๋ฏธ์ง ํ์ผ ์ค๋น
import numpy as np
import cv2
src = cv2.imread("image.jpg", cv2.IMREAD_COLOR)
#b,g,r = cv2.split(src)
b = src[:, :, 0]
g = src[:, :, 1]
r = src[:, :, 2]
inverse = cv2.merge((r,g,b))
cv2.imshow("b", b)
cv2.imshow("g", g)
cv2.imshow("r", r)
cv2.imshow("inverse", inverse)
cv2.waitKey()
cv2.destroyAllWindows()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
B
G
R
inverse
9. ์ปฌ๋ฌ ์ด๋ฏธ์ง์ BGR(Blue, Green, Red) ์ฑ๋์ ๋ถ๋ฆฌ ํ Red ์ฑ๋๋ง 0(๊ฒ์ ์)
๐ ์ด๋ฏธ์ง ํ์ผ ์ค๋น
import numpy as np
import cv2
src = cv2.imread("bgr.png", cv2.IMREAD_COLOR)
b = src[:, :, 0]
g = src[:, :, 1]
r = src[:, :, 2]
height, width, channel = src.shape
zero = np.zeros((height, width, 1), dtype=np.uint8)
bgz = cv2.merge((b, g, zero))
cv2.imshow("b", b)
cv2.imshow("g", g)
cv2.imshow("r", r)
cv2.imshow("bgz", bgz)
cv2.waitKey()
cv2.destroyAllWindows()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
B
G
R
bgz
10. ๋์์์์ ์ํ๋ ์ฅ๋ฉด์ ์ด๋ฏธ์ง๋ก ์บก์ฒํ๊ธฐ
๐ ๋์์ ํ์ผ ์ค๋น
import numpy as np
import cv2
import os
save_dir = "SON"
os.makedirs(save_dir, exist_ok=True)
cap = cv2.VideoCapture("output.mp4")
img_idx = 1
while cap.isOpened():
ret, frame = cap.read()
if not ret:
cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
continue
height, width = frame.shape[:2]
small_frame = cv2.resize(frame, (width // 2, height // 2), interpolation=cv2.INTER_AREA)
cv2.imshow("Frame", small_frame)
key = cv2.waitKey(80)
if key & 0xFF == ord('q'):
break
if key & 0xFF == ord('c'):
while True:
filename = f"{img_idx:03d}.jpg"
filepath = os.path.join(save_dir, filename)
if not os.path.exists(filepath):
cv2.imwrite(filepath, small_frame)
print(f"Saved {filepath}")
img_idx += 1
break
else:
img_idx += 1
cap.release()
cv2.destroyAllWindows()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
11. ๋ค์ํ OpenCV ๊ทธ๋ฆฌ๊ธฐ ํจ์ ์ฌ์ฉํด๋ณด๊ธฐ
import numpy as np
import cv2
cap = cv2.VideoCapture(5)
circle_centers = []
def draw_circle(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
circle_centers.append((x, y))
cv2.namedWindow("Camera")
cv2.setMouseCallback("Camera", draw_circle)
topLeft = (50, 50)
bottomRight = (300, 300)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
cv2.line(frame, topLeft, bottomRight, (0, 255, 0), 3)
cv2.rectangle(frame,
[pt+30 for pt in topLeft], [pt-30 for pt in bottomRight], (255, 0, 255), 3)
font = cv2.FONT_ITALIC
cv2.putText(frame, 'me',
[pt+40 for pt in bottomRight], font, 2, (255, 0, 255), 5)
for center in circle_centers:
cv2.circle(frame, center, 30, (255, 255, 0), 3)
cv2.imshow("Camera", frame)
key = cv2.waitKey(1)
if key & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
12. ์ค์๊ฐ ์นด๋ฉ๋ผ ์์ ์์ ๊ธ์ ์ถ๋ ฅํ๊ณ ํธ๋๋ฐ๋ก ๊ตต๊ธฐ, ํฌ๊ธฐ, ์์ ์กฐ์ ํ๊ธฐ
import numpy as np
import cv2
cap = cv2.VideoCapture(4)
#initial
topLeft = (100, 100)
bold = 0
font_size = 1
r, g, b = 0, 255, 255
def on_bold_trackbar(value):
global bold
bold = value
def on_fontsize_trackbar(value):
global font_size
font_size = max(1, value)
def on_r(val):
global r
r = val
def on_g(val):
global g
g = val
def on_b(val):
global b
b = val
cv2.namedWindow("Camera")
cv2.createTrackbar("bold", "Camera", bold, 10, on_bold_trackbar)
cv2.createTrackbar("font size", "Camera", font_size, 10, on_fontsize_trackbar)
cv2.createTrackbar('R', 'Camera', 0, 255, on_r)
cv2.createTrackbar('G', 'Camera', 255, 255, on_g)
cv2.createTrackbar('B', 'Camera', 255, 255, on_b)
while cap.isOpened():
ret, frame = cap.read()
if ret is False:
print("Can't receive frame (stream end?). Exiting . . .")
break
# Text
cv2.putText(frame, 'TEXT', topLeft, cv2.FONT_HERSHEY_SIMPLEX, font_size, (b, g, r), 1 + bold)
# Display
cv2.imshow("Camera", frame)
key = cv2.waitKey(1)
if key & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
13. ์ค์๊ฐ ์นด๋ฉ๋ผ ์์ ์์ ํ๊ธ ์ถ๋ ฅํ๊ณ ํธ๋๋ฐ๋ก ๊ตต๊ธฐ, ํฌ๊ธฐ, ์์ ์กฐ์ ํ๊ธฐ
import numpy as np
import cv2
from PIL import ImageFont, ImageDraw, Image
cap = cv2.VideoCapture(4)
topLeft = (100, 100)
bold = 0
font_size = 10
r, g, b = 0, 255, 255
def on_bold_trackbar(value):
global bold
bold = value
def on_fontsize_trackbar(value):
global font_size
font_size = max(10, value * 5)
def on_r(val):
global r
r = val
def on_g(val):
global g
g = val
def on_b(val):
global b
b = val
cv2.namedWindow("Camera")
cv2.createTrackbar("bold", "Camera", bold, 10, on_bold_trackbar)
cv2.createTrackbar("font size", "Camera", font_size//5, 10, on_fontsize_trackbar)
cv2.createTrackbar('R', 'Camera', 0, 255, on_r)
cv2.createTrackbar('G', 'Camera', 255, 255, on_g)
cv2.createTrackbar('B', 'Camera', 255, 255, on_b)
font_path = "NanumGothic.ttf"
while cap.isOpened():
ret, frame = cap.read()
if not ret:
print("Can't receive frame (stream end?). Exiting . . .")
break
img_pil = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
draw = ImageDraw.Draw(img_pil)
font = ImageFont.truetype(font_path, font_size)
text = 'LEE ์์ฑ'
# Bold ํจ๊ณผ: ์ฌ๋ฌ ๋ฒ ๊ฒน์ณ ๊ทธ๋ฆฌ๊ธฐ
for dx in range(-bold, bold+1):
for dy in range(-bold, bold+1):
draw.text((topLeft[0]+dx, topLeft[1]+dy), text, font=font, fill=(r, g, b, 0))
frame = cv2.cvtColor(np.array(img_pil), cv2.COLOR_RGB2BGR)
cv2.imshow("Camera", frame)
key = cv2.waitKey(1)
if key & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
๐ก ์ถ๋ ฅ ๊ฒฐ๊ณผ
-
Day1: AI Algotirhm and Structure
Von Neumann Architecture
ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ
ํฐ ๋
ธ์ด๋ง ๋ณ๋ชฉ ํ์
ํ๋ฒ๋ ๊ตฌ์กฐ
ํ์ดํ๋ผ์ธ
1. ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ
ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ๋?
ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ๊ฐ ๋ฑ์ฅํ๊ธฐ ์ ๊น์ง๋ ํ๋์์ด์ด๋ ํ๋ก๊ทธ๋๋ฐ ๋ฐฉ์์ ์ฌ์ฉํ๋ค. ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ๊ฐ ๋ฑ์ฅํ๋ฉด์, ํ๋ก๊ทธ๋จ ๋ด์ฅ ๋ฐฉ์์ ์ฌ์ฉํ๊ฒ ๋์๊ณ , ํน์ง์ ๋ช
๋ น์ด์ ๋ฐ์ดํฐ๊ฐ ๊ฐ์ ๋ฉ๋ชจ๋ฆฌ ๊ณต๊ฐ์ ์ ์ฅ๋๊ณ ์์ฐจ์ ์ผ๋ก ์คํ๋๋ค.
ํ๋์์ด์ด๋ ํ๋ก๊ทธ๋๋ฐ ๋ฐฉ์ : ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ๊ฐ ๋ฑ์ฅํ๊ธฐ ์ ๊น์ง๋ ๊ณ์ฐ์ ํ ๋๋ง๋ค ์์ผ๋ก ์ง์ ์ง๊ณต๊ด์ ํ๋ก ์ค์์น๋ฅผ ์กฐ์ ํ์ฌ ์ ์
๋ ฅ์ ์ฒ๋ฆฌํ๋ ํ๋์จ์ด ํ๋ก๊ทธ๋จ ๋ฐฉ์
ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ์ ์ฃผ์ ๊ตฌ์ฑ ์์
์ค์์ฒ๋ฆฌ์ฅ์น(CPU)
๋ฉ๋ชจ๋ฆฌ(Memory)
์
์ถ๋ ฅ์ฅ์น(In.Out Device)
๋ฒ์ค ์์คํ
(Bus)
ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ์ ๋์ ์๋ฆฌ
ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ์ ์ปดํจํฐ๋ ๋ช
๋ น์ด ์คํ ์ฌ์ดํด์ ๋ฐ๋ณต ๋์ํ๋ค.
๋ช
๋ น์ด ์ธ์ถ(Fetch): ๋ฉ๋ชจ๋ฆฌ์์ ๋ช
๋ น์ด๋ฅผ ๊ฐ์ ธ์จ๋ค.
๋ช
๋ น์ด ํด์(Decode): ๋ฉ๋ชจ๋ฆฌ์์ ๊ฐ์ ธ์จ ๋ช
๋ น์ด๊ฐ ์ด๋ค ๋ช
๋ น์ด์ธ์ง ํด์ํ๋ค.
๋ช
๋ น์ด ์คํ(Execute): ๋ช
๋ น์ด๋ฅผ ์คํํ๋ค.
๋ฉ๋ชจ๋ฆฌ ์ฐ์ฐ(Data Memory): ๋ช
๋ น์ด ์ํ์ ์ํด ๋ฉ๋ชจ๋ฆฌ์ ๋ฐ์ดํฐ ๋ ์ง์คํฐ ๊ฐ์ ๋ฐ์ดํฐ ์ด๋์ ์ฒ๋ฆฌ
์ ์ฅ(WriteBack): ์ฐ์ฐ ๊ฒฐ๊ณผ๋ฅผ ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅํ๋ค.
//์ฌ์ง ๋ฃ๊ธฐ
2. ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ์ ๋ณ๋ชฉ ํ์
ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ์ ๋จ์
ํฐ๋
ธ์ด๋ง ๊ตฌ์กฐ์ ๊ฐ์ฅ ์น๋ช
์ ์ธ ๋จ์ ์ ํฐ๋
ธ์ด๋ง ๋ณ๋ชฉํ์์ด๋ค.
๋จ์ผ ๋ฒ์ค ๊ตฌ์กฐ
๋ช
๋ น์ด์ ๋ฐ์ดํฐ๊ฐ ๊ฐ์ ๋ฒ์ค๋ฅผ ๊ณต์ ํ๊ธฐ ๋๋ฌธ์ ๋ํ๋๋ ํ์์ด๋ค. CPU๋ ํ๋ฒ์ ๋ช
๋ น์ด ๋๋ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๊ธฐ ๋๋ฌธ์ ๋์์ ๋ถ๊ฐ๋ฅํ๋ค.
๋ฉ๋ชจ๋ฆฌ ๋ฒฝ
CPU์ ์ฑ๋ฅ์ ๊ธฐํ๊ธ์์ ์ผ๋ก ๋ฐ์ ํ์ง๋ง, ๋ฉ๋ชจ๋ฆฌ์ ์๋๊ฐ ๊ทธ์ ๋ฏธ์น์ง ๋ชปํด ์ด ์๋ ๊ฒฉ์ฐจ๊ฐ CPU์ ๋๊ธฐ ์๊ฐ์ ๋๋ ค CPU์ ์ ์ฑ๋ฅ์ ๋ฐํํ์ง ๋ชปํ๋ค.
์์ฐจ์ ์ฒ๋ฆฌ
๋ช
๋ น์ด๊ฐ ์์ฐจ์ ์ผ๋ก ์คํ์ด ๋๋๋ฐ, ์ด๋ฌํ ์ฒ๋ฆฌ ๋ฐฉ์์ ๊ฐ์๋ก ๋ฐ์ดํฐ ์ข
๋ฅ๊ฐ ๋ค์ํด์ง๊ณ , ๋๊ท๋ชจ ๋ณ๋ ฌ ์ฐ์ฐ์ด ํ์ํ ํ๋ ์ฌํ์์๋ ๋นํจ์จ์ ์ด๋ค.
ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ์ ๋ณ๋ชฉํ์์ด ๋ฏธ์น๋ ์ํฅ
์๋์ ์ผ๋ก ๋ฉ๋ชจ๋ฆฌ๋ณด๋ค ๋น ๋ฅธ CPU๊ฐ ๋๋ถ๋ถ์ ์๊ฐ์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๊ธฐ๋ค๋ฆฌ๊ฒ ๋๋ฏ๋ก ์์คํ
์ ์ฑ๋ฅ ์ ํ๋ก ์ด์ด์ง๋ค. (CPU์ ์ ํ ์๊ฐ ์ฆ๊ฐ)
๋ฐ์ดํฐ๊ฐ CPU์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์๋ค๊ฐ๋คํ๋ ๊ฒ์ด ์ ๋ ฅ ์๋ชจ๊ฐ ํฌ๋ค.
-> ์ ํธ ์ ์ด(Transition)์ ๋ฐ๋ฅธ ์ ๋ ฅ ์๋ชจ
๋ฒ์ค์์ ๋ฐ์ดํฐ๊ฐ 0->1, 1->0์ผ๋ก ๋ฐ๋ ๋๋ง๋ค transition์ด ๋ฐ์ -> transition์ ํ์๊ฐ ๋ง์์ง์๋ก ์ ๋ ฅ ์๋ชจ ์ฆ๊ฐ
-> ์บํจ์ํฐ ์ถฉ์ ๊ณผ ๋ฐฉ์
๋ฒ์ค์ ์ ๋ก๋ ์บํจ์ํฐ ์ญํ ์ ํจ -> ๋ฐ์ดํฐ๊ฐ ๋ณ๊ฒฝ ๋ ๋๋ง๋ค ์ปคํจ์ํฐ๋ฅผ ์ถฉ๋ฐฉ์ ํ๊ฒ ๋๋ค -> ๋ ๋น ๋ฅธ ์ค์์นญ์ ์ํด์๋ ๋์ ๊ณผ๋ ์ ๋ฅ๊ฐ ํ์ํ๊ฒ ๋์ด ์ ๋ ฅ ์๋ชจ๊ฐ ์ฆ๊ฐํ๊ฒ ๋๋ค.
3. ํ๋ฒ๋ ๊ตฌ์กฐ
ํ๋ฒ๋ ๊ตฌ์กฐ๋?
ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ์์๋ ํ๋์ ๋ฒ์ค ์์คํ
์์ ๋ฐ์ดํฐ์ ๋ช
๋ น์ด๊ฐ ์ด๋ํ์ง๋ง, ํ๋ฒ๋ ๊ตฌ์กฐ๋ ๋ช
๋ น์ด์ ๋ฐ์ดํฐ๋ฅผ ๋ฌผ๋ฆฌ์ ์ผ๋ก ๋ถ๋ฆฌ๋ ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅํ๊ณ ์ ๊ทผํ๋ ๊ตฌ์กฐ์ด๋ค.
ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ vs ํ๋ฒ๋ ๊ตฌ์กฐ
ํ๋ฒ๋ ๊ตฌ์กฐ์์๋ ํฐ ๋
ธ์ด๋ง ๊ตฌ์กฐ์ ๋ฌ๋ฆฌ ๋ช
๋ น์ด๋ฅผ ๋ฉ๋ชจ๋ฆฌ๋ก๋ถํฐ ์ฝ๋ ๊ฒ๊ณผ ๋ฐ์ดํฐ๋ฅผ ๋ฉ๋ชจ๋ฆฌ๋ก๋ถํฐ ์ฝ๋ ๊ฒ์ ๋์์ ํ ์ ์๋ค.
ํ๋ฒ๋ ๊ตฌ์กฐ๋ ๋ณ๋ ฌ ์ฒ๋ฆฌ๋ฅผ ํตํ ์ฑ๋ฅ ํฅ์์ด ๊ฐ๋ฅํ๋ค. ํ์ฌ ๋ช
๋ น์ด๋ฅผ ์ฒ๋ฆฌํจ๊ณผ ๋์์ ๋ค์ ๋ช
๋ น์ด๋ฅผ ์ฝ์ ์ ์๋ค. (ํ์ดํ๋ผ์ธ)
ํ๋ฒ๋ ๊ตฌ์กฐ ์ ์ฉ ์ฌ๋ก
๋์งํธ ์ ํธ ์ฒ๋ฆฌ๊ธฐ (DSP)์์ ์ฃผ๋ก ์ฌ์ฉํ๋ค. ์ค์๊ฐ ๋ฐ์ดํฐ ์ฒ๋ฆฌ๊ฐ ์ค์ํ ํ๋ก์ธ์๋ก, ํ๋ฒ๋ ๊ตฌ์กฐ์ ๋ณ๋ ฌ ๋ฉ๋ชจ๋ฆฌ ์ ๊ทผ ๋ฅ๋ ฅ์ด ๋ ๋์ ๋ฉ๋ชจ๋ฆฌ ๋์ญํญ์ ์ ๊ณตํ๊ธฐ ๋๋ฌธ์ด๋ค.
๋ฉ๋ชจ๋ฆฌ ๋์ญํญ์ด๋?
-> ๋จ์ ์๊ฐ๋น ์ ์ก ๊ฐ๋ฅํ ๋ฐ์ดํฐ์ ์, ์ด๋น ์ผ๋ง๋ ๋ง์ ๋นํธ(bit)๋ฅผ ์ฃผ๊ณ ๋ฐ์ ์ ์๋ ์ง.
-> CPU๊ฐ ๋ช
๋ น์ด๋ฅผ ์ธ์ถํ๋ฉด์ ๋์์ ๋ฐ์ดํฐ ๋ฉ๋ชจ๋ฆฌ์์ ์ฐ์ฐ์ ํ์ํ ๋ฐ์ดํฐ๋ฅผ ์ฝ์ด์ฌ ์ ์๋ค. ์ฆ, ๋ ๊ฐ์ ๋
๋ฆฝ๋ ๋ช
๋ น์ด ๋ฒ์ค, ๋ฐ์ดํฐ ๋ฒ์ค๋ฅผ ํตํด ๋์์ ์ ์ก์ด ๊ฐ๋ฅํ๋ฏ๋ก ์ ์ฒด ๋ฉ๋ชจ๋ฆฌ ๋์ญํญ์ ๋๋ฐฐ๋ก ์ฌ์ฉ ๊ฐ๋ฅ.
-
-
-
-
CMOS Inverter
CMOS Inverter Simulation with Synopsys Custom Compiler
This guide walks through creating, simulating, and analyzing a CMOS inverter schematic using Synopsys Custom Compiler and PrimeWave.
1. Library and Cell Setup
Create a new library:
New โ Library
Set attributes:
Name: Library name
Technology: Select tech library
Create a new CellView:
File โ New โ CellView
Configure:
Cell Name: Inverter
View Name: schematic
Design Settings:
Options โ Design โ Configure:
Snap Spacing (X,Y): Grid spacing
Solder Dot Size: Connection point size
Fat Wire Width: Thick wire width
Default Net Prefix: Signal prefix
2. Schematic Design
Add Components:
Use the Add tool (I=Instance, W=Wire, L=Label, P=Pin):
Add
I
W
L
P
Instance
Wire
Label
Pin
CMOS Inverter Schematic:
Place PMOS and NMOS transistors
Connect to VDD (top) and VSS (bottom)
Add input (VIN) and output (VOUT) pins
CMOS Schematic
Component Properties:
Select components โ Press q โ Configure:
Transistor dimensions (W/L)
Net connections
3. Symbol Creation
Generate Symbol:
Pin Arrangement:
Position
Pin Name
Left
VIN
Right
VOUT
Top
VDD
Bottom
VSS
Adjust Pins
Final Inverter Symbol:
Not symbol
4. Test Schematic Setup
Create Testbench:
Add Components:
Inverter symbol (Instance)
Ground (GND)
Voltage source (VDC)
Configure Voltage Sources:
Component
Property
Value
VDD
Voltage
1.8V
VIN
Voltage
DC variable
VSS
Voltage
0V
5. Simulation with PrimeWave
Launch PrimeWave:
Set Model Files:
Configure Simulation:
Model Section: Select (e.g., FF)
Variables: Copy from Design โ Set VIN=0 (์ค์ ํ์ง ์์ผ๋ฉด simulation์ด ์๋์ฌ ์ ์๋ค)
Simulation Engine: PrimeSim HSPICE
Run Analysis:
Setup โ Analyses
Analysis Type: dc
DC Analysis โ Design Variable
Variable Name, Sweep Type: VIN
Start, Stop, Step Size: e.g., 0, 1.8, 0.01
Run Simulation:
Results:
NOT WaveView
6. Troubleshooting
Schematic Lock Issue:
Delete lock file: *sch.oa.cdslck
Advanced Configuration:
Variable overrides
Simulator options
Key Notes
VIN Initialization: Must be set to 0V for DC sweep
Model Selection: Use correct technology corner (e.g., FF)
Port Connections: Verify VDD/VSS connections in test schematic
This structured guide ensures reproducible CMOS inverter simulation with clear visualization at each step.
-
-
[ex46]
๋ฌธ์ ์ค๋ช
์ ๋ต ์ฝ๋
//stm32f10x_it.c
volatile int Uart1_Rx_In = 0;
volatile int Uart1_Rx_Data = 0;
void USART1_IRQHandler(void)
{
Uart1_Rx_Data = (unsigned char)USART1->DR;
Uart1_Send_Byte(Uart1_Rx_Data);
Uart1_Rx_In = 1;
NVIC_ClearPendingIRQ(37);
}
volatile int note_end = 0;
void TIM2_IRQHandler(void)
{
Macro_Clear_Bit(TIM2->SR, 0);
NVIC_ClearPendingIRQ(28);
note_end = 1;
}
//main.c
#include "device_driver.h"
static void Sys_Init(void)
{
Clock_Init();
LED_Init();
Uart_Init(115200);
Key_Poll_Init();
SCB->VTOR = 0x08003000;
SCB->SHCSR = 0;
}
#define BASE (500) //msec
enum key{C1, C1_, D1, D1_, E1, F1, F1_, G1, G1_, A1, A1_, B1, C2, C2_, D2, D2_, E2, F2, F2_, G2, G2_, A2, A2_, B2};
enum note{N16=BASE/4, N8=BASE/2, N4=BASE, N2=BASE*2, N1=BASE*4};
const int song1[][2] = { {G1,N4},{G1,N4},{E1,N8},{F1,N8},{G1,N4},{A1,N4},{A1,N4},{G1,N2},{G1,N4},{C2,N4},{E2,N4},{D2,N8},{C2,N8},{D2,N2} };
static void Buzzer_Beep(unsigned char tone, int duration)
{
const static unsigned short tone_value[] = {261,277,293,311,329,349,369,391,415,440,466,493,523,554,587,622,659,698,739,783,830,880,932,987};
TIM3_Out_Freq_Generation(tone_value[tone]);
TIM2_Delay(duration);
}
extern volatile int Uart1_Rx_In;
extern volatile int Uart1_Rx_Data;
extern volatile int note_end;
void Main(void)
{
Sys_Init();
TIM4_Out_Init();
TIM3_Out_Init();
Uart1_RX_Interrupt_Enable(1);
static int timer_run = 0;
volatile int i = 0;
Buzzer_Beep(song1[i][0], song1[i][1]);
for(;;)
{
if (Uart1_Rx_In)
{
Uart1_Rx_Data = Uart1_Rx_Data - '0';
if (Uart1_Rx_Data == 0)
{
TIM4_Out_Stop();
timer_run = 0;
}
else
{
if (timer_run == 0)
{
TIM4_Out_PWM_Generation(1000, Uart1_Rx_Data);
timer_run = 1;
}
else
{
TIM4_Change_Duty(Uart1_Rx_Data);
}
}
Uart1_Rx_In = 0;
}
if (note_end)
{
TIM3_Out_Stop();
i++;
if (i >= sizeof(song1)/sizeof(song1[0]))
{
i = 0;
}
Buzzer_Beep(song1[i][0], song1[i][1]);
note_end = 0;
}
}
}
๋ฉ๋ชจ
printf ๋ด๋ถ์ \n ์ต๊ดํ ํ์
-
Manage blog comments with Giscus
Giscus is a free comments system powered without your own database. Giscus uses the Github Discussions to store and load associated comments based on a chosen mapping (URL, pathname, title, etc.).
To comment, visitors must authorize the giscus app to post on their behalf using the GitHub OAuth flow. Alternatively, visitors can comment on the GitHub Discussion directly. You can moderate the comments on GitHub.
Prerequisites
Create a github repo
You need a GitHub repository first. If you gonna use GitHub Pages for hosting your website, you can choose the corresponding repository (i.e., [userID].github.io)
The repository should be public, otherwise visitors will not be able to view the discussion.
Turn on Discussion feature
In your GitHub repository Settings, make sure that General > Features > Discussions feature is enabled.
Activate Giscus API
Follow the steps in Configuration guide. Make sure the verification of your repository is successful.
Then, scroll down from the manual page and choose the Discussion Category options. You donโt need to touch other configs.
Copy _config.yml
Now, you get the giscus script. Copy the four properties marked with a red box as shown below:
Paste those values to _config.yml placed in the root directory.
# External API
giscus_repo: "[ENTER REPO HERE]"
giscus_repoId: "[ENTER REPO ID HERE]"
giscus_category: "[ENTER CATEGORY NAME HERE]"
giscus_categoryId: "[ENTER CATEGORY ID HERE]"
None
ยท 2024-02-03
-
Classic Literature #2: Don Quixote
About the book
Author: Miguel de Cervantes
Original title: El ingenioso hidalgo don Quixote de la Mancha
Country: Spain
Genre: Novel
Publication date:
1605 (Part One)
1615 (Part Two)
Chapter I.
In a village of La Mancha, the name of which I have no desire to call to mind, there lived not long since one of those gentlemen that keep a lance in the lance-rack, an old buckler, a lean hack, and a greyhound for coursing. An olla of rather more beef than mutton, a salad on most nights, scraps on Saturdays, lentils on Fridays, and a pigeon or so extra on Sundays, made away with three-quarters of his income. The rest of it went in a doublet of fine cloth and velvet breeches and shoes to match for holidays, while on week-days he made a brave figure in his best homespun. He had in his house a housekeeper past forty, a niece under twenty, and a lad for the field and market-place, who used to saddle the hack as well as handle the bill-hook. The age of this gentleman of ours was bordering on fifty; he was of a hardy habit, spare, gaunt-featured, a very early riser and a great sportsman. They will have it his surname was Quixada or Quesada (for here there is some difference of opinion among the authors who write on the subject), although from reasonable conjectures it seems plain that he was called Quexana. This, however, is of but little importance to our tale; it will be enough not to stray a hairโs breadth from the truth in the telling of it.
You must know, then, that the above-named gentleman whenever he was at leisure (which was mostly all the year round) gave himself up to reading books of chivalry with such ardour and avidity that he almost entirely neglected the pursuit of his field-sports, and even the management of his property; and to such a pitch did his eagerness and infatuation go that he sold many an acre of tillageland to buy books of chivalry to read, and brought home as many of them as he could get. But of all there were none he liked so well as those of the famous Feliciano de Silvaโs composition, for their lucidity of style and complicated conceits were as pearls in his sight, particularly when in his reading he came upon courtships and cartels, where he often found passages like โthe reason of the unreason with which my reason is afflicted so weakens my reason that with reason I murmur at your beauty;โ or again, โthe high heavens, that of your divinity divinely fortify you with the stars, render you deserving of the desert your greatness deserves.โ Over conceits of this sort the poor gentleman lost his wits, and used to lie awake striving to understand them and worm the meaning out of them; what Aristotle himself could not have made out or extracted had he come to life again for that special purpose. He was not at all easy about the wounds which Don Belianis gave and took, because it seemed to him that, great as were the surgeons who had cured him, he must have had his face and body covered all over with seams and scars. He commended, however, the authorโs way of ending his book with the promise of that interminable adventure, and many a time was he tempted to take up his pen and finish it properly as is there proposed, which no doubt he would have done, and made a successful piece of work of it too, had not greater and more absorbing thoughts prevented him.
Many an argument did he have with the curate of his village (a learned man, and a graduate of Siguenza) as to which had been the better knight, Palmerin of England or Amadis of Gaul. Master Nicholas, the village barber, however, used to say that neither of them came up to the Knight of Phoebus, and that if there was any that could compare with him it was Don Galaor, the brother of Amadis of Gaul, because he had a spirit that was equal to every occasion, and was no finikin knight, nor lachrymose like his brother, while in the matter of valour he was not a whit behind him. In short, he became so absorbed in his books that he spent his nights from sunset to sunrise, and his days from dawn to dark, poring over them; and what with little sleep and much reading his brains got so dry that he lost his wits. His fancy grew full of what he used to read about in his books, enchantments, quarrels, battles, challenges, wounds, wooings, loves, agonies, and all sorts of impossible nonsense; and it so possessed his mind that the whole fabric of invention and fancy he read of was true, that to him no history in the world had more reality in it. He used to say the Cid Ruy Diaz was a very good knight, but that he was not to be compared with the Knight of the Burning Sword who with one back-stroke cut in half two fierce and monstrous giants. He thought more of Bernardo del Carpio because at Roncesvalles he slew Roland in spite of enchantments, availing himself of the artifice of Hercules when he strangled Antaeus the son of Terra in his arms. He approved highly of the giant Morgante, because, although of the giant breed which is always arrogant and ill-conditioned, he alone was affable and well-bred. But above all he admired Reinaldos of Montalban, especially when he saw him sallying forth from his castle and robbing everyone he met, and when beyond the seas he stole that image of Mahomet which, as his history says, was entirely of gold. To have a bout of kicking at that traitor of a Ganelon he would have given his housekeeper, and his niece into the bargain.
In short, his wits being quite gone, he hit upon the strangest notion that ever madman in this world hit upon, and that was that he fancied it was right and requisite, as well for the support of his own honour as for the service of his country, that he should make a knight-errant of himself, roaming the world over in full armour and on horseback in quest of adventures, and putting in practice himself all that he had read of as being the usual practices of knights-errant; righting every kind of wrong, and exposing himself to peril and danger from which, in the issue, he was to reap eternal renown and fame. Already the poor man saw himself crowned by the might of his arm Emperor of Trebizond at least; and so, led away by the intense enjoyment he found in these pleasant fancies, he set himself forthwith to put his scheme into execution.
The first thing he did was to clean up some armour that had belonged to his great-grandfather, and had been for ages lying forgotten in a corner eaten with rust and covered with mildew. He scoured and polished it as best he could, but he perceived one great defect in it, that it had no closed helmet, nothing but a simple morion. This deficiency, however, his ingenuity supplied, for he contrived a kind of half-helmet of pasteboard which, fitted on to the morion, looked like a whole one. It is true that, in order to see if it was strong and fit to stand a cut, he drew his sword and gave it a couple of slashes, the first of which undid in an instant what had taken him a week to do. The ease with which he had knocked it to pieces disconcerted him somewhat, and to guard against that danger he set to work again, fixing bars of iron on the inside until he was satisfied with its strength; and then, not caring to try any more experiments with it, he passed it and adopted it as a helmet of the most perfect construction.
He next proceeded to inspect his hack, which, with more quartos than a real and more blemishes than the steed of Gonela, that โtantum pellis et ossa fuit,โ surpassed in his eyes the Bucephalus of Alexander or the Babieca of the Cid. Four days were spent in thinking what name to give him, because (as he said to himself) it was not right that a horse belonging to a knight so famous, and one with such merits of his own, should be without some distinctive name, and he strove to adapt it so as to indicate what he had been before belonging to a knight-errant, and what he then was; for it was only reasonable that, his master taking a new character, he should take a new name, and that it should be a distinguished and full-sounding one, befitting the new order and calling he was about to follow. And so, after having composed, struck out, rejected, added to, unmade, and remade a multitude of names out of his memory and fancy, he decided upon calling him Rocinante, a name, to his thinking, lofty, sonorous, and significant of his condition as a hack before he became what he now was, the first and foremost of all the hacks in the world.
Having got a name for his horse so much to his taste, he was anxious to get one for himself, and he was eight days more pondering over this point, till at last he made up his mind to call himself โDon Quixote,โ whence, as has been already said, the authors of this veracious history have inferred that his name must have been beyond a doubt Quixada, and not Quesada as others would have it. Recollecting, however, that the valiant Amadis was not content to call himself curtly Amadis and nothing more, but added the name of his kingdom and country to make it famous, and called himself Amadis of Gaul, he, like a good knight, resolved to add on the name of his, and to style himself Don Quixote of La Mancha, whereby, he considered, he described accurately his origin and country, and did honour to it in taking his surname from it.
So then, his armour being furbished, his morion turned into a helmet, his hack christened, and he himself confirmed, he came to the conclusion that nothing more was needed now but to look out for a lady to be in love with; for a knight-errant without love was like a tree without leaves or fruit, or a body without a soul. As he said to himself, โIf, for my sins, or by my good fortune, I come across some giant hereabouts, a common occurrence with knights-errant, and overthrow him in one onslaught, or cleave him asunder to the waist, or, in short, vanquish and subdue him, will it not be well to have some one I may send him to as a present, that he may come in and fall on his knees before my sweet lady, and in a humble, submissive voice say, โI am the giant Caraculiambro, lord of the island of Malindrania, vanquished in single combat by the never sufficiently extolled knight Don Quixote of La Mancha, who has commanded me to present myself before your Grace, that your Highness dispose of me at your pleasureโ?โ Oh, how our good gentleman enjoyed the delivery of this speech, especially when he had thought of some one to call his Lady! There was, so the story goes, in a village near his own a very good-looking farm-girl with whom he had been at one time in love, though, so far as is known, she never knew it nor gave a thought to the matter. Her name was Aldonza Lorenzo, and upon her he thought fit to confer the title of Lady of his Thoughts; and after some search for a name which should not be out of harmony with her own, and should suggest and indicate that of a princess and great lady, he decided upon calling her Dulcinea del Tobosoรขโฌโshe being of El Tobosoรขโฌโa name, to his mind, musical, uncommon, and significant, like all those he had already bestowed upon himself and the things belonging to him.
-
Classic Literature #1: Romeo and Juliet
About the book
Author: William Shakespeare
Country: England
Genre: Shakespearean tragedy
Publication date: 1597
Synopsis
The prologue of Romeo and Juliet calls the title characters โstar-crossed loversโโand the stars do seem to conspire against these young lovers.
Romeo is a Montague, and Juliet a Capulet. Their families are enmeshed in a feud, but the moment they meetโwhen Romeo and his friends attend a party at Julietโs house in disguiseโthe two fall in love and quickly decide that they want to be married.
A friar secretly marries them, hoping to end the feud. Romeo and his companions almost immediately encounter Julietโs cousin Tybalt, who challenges Romeo. When Romeo refuses to fight, Romeoโs friend Mercutio accepts the challenge and is killed. Romeo then kills Tybalt and is banished. He spends that night with Juliet and then leaves for Mantua.
Julietโs father forces her into a marriage with Count Paris. To avoid this marriage, Juliet takes a potion, given her by the friar, that makes her appear dead. The friar will send Romeo word to be at her family tomb when she awakes. The plan goes awry, and Romeo learns instead that she is dead. In the tomb, Romeo kills himself. Juliet wakes, sees his body, and commits suicide. Their deaths appear finally to end the feud.
-
Classic Literature #1: Romeo and Juliet
About the book
Author: William Shakespeare
Country: England
Genre: Shakespearean tragedy
Publication date: 1597
Synopsis
The prologue of Romeo and Juliet calls the title characters โstar-crossed loversโโand the stars do seem to conspire against these young lovers.
Romeo is a Montague, and Juliet a Capulet. Their families are enmeshed in a feud, but the moment they meetโwhen Romeo and his friends attend a party at Julietโs house in disguiseโthe two fall in love and quickly decide that they want to be married.
A friar secretly marries them, hoping to end the feud. Romeo and his companions almost immediately encounter Julietโs cousin Tybalt, who challenges Romeo. When Romeo refuses to fight, Romeoโs friend Mercutio accepts the challenge and is killed. Romeo then kills Tybalt and is banished. He spends that night with Juliet and then leaves for Mantua.
Julietโs father forces her into a marriage with Count Paris. To avoid this marriage, Juliet takes a potion, given her by the friar, that makes her appear dead. The friar will send Romeo word to be at her family tomb when she awakes. The plan goes awry, and Romeo learns instead that she is dead. In the tomb, Romeo kills himself. Juliet wakes, sees his body, and commits suicide. Their deaths appear finally to end the feud.
-
My personal Online Library
What is Lorem Ipsum?
This is an example post โ<โ. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industryโs standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using โContent here, content hereโ, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for โlorem ipsumโ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Where does it come from?
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of โde Finibus Bonorum et Malorumโ (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, โLorem ipsum dolor sit amet..โ, comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from โde Finibus Bonorum et Malorumโ by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
Where can I get some?
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which donโt look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isnโt anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
-
Touch background to close