๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Deep Learning/2023 DL ๊ธฐ์ดˆ ์ด๋ก  ๊ณต๋ถ€

[๋ชจ๋‘๋ฅผ ์œ„ํ•œ ๋”ฅ๋Ÿฌ๋‹ ์‹œ์ฆŒ 2] lab-01-1~08-2

by ์ œ๋ฃฝ 2023. 7. 9.
728x90
๋ฐ˜์‘ํ˜•

 

lab-01-1~08-2
01-1~2 Tensor Manipulation 1~2
  • 1์ฐจ์›: ๋ฒกํ„ฐ
  • 2์ฐจ์›: ํ–‰๋ ฌ
  • 3์ฐจ์›: ํ…์„œ(๋ฐฐ์—ด์„ ์˜๋ฏธ)
  • 4์ฐจ์›: ํ…์„œ๋ฅผ ์œ„๋กœ ์Œ“์€ ๊ฒƒ
  • 5์ฐจ์›: ํ…์„œ๋ฅผ ์˜†์œผ๋กœ ์Œ“์€ ๊ฒƒ
  • 6์ฐจ์›: 5์ฐจ์›์„ ๋’ค๋กœ ์Œ“์€ ๊ฒƒ
  • batch size=64
  • dim=256
  • *๊ฐ€์žฅ ์ „ํ˜•์ ์ธ 2์ฐจ์› ํ…์„œ

๊ฐ€๋กœ: ๋„ˆ๋น„(width) ์„ธ๋กœ: ๋†’์ด(height)

length: ๋ฌธ์žฅ๊ธธ์ด dim: ๋‹จ์–ด ๋ฒกํ„ฐ์˜ ์ฐจ์› ex)['๋‚˜๋Š” ์‚ฌ๊ณผ๋ฅผ ์ข‹์•„ํ•ด'] ๋ฌธ์žฅ๊ธธ์ด(length=3) '๋‚˜๋Š”'=[0.1,0.2,0.9] '์‚ฌ๊ณผ๋ฅผ'=[0.3,0.5,0.1] '์ข‹์•„ํ•ด'=[0.5,0.6,0.7] => [[0.1,0.2,0.9], [0.3,0.5,0.1], [0.5,0.6,0.7]]

ํŒŒ์ดํ† ์น˜์˜ ๊ฒฝ์šฐ, ์ž๋™์ ์œผ๋กœ ํ–‰๋ ฌ ์ฐจ์›์˜ ์‚ฌ์ด์ฆˆ๋ฅผ ๋งž์ถฐ์ค€๋‹ค. (Broadcasting) ๋”ฐ๋ผ์„œ ํฌ๊ธฐ์™€ ๋‹ค๋ฅธ ๋ฒกํ„ฐ๋ผ๋ฆฌ๋„ ์—ฐ์‚ฐ์ด ๊ฐ€๋Šฅ.

.A.matmul(B): Aํ–‰๋ ฌ๊ณผ Bํ–‰๋ ฌ์˜ ํ–‰๋ ฌ๊ณฑ, ์ฐจ์›์ด ๊ฐ™์•„์•ผํ•จ A.mul(B): A ํ…์„œ์™€ Bํ…์„œ์˜ ์›์†Œ๋ณ„ ๊ณฑ์…ˆ ์—ฐ์‚ฐ, ๋ธŒ๋กœ๋“œ์บ์ŠคํŒ… ๊ธฐ๋Šฅ ์ œ๊ณต

mean(dim): ํ•ด๋‹น ์ฐจ์›(dim)์„ ์ œ๊ฑฐํ•ด์„œ ํ‰๊ท  ์ถœ๋ ฅ dim=0 ์˜ ์˜๋ฏธ: ์ฒซ๋ฒˆ์งธ ์ฐจ์›=ํ–‰ ์„ ์ง€์›Œ๋ผ (์—ด๋งŒ ๋‚จ๊ฒจ๋ผ) dim=1 ์˜ ์˜๋ฏธ: ์—ด์„ ์ง€์›Œ๋ผ(ํ–‰๋งŒ ๋‚จ๊ฒจ๋ผ)

sum(dim): ํ•ด๋‹น์ฐจ์›์„ ์ œ๊ฑฐํ•ด์„œ ํ•ฉ๊ณ„ ์ถœ๋ ฅ

max(dim): ํ•ด๋‹น์ฐจ์›์„ ์ œ๊ฑฐํ•ด์„œ ์›์†Œ์˜ ์ตœ๋Œ“๊ฐ’๊ณผ ์ธ๋ฑ์Šค ๋ฆฌํ„ด

torch.Tensor.view(์›ํ•˜๋Š”ํฌ๊ธฐ): ํ…์„œ ์•ˆ์˜ ์›์†Œ ๊ฐœ์ˆ˜๋Š” ์œ ์ง€ but, ํ…์„œ์˜ ํฌ๊ธฐ๋ฅผ ๋ณ€๊ฒฝ -1๋กœ ์„ค์ •ํ•  ์‹œ, ์•Œ์•„์„œ ๊ณ„์‚ฐํ•ด์คŒ

squeeze(): ์ฐจ์›์ด 1์ธ ์ฐจ์› ์ œ๊ฑฐ unsqueeze(dim): dim์ด 1์ธ ๊ฒฝ์šฐ ํ•ด๋‹น ์ฐจ์› ์ œ๊ฑฐ

unsqueeze(dim): dim์— 1์ธ์ฐจ์› ์ถ”๊ฐ€ ex) unsqueeze(0): ํ–‰ ์ž๋ฆฌ์— 1์„ ๋„ฃ์–ด์ค˜

์ž๋ฃŒํ˜• ๋ณ€ํ™˜= Type Casting

ํ•ด๋‹น ์ฐจ์›์— ์•Œ๋งž๊ฒŒ ์ด์–ด ๋ถ™์—ฌ์คŒ

stack์ด ๋” ๋งŽ์€ ์—ฐ์‚ฐ์„ ๋‚ดํฌํ•ด concat๋ณด๋‹ค ๋” ํŽธ๋ฆฌ ** concat vs stack: ํ…์„œ๋“ค์„ ๋‹จ์ˆœํžˆ ์ด์–ด๋ถ™์ž„ ํ…์„œ ๊ทธ๋Œ€๋กœ ์Œ“์Œ

 

ones_like(x): 1๋กœ ์ฑ„์›Œ์ง„ ํ…์„œ ์ƒ์„ฑ zeros_like(x): 0์œผ๋กœ ์ฑ„์›Œ์ง„ ํ…์„œ ์ƒ์„ฑ

์—ฐ์‚ฐ ๋’ค์— _: ๊ธฐ์กด ํ…์„œ์— ๋„ฃ์Œ(์—…๋ฐ์ดํŠธ)

08-1~08-2 Perceptron / Multi Layer Perceptron

AND: ๋‘˜๋‹ค 1์ด์–ด์•ผ 1๋กœ OR: ๋‘˜ ์ค‘ 1๊ฐœ๋งŒ 1์ด๋ฉด 1๋กœ

์„œ๋กœ ๋‹ค๋ฅธ ์ž…๋ ฅ์ด ๋“ค์–ด์˜ฌ ๊ฒฝ์šฐ 1 ๊ฐ™์€ ์ž…๋ ฅ์ผ ๊ฒฝ์šฐ 0 => linear๋กœ ๊ตฌ๋ถ„ํ•˜์ง€ ๋ชปํ•จ => ์•”ํ‘๊ธฐ ๋Œ์ž…

 

์ด์— ๋Œ€ํ•ด ์—ฌ๋Ÿฌ ์ธต์ด ์ƒ๊ธฐ๋Š” MLP(multi layer perceptron)์ด ๋“ฑ์žฅํ•˜๊ฒŒ ๋จ.

๊ณ„์‚ฐ ๊ฒฐ๊ณผ์™€ ์ •๋‹ต์˜ ์˜ค์ฐจ๋ฅผ ๊ตฌํ•จ => ์˜ค์ฐจ์— ๊ด€์—ฌํ•˜๋Š” ๊ฐ’๋“ค์˜ ๊ฐ€์ค‘์น˜๋ฅผ ์ˆ˜์ •=> ์˜ค์ฐจ๊ฐ€ ์ž‘์•„์ง€๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ์ผ์ • ํšŸ์ˆ˜๋ฅผ ๋ฐ˜๋ณตํ•ด ์ˆ˜์ •ํ•˜๋Š” ๋ฐฉ๋ฒ• => ๋ฐ‘์‹œ๋”ฅ chap5 ์ข€ ๋” ๊ณต๋ถ€ํ•ด์•ผ

 

 

 

 

 

 

 

 


728x90
๋ฐ˜์‘ํ˜•