[Deep Learning๐Ÿ‘ฝ] Loss ์ •๋ฆฌ 1๏ธโƒฃ : GAN loss

ํ˜œ๋นˆยท2021๋…„ 2์›” 28์ผ
4

Hyebbb Deep Learning study

๋ชฉ๋ก ๋ณด๊ธฐ
1/2
post-thumbnail

๊ฐ„๋‹จํ•˜๊ฒŒ ๋”ฅ๋Ÿฌ๋‹์„ ํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋Š” Loss ๋ช‡ ๊ฐœ๋ฅผ ์ •๋ฆฌํ•ด ๋ณด๊ณ ์ž ํ•œ๋‹ค.

์ด๋ฒˆ ํฌ์ŠคํŒ…๋ถ€ํ„ฐ loss ํ•˜๋‚˜์”ฉ ์ฐจ๊ทผ์ฐจ๊ทผ ์•Œ์•„๋ณด์ž.


โœ… GAN Loss (Minimax Loss)

GAN(Generative Adversarial Nets)

GAN์€ Generative Adversarial Nets์ด๋‹ค.

์ด ๋…ผ๋ฌธ์—์„œ ์†Œ๊ฐœ๋˜๋Š” adversarial nets ํ”„๋ ˆ์ž„์›Œํฌ์˜ ์ปจ์…‰์€ โ€˜๊ฒฝ์Ÿโ€™์œผ๋กœ, discriminative model(ํŒ๋ณ„์ž)์€ sample data๊ฐ€ generative model(์ƒ์„ฑ์ž)์ด ์ƒ์„ฑํ•ด๋‚ธ sample data์ธ์ง€, ์‹ค์ œ training data distribution์ธ์ง€ ํŒ๋ณ„ํ•˜๋Š” ๊ฒƒ์„ ํ•™์Šตํ•œ๋‹ค.

๊ฒฐ๊ตญ GAN์˜ ํ•ต์‹ฌ ์ปจ์…‰์€ ๊ฐ๊ฐ์˜ ์—ญํ• ์„ ๊ฐ€์ง„ ๋‘ ๋ชจ๋ธ์„ ํ†ตํ•ด ์ ๋Œ€์  ํ•™์Šต์„ ํ•˜๋ฉด์„œ โ€˜์ง„์งœ๊ฐ™์€ ๊ฐ€์งœโ€™๋ฅผ ์ƒ์„ฑํ•ด๋‚ด๋Š” ๋Šฅ๋ ฅ์„ ํ‚ค์›Œ์ฃผ๋Š” ๊ฒƒ.

GAN์„ ์„ค๋ช…ํ•  ๋•Œ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” ์œ„์กฐ์ง€ํ๋ฒ”๊ณผ ๊ฒฝ์ฐฐ๋กœ GAN์„ ๋น„์œ ํ•œ ์ด๋ฏธ์ง€์ด๋‹ค

minimax loss function

GAN์—์„œ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” loss function์€ minimax loss๋กœ, ์‹์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

๊ฐ๊ฐ์˜ ํ•ญ์€ ๋‹ค์Œ์„ ์˜๋ฏธํ•œ๋‹ค.

  • ์ฒซ๋ฒˆ์งธ ํ•ญ: real data x๋ฅผ discriminator ์— ๋„ฃ์—ˆ์„ ๋•Œ ๋‚˜์˜ค๋Š” ๊ฒฐ๊ณผ๋ฅผ log ์ทจํ–ˆ์„ ๋•Œ ์–ป๋Š” ๊ธฐ๋Œ“๊ฐ’
  • ๋‘๋ฒˆ์งธ ํ•ญ: fake data z๋ฅผ generator์— ๋„ฃ์—ˆ์„ ๋•Œ ๋‚˜์˜ค๋Š” ๊ฒฐ๊ณผ๋ฅผ discriminator์— ๋„ฃ์—ˆ์„ ๋•Œ ๊ทธ ๊ฒฐ๊ณผ๋ฅผ log(1-๊ฒฐ๊ณผ)ํ–ˆ์„ ๋•Œ ์–ป๋Š” ๊ธฐ๋Œ“๊ฐ’

์ด ๋ฐฉ์ •์‹์„ Discriminator์˜ ์ž…์žฅ, Generator์˜ ์ž…์žฅ์—์„œ ๊ฐ๊ฐ ์ดํ•ดํ•ด๋ณด์ž. (์•„๋ž˜๋ถ€ํ„ฐ๋Š” ๊ฐ„๋‹จํ•˜๊ฒŒ D,G๋กœ ์นญํ•˜๊ฒ ๋‹ค)

  1. (D์˜ ์ž…์žฅ์—์„œ) ์ด value function V(D,G)์˜ ์ด์ƒ์ ์ธ ๊ฒฐ๊ณผ๋ฅผ ์ƒ๊ฐํ•ด๋ณด์ž.
    D๊ฐ€ ๋งค์šฐ ๋›ฐ์–ด๋‚œ ์„ฑ๋Šฅ์œผ๋กœ ํŒ๋ณ„์„ ์ž˜ ํ•ด๋‚ธ๋‹ค๊ณ  ํ–ˆ์„ ๋•Œ,

    • D๊ฐ€ ํŒ๋ณ„ํ•˜๋ ค๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ์‹ค์ œ ๋ฐ์ดํ„ฐ์—์„œ ์˜จ ์ƒ˜ํ”Œ์ผ ๊ฒฝ์šฐ์—๋Š”, D(x)๊ฐ€ 1์ด ๋˜์–ด ์ฒซ๋ฒˆ์งธ ํ•ญ์€ 0์ด ๋˜์–ด ์‚ฌ๋ผ์ง€๊ณ  G(z)๊ฐ€ ์ƒ์„ฑํ•ด๋‚ธ ๊ฐ€์งœ ์ด๋ฏธ์ง€๋ฅผ ๊ตฌ๋ณ„ํ•ด๋‚ผ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ D(G(z))๋Š” 0์ด ๋˜์–ด ๋‘๋ฒˆ์งธ ํ•ญ์€ log(1-0)=log1=0์ด ๋˜์–ด ์ „์ฒด ์‹ V(D,G) = 0์ด ๋œ๋‹ค.
    • ์ฆ‰ D์˜ ์ž…์žฅ์—์„œ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์ด์ƒ์ ์ธ ๊ฒฐ๊ณผ, '์ตœ๋Œ“๊ฐ’'์€ '0'์ž„์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.
  2. (G์˜ ์ž…์žฅ์—์„œ) ์ด value function V(D,G)์˜ ์ด์ƒ์ ์ธ ๊ฒฐ๊ณผ๋ฅผ ์ƒ๊ฐํ•ด๋ณด์ž.
    G๊ฐ€ D๊ฐ€ ๊ตฌ๋ณ„๋ชปํ• ๋งŒํผ ์ง„์งœ์™€ ๊ฐ™์€ ๋ฐ์ดํ„ฐ๋ฅผ ์ž˜ ์ƒ์„ฑํ•ด๋‚ธ๋‹ค๊ณ  ํ–ˆ์„ ๋•Œ,

    • ์ฒซ๋ฒˆ์งธ ํ•ญ์€ D๊ฐ€ ๊ตฌ๋ณ„ํ•ด๋‚ด๋Š” ๊ฒƒ์— ๋Œ€ํ•œ ํ•ญ์œผ๋กœ G์˜ ์„ฑ๋Šฅ์— ์˜ํ•ด ๊ฒฐ์ •๋  ์ˆ˜ ์žˆ๋Š” ํ•ญ์ด ์•„๋‹ˆ๋ฏ€๋กœ ๋ฌด์‹œํ•˜๊ณ 
    • ๋‘๋ฒˆ์งธ ํ•ญ์—์„œ๋Š” G๊ฐ€ ์ƒ์„ฑํ•ด๋‚ธ ๋ฐ์ดํ„ฐ๋Š” D๋ฅผ ์†์ผ ์ˆ˜ ์žˆ๋Š” ์„ฑ๋Šฅ์ด๋ผ ๊ฐ€์ •ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— D๊ฐ€ G๊ฐ€ ์ƒ์„ฑํ•ด๋‚ธ ์ด๋ฏธ์ง€๋ฅผ ๊ฐ€์งœ๋ผ๊ณ  ์ธ์‹ํ•˜์ง€ ๋ชปํ•˜๊ณ  ์ง„์งœ๋ผ๊ณ  ๊ฒฐ์ •๋‚ด๋ฒ„๋ฆฐ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ D(G(z)) =1์ด ๋˜๊ณ  log(1-1) = log0 = -โˆž ๊ฐ€ ๋œ๋‹ค.
    • ์ฆ‰, G์˜ ์ž…์žฅ์—์„œ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์ด์ƒ์ ์ธ ๊ฒฐ๊ณผ, '์ตœ์†Ÿ๊ฐ’'์€ '-โˆž'์ž„์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

๋‹ค์‹œ๋งํ•ด,

  • D๋Š” training data์˜ sample๊ณผ G์˜ sampl์— ์ง„์งœ์ธ์ง€ ๊ฐ€์งœ์ธ์ง€ ์˜ฌ๋ฐ”๋ฅธ ๋ผ๋ฒจ์„ ์ง€์ •ํ•  ํ™•๋ฅ ์„ ์ตœ๋Œ€ํ™”ํ•˜๊ธฐ ์œ„ํ•ด ํ•™์Šตํ•˜๊ณ , (V(D,G) ์ตœ๋Œ€ํ™”)

๐ŸŒŸ ์ด ๋•Œ ํŒ๋ณ„์ž D๋Š” real or fake๋ฅผ ํŒ๋‹จํ•˜๋ฏ€๋กœ, Binary Cross Entropy loss๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค) ๐ŸŒŸ

  • G๋Š” log(1-D(G(z))๋ฅผ ์ตœ์†Œํ™”(D(G(z))๋ฅผ ์ตœ๋Œ€ํ™”)ํ•˜๊ธฐ ์œ„ํ•ด ํ•™์Šต๋˜๋„๋กํ•˜๋Š” ๊ฒƒ์ด (V(D,G) ์ตœ์†Œํ™”)

GAN๊ณผ minimax loss function์˜ ํ•ต์‹ฌ์ด๋‹ค.

(์•ฝ 1๋…„์ „ ๋™์•„๋ฆฌ ๊ณผ์ œ๋กœ ์ด ๋…ผ๋ฌธ์„ ๋ฆฌ๋ทฐํ•œ ์ ์ด ์žˆ์–ด ๊ด€๋ จ ๋งํฌ๋ฅผ ์ฒจ๋ถ€ํ•œ๋‹ค ์ด ๋ฆฌ๋ทฐ๋ฅผ ๋‹ค์‹œ ๋ณด๋ฉฐ ๊ธฐ์–ต์„ ๋˜์‚ด๋ฆฌ๋ฉฐ loss๋ฅผ ์ •๋ฆฌํ–ˆ๋‹ค)

โ‡’ GAN paper review


์—ฌ๋Ÿฌ loss๋“ค์ด ์žˆ์ง€๋งŒ, ์•„๋ฌด ์ƒ๊ฐ ์—†์ด ์ •์˜ํ•ด์„œ ์‚ฌ์šฉํ–ˆ๋˜ loss๋“ค์ด ๋งŽ์€ ๊ฒƒ ๊ฐ™์•„ ์ •๋ฆฌ๋ฅผ ์‹œ์ž‘ํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค. (์‚ฌ์‹ค ๋”ฅ๋Ÿฌ๋‹ ๋ชจ๋ธ์—์„œ ์ค‘์š”ํ•œ๊ฑด loss function์ธ๋ฐ ๋ง์•ผ,,) SRGAN์—์„œ ์‚ฌ์šฉํ•˜๋Š” VGG loss, ๊ทธ๋ฆฌ๊ณ  GAN์—์„œ ํŒ๋ณ„์ž๊ฐ€ binary cross entropy loss๋ฅผ ์‚ฌ์šฉํ•จ์œผ๋กœ์จ ๋ฐœ์ƒํ•˜๋Š” ๋ช‡ ๋ฌธ์ œ๋“ค์„ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์ œ์‹œํ•œ WGAN loss ๋“ฑ๋“ฑ ๋‹ค๋ฅธ loss๋“ค์„ ์•ž์œผ๋กœ ์ •๋ฆฌํ•ด ๋ณด๊ณ ์ž ํ•œ๋‹ค.

๋`(>๏น<)โ€ฒ

profile
(โยดโ—ก`โ)

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 7์›” 13์ผ

์•ˆ๋…•ํ•˜์„ธ์š” GAN ๋ชจ๋ธ ๊ด€๋ จํ•ด์„œ ๊ธ€์„ ์“ฐ๋‹ค๊ฐ€ ์„ค๋ช…์ด ์ž˜๋˜์–ด์žˆ๋Š” ์ž‘์„ฑ์ž๋‹˜์˜ ๊ธ€์„ ๋ณด๊ณ  ์ œ๋Œ€๋กœ ์ดํ•ดํ•˜์—ฌ ์ œ ๊ธ€์— ๋น„์Šทํ•œ ๋ฐฉ์‹์˜ ์„ค๋ช…์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค. ํ˜น์‹œ๋‚˜ ๋‚ด์šฉ ์ˆ˜์ •์„ ์›ํ•˜์‹ ๋‹ค๋ฉด ์ œ ๊ธ€์— ๋Œ“๊ธ€๋กœ ๋‹ฌ์•„์ฃผ์‹œ๋ฉด ์ˆ˜์ •ํ† ๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
https://velog.io/@hsysfan/Defect-GAN-High-Fidelity-Defect-Synthesis-for-Automated-Defect-Inspection-%EB%85%BC%EB%AC%B8-%EB%A6%AC%EB%B7%B0

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ