Skip to content

a project to improve camera image quality using AI

Notifications You must be signed in to change notification settings

ilovemyminutes/image-reconstruction

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒŸ์นด๋ฉ”๋ผ ์ด๋ฏธ์ง€ ํ’ˆ์งˆ ํ–ฅ์ƒ AI ๊ฒฝ์ง„๋Œ€ํšŒ

Contents


๐ŸงTask Description

Subject

๋ณธ ๋Œ€ํšŒ์˜ ์ฃผ์ œ๋Š” ๋น› ๋ฒˆ์ง์œผ๋กœ ์ €ํ•˜๋œ ์นด๋ฉ”๋ผ ์ด๋ฏธ์ง€ ํ’ˆ์งˆ์„ ํ–ฅ์ƒ์‹œํ‚ค๋Š” AI ๋ชจ๋ธ ๊ฐœ๋ฐœ์ด์—ˆ์Šต๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ์ด๋ฏธ์ง€๋Š” ์•„๋ž˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ๋น›๋ฒˆ์ง, ๋ธ”๋Ÿฌ ํ˜„์ƒ ๋“ฑ์„ ํฌํ•จํ•˜์—ฌ ๋ณตํ•ฉ์ ์ธ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ํ•„์š”๊ฐ€ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

Data

  • ํ•™์Šต ๋ฐ์ดํ„ฐ: 272์žฅ์˜ 2448ร—3264, 350์žฅ์˜ 1224ร—1632 ์ด๋ฏธ์ง€๋กœ ๊ตฌ์„ฑ๋œ 622์žฅ์˜ ๋น›๋ฒˆ์ง ์ด๋ฏธ์ง€
  • ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ: 20์žฅ์˜ 2448ร—3264 ๋น›๋ฒˆ์ง ์ด๋ฏธ์ง€

Metric

  • PSNR(Peak Signal-to-noise ratio): ์‹ ํ˜ธ๊ฐ€ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€ ์ „๋ ฅ์— ๋Œ€ํ•œ ์žก์Œ์˜ ์ „๋ ฅ์„ ๋‚˜ํƒ€๋‚ธ ๊ฒƒ์œผ๋กœ, ์˜์ƒ ๋˜๋Š” ๋™์˜์ƒ ์†์‹ค ์••์ถ•์—์„œ ํ™”์งˆ ์†์‹ค ์ •๋ณด๋ฅผ ํ‰๊ฐ€ํ• ๋•Œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.


โš™Installation

Preparation

# clone repository
$ git clone https://github.com/TeamBCP5/image-reconstruction.git

# install necessary tools
$ pip install -r requirements.txt

Data Structure

# Download: https://dacon.io/competitions/official/235746/data
[camera_dataset]/
โ”œโ”€โ”€ train_input_img/ # ํ•™์Šต ๋ฐ์ดํ„ฐ ์ž…๋ ฅ ์ด๋ฏธ์ง€
โ”œโ”€โ”€ train_label_img/
โ”œโ”€โ”€ hinet_dataset/ # postprocessing ๋ฐ์ดํ„ฐ์…‹ ๋””๋ ‰ํ† ๋ฆฌ NOTE. ํ•™์Šต ๊ณผ์ • ์ค‘ ๊ตฌ์ถ•๋˜๋Š” ๋””๋ ‰ํ† ๋ฆฌ์ž…๋‹ˆ๋‹ค.
โ”‚     โ”œโ”€โ”€ train_input_img/
โ”‚     โ””โ”€โ”€ train_label_img/
โ””โ”€โ”€ test_input_img/

Code Structure

[code]
โ”œโ”€โ”€ camera_dataset/ # ๋ฐ์ดํ„ฐ์…‹ ๋””๋ ‰ํ† ๋ฆฌ
โ”œโ”€โ”€ configs/ # ๋ชจ๋ธ config ํŒŒ์ผ ๋””๋ ‰ํ† ๋ฆฌ
โ”œโ”€โ”€ data/ # data ์ฒ˜๋ฆฌ ๊ด€๋ จ ๋ชจ๋“ˆ ๋””๋ ‰ํ† ๋ฆฌ
โ”œโ”€โ”€ networks/ # ๋ชจ๋ธ ์•„ํ‚คํ…์ฒ˜ ๊ด€๋ จ ๋ชจ๋“ˆ ๋””๋ ‰ํ† ๋ฆฌ
โ”œโ”€โ”€ train_modules/ # ๋ชจ๋ธ ํ•™์Šต ๊ด€๋ จ ๋ชจ๋“ˆ ๋””๋ ‰ํ† ๋ฆฌ
โ”œโ”€โ”€ utils/ # ์œ ํ‹ธ๋ฆฌํ‹ฐ ๊ด€๋ จ ๋ชจ๋“ˆ ๋””๋ ‰ํ† ๋ฆฌ
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ demo_augmentations.py # Augmentation ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ
โ”œโ”€โ”€ demo_preprocessing.py # Preprocessing ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ
โ”œโ”€โ”€ train.py
โ””โ”€โ”€ inference.py

๐Ÿ•นCommand Line Interface

์นด๋ฉ”๋ผ ์ด๋ฏธ์ง€ ํ™”์งˆ ๊ฐœ์„  ๊ณผ์ •์€ ๋Œ€๋žต ๋‹ค์Œ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. Sliding Window ๊ธฐ๋ฐ˜์˜ Pix2Pix ๋ชจ๋ธ์„ ํ†ตํ•ด 1์ฐจ์ ์œผ๋กœ ๋น›๋ฒˆ์ง์„ ์ œ๊ฑฐํ•œ ๋’ค, HINet ๋ชจ๋ธ์„ ํ†ตํ•ด ๊ฒฉ์ž ๋ฌด๋Šฌ ๋“ฑ ์†์ƒ๋œ ํ™”์งˆ์„ ๋ณด์™„ํ•ฉ๋‹ˆ๋‹ค. ํŠนํžˆ, ํ•™์Šต ๋‹จ๊ณ„์—์„œ Pix2Pix Generator๋Š” Discriminator์™€ ํ•จ๊ป˜ ํ•™์Šต๋ฉ๋‹ˆ๋‹ค.

Configurations

๋ชจ๋ธ ํ•™์Šต๊ณผ ์ถ”๋ก ์€ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ชจ๋ธ๋ณ„ Configuration ํŒŒ์ผ์„ ๋ฐ”ํƒ•์œผ๋กœ ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค. ๊ฐ Configuration ํŒŒ์ผ์—๋Š” ๋ชจ๋ธ ๊ตฌ์กฐ์™€ ํ•™์Šต ๋ฐ์ดํ„ฐ์…‹ ๊ฒฝ๋กœ ๋“ฑ ํ•™์Šต๊ณผ ์ถ”๋ก ์„ ์œ„ํ•œ ์„ค์ •๊ฐ’์ด ๊ธฐ๋ก๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์›ํ™œํ•œ ํ•™์Šต/์ถ”๋ก ์„ ์œ„ํ•ด์„œ๋Š” ๋ฐ์ดํ„ฐ์…‹ ๊ฒฝ๋กœ ๋“ฑ ์„ค์ •๊ฐ’์„ ํ™˜๊ฒฝ์— ๋งž๊ฒŒ ์„ค์ •ํ•ด์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค. Configuration ํŒŒ์ผ ๋ช…์„ธ๋Š” ์ด๊ณณ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Train

์ตœ์ข… ๊ฒฐ๊ณผ๋ฌผ ์ œ์ถœ์— ํ™œ์šฉ๋œ ๋ชจ๋ธ์€ ๋‹ค์Œ์˜ 3๋‹จ๊ณ„์— ๊ฑธ์นœ ํ•™์Šต์„ ํ†ตํ•ด ์ œ์ž‘๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

I. ๋ฉ”์ธ ๋ชจ๋ธ(Pix2Pix) ํ•™์Šต

  • Sliding Window ๋ฐฉ๋ฒ•์„ ๋ฐ”ํƒ•์œผ๋กœ ์ด๋ฏธ์ง€ ํ’ˆ์งˆ์„ ํ–ฅ์ƒ์‹œํ‚ค๋Š” ๋ฉ”์ธ ๋ชจ๋ธ(Pix2Pix)์„ ํ•™์Šตํ•ฉ๋‹ˆ๋‹ค.
  • Input. ๋Œ€ํšŒ์—์„œ ์ฃผ์–ด์ง„ ํ•™์Šต ๋ฐ์ดํ„ฐ์˜ input ์ด๋ฏธ์ง€
  • Label. ๋Œ€ํšŒ์—์„œ ์ฃผ์–ด์ง„ ํ•™์Šต ๋ฐ์ดํ„ฐ์˜ label ์ด๋ฏธ์ง€

II. ํ›„์ฒ˜๋ฆฌ ๋ชจ๋ธ(HINet) 1์ฐจ ํ•™์Šต

  • ํ›„์ฒ˜๋ฆฌ ๋ชจ๋ธ(HINet)์„ ์ฃผ์–ด์ง„ ๋ฐ์ดํ„ฐ๋ฅผ ํ™œ์šฉํ•˜์—ฌ 1์ฐจ์ ์œผ๋กœ ํ•™์Šตํ•ฉ๋‹ˆ๋‹ค.
  • Input. ๋Œ€ํšŒ์—์„œ ์ฃผ์–ด์ง„ ํ•™์Šต ๋ฐ์ดํ„ฐ์˜ input ์ด๋ฏธ์ง€
  • Label. ๋Œ€ํšŒ์—์„œ ์ฃผ์–ด์ง„ ํ•™์Šต ๋ฐ์ดํ„ฐ์˜ label ์ด๋ฏธ์ง€

III. ํ›„์ฒ˜๋ฆฌ ๋ชจ๋ธ(HINet) 2์ฐจ ํ•™์Šต

  • II์—์„œ ํ•™์Šตํ•œ ํ›„์ฒ˜๋ฆฌ ๋ชจ๋ธ(HINet)์„ ๋ถˆ๋Ÿฌ์™€ ํ•™์Šต์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  • Input. ๋Œ€ํšŒ์—์„œ ์ฃผ์–ด์ง„ ํ•™์Šต ๋ฐ์ดํ„ฐ์˜ input ์ด๋ฏธ์ง€์— ๋Œ€ํ•œ I์—์„œ ํ•™์Šตํ•œ ๋ฉ”์ธ ๋ชจ๋ธ(Pix2Pix)์˜ ์ถ”๋ก  ๊ฒฐ๊ณผ
  • Label. ๋Œ€ํšŒ์—์„œ ์ฃผ์–ด์ง„ ํ•™์Šต ๋ฐ์ดํ„ฐ์˜ label ์ด๋ฏธ์ง€

Train All Pipeline

์œ„ ํ•™์Šต ๋‹จ๊ณ„๋ฅผ ๋ชจ๋‘ ํฌํ•จํ•œ ํ•™์Šต์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

$ python train.py --train_type 'all'

Train Pix2Pix in single

๋‹จ๊ณ„ I์— ํ•ด๋‹น๋˜๋Š” Pix2Pix ๋ชจ๋ธ ํ•™์Šต์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

$ python train.py --train_type 'pix2pix'

Train HINet in single

๋‹จ๊ณ„ II์— ํ•ด๋‹น๋˜๋Š” HINet ๋ชจ๋ธ ํ•™์Šต์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

$ python train.py --train_type 'hinet'

Arguments

train_type: ํ•™์Šต ๋ฐฉ์‹ ์„ค์ •

  • 'all': ์œ„ ์„ธ ๋‹จ๊ณ„์— ๊ฑธ์นœ ํ•™์Šต์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ์ตœ์ข… ๊ฒฐ๊ณผ๋ฌผ ์žฌํ˜„์—๋Š” ์ด ์„ค์ •๊ฐ’์„ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
  • 'pix2pix': Pix2Pix ๋ชจ๋ธ์˜ ๊ฐœ๋ณ„ ํ•™์Šต์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  • 'hinet': HINet ๋ชจ๋ธ์˜ ๊ฐœ๋ณ„ ํ•™์Šต์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. '๋‹จ๊ณ„ II. ํ›„์ฒ˜๋ฆฌ ๋ชจ๋ธ(HINet) 1์ฐจ ํ•™์Šต'์„ ๊ธฐ์ค€์œผ๋กœ ํ•™์Šต์ด ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค.

config_pix2pix: Pix2Pix ๋ชจ๋ธ configuration ํŒŒ์ผ ๊ฒฝ๋กœ

config_hinet_phase1: HINet ๋ชจ๋ธ(phase1) configuration ํŒŒ์ผ ๊ฒฝ๋กœ

config_hinet_phase2: HINet ๋ชจ๋ธ(phase2) configuration ํŒŒ์ผ ๊ฒฝ๋กœ

Inference

๋ฉ”์ธ ๋ชจ๋ธ(Pix2Pix)๊ณผ ํ›„์ฒ˜๋ฆฌ ๋ชจ๋ธ(HINet)์„ ๋ถˆ๋Ÿฌ์™€ ์ถ”๋ก ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ์ถ”๋ก ์€ ๋‹ค์Œ์˜ ๋‘ ๋‹จ๊ณ„๋ฅผ ๊ฑฐ์ณ ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค.

$ python inference.py --checkpoint_main "./best_models/pix2pix.pth" --checkpoint_post "./best_models/hinet.pth" --image_dir "./camera_dataset/test_input_img"

I. ๋ฉ”์ธ ๋ชจ๋ธ(Pix2Pix) ์ถ”๋ก 

  • Input. ๋Œ€ํšŒ์—์„œ ์ฃผ์–ด์ง„ ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ์˜ input ์ด๋ฏธ์ง€

II. ํ›„์ฒ˜๋ฆฌ ๋ชจ๋ธ(HINet) 1์ฐจ ํ•™์Šต

  • Input. ๋‹จ๊ณ„ I์—์„œ ๋ฉ”์ธ ๋ชจ๋ธ์˜ ์ถ”๋ก  ๊ฒฐ๊ณผ
  • ํ•ด๋‹น ๋‹จ๊ณ„์—์„œ์˜ ๊ฒฐ๊ณผ๋ฌผ์ด ์ตœ์ข… ์ถ”๋ก  ๊ฒฐ๊ณผ๋ฌผ๋กœ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.

Arguments

config_main: Main ๋ชจ๋ธ(Pix2Pix) config ํŒŒ์ผ ๊ฒฝ๋กœ

config_post: Postprocessing ๋ชจ๋ธ(HINet) config ํŒŒ์ผ ๊ฒฝ๋กœ

checkpoint_main: ํ•™์Šตํ•œ main ๋ชจ๋ธ(Pix2Pix)์˜ pth ํŒŒ์ผ ๊ฒฝ๋กœ

checkpoint_post: ํ•™์Šตํ•œ postprocessing ๋ชจ๋ธ(HINet)์˜ pth ํŒŒ์ผ ๊ฒฝ๋กœ

image_dir: ์ถ”๋ก  ์‹œ ์‚ฌ์šฉ๋  ๋ฐ์ดํ„ฐ ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ

patch_size: ์ถ”๋ก  ์‹œ ์‚ฌ์šฉ๋  ์ด๋ฏธ์ง€ patch์˜ ํฌ๊ธฐ

stride: ์ถ”๋ก  ์‹œ ์‚ฌ์šฉ๋  stride์˜ ํฌ๊ธฐ

batch_size: ์ถ”๋ก  ์‹œ ์‚ฌ์šฉ๋  batch์˜ ํฌ๊ธฐ

output_dir: ์ถ”๋ก  ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•  ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ. ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ ๋‚ด ์••์ถ•ํŒŒ์ผ ํ˜•ํƒœ๋กœ ๊ฒฐ๊ณผ๋ฌผ์ด ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.

Demo Augmentation

๋ชจ๋ธ ํ•™์Šต์— ํ™œ์šฉํ•œ data augmentation์˜ ์˜ˆ์‹œ ๊ฒฐ๊ณผ๋ฌผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

$ python demo_augmentation.py --data_dir "./camera_dataset/" --num_samples 10 --save_dir './sample_augmentation/'

Outputs

[SAVE_DIR]
โ”œโ”€โ”€ original/ # ์›๋ณธ ์ด๋ฏธ์ง€
โ”œโ”€โ”€ hinet/ # HINet์„ ์œ„ํ•œ data augmentation ๊ฒฐ๊ณผ๋ฌผ
โ””โ”€โ”€ pix2pix/ # pix2pix๋ฅผ ์œ„ํ•œ data augmentation ๊ฒฐ๊ณผ๋ฌผ

Arguments

data_dir: input ๋ฐ์ดํ„ฐ ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ

num_samples: ์ƒ์„ฑํ•  ์ƒ˜ํ”Œ ์ˆ˜

save_dir: Augmentation ์ ์šฉ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•  ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ

Demo Preprocessing

๋ชจ๋ธ ํ•™์Šต์— ํ™œ์šฉํ•œ data preprocessing์˜ ์˜ˆ์‹œ ๊ฒฐ๊ณผ๋ฌผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

$ python demo_preprocessing.py --data_dir "./camera_dataset/" --num_samples 10 --save_dir './sample_preprocessing/'

Outputs

[SAVE_DIR]
โ”œโ”€โ”€ original/ # ์›๋ณธ ์ด๋ฏธ์ง€
โ”œโ”€โ”€ hinet/ # HINet์„ ์œ„ํ•œ data preprocessing ๊ฒฐ๊ณผ๋ฌผ
โ””โ”€โ”€ pix2pix/ # pix2pix๋ฅผ ์œ„ํ•œ data preprocessing ๊ฒฐ๊ณผ๋ฌผ

Arguments

data_dir: input ๋ฐ์ดํ„ฐ ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ

num_samples: ์ƒ์„ฑํ•  ์ƒ˜ํ”Œ ์ˆ˜

save_dir: Augmentation ์ ์šฉ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•  ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ

stride: Sliding Window ์‹œ ์‚ฌ์šฉํ•  stride

patch_size: Sliding Window ์‹œ ์‚ฌ์šฉํ•  patch ์‚ฌ์ด์ฆˆ

About

a project to improve camera image quality using AI

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%