Skip to content

Commit

Permalink
KerasKorea#74 : add some comment to explain code
Browse files Browse the repository at this point in the history
  • Loading branch information
jhp committed Oct 3, 2018
1 parent 7f75f92 commit eb2fd90
Showing 1 changed file with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,52 @@ def __init__(self):
self.lambda_id, self.lambda_id ],
optimizer=optimizer)
```
> **2. build_generator()**
>
> build_generator() 는 Generator 의 구조를 만듭니다. 이 코드에서는 U-Net 을 Generator 로 사용했습니다.
>
>
> conv2d 는 input image 의 특성을 추출하기 위해서 downsampling 의 용도로 사용합니다. deconv2d 는 이미지의 스타일을 바꿔(translation)주는 용도로 사용합니다.
```python
def build_generator(self):
"""U-Net Generator"""

def conv2d(layer_input, filters, f_size=4):
"""Downsampling 하는 레이어"""
d = Conv2D(filters, kernel_size=f_size, strides=2, padding='same')(layer_input)
d = LeakyReLU(alpha=0.2)(d)
d = InstanceNormalization()(d)
return d

def deconv2d(layer_input, skip_input, filters, f_size=4, dropout_rate=0):
"""Upsampling 하는 레이어"""
u = UpSampling2D(size=2)(layer_input)
u = Conv2D(filters, kernel_size=f_size, strides=1, padding='same', activation='relu')(u)
if dropout_rate:
u = Dropout(dropout_rate)(u)
u = InstanceNormalization()(u)
u = Concatenate()([u, skip_input])
return u

# 이미지 입력. Keras 의 Input 을 사용.
d0 = Input(shape=self.img_shape)

# Downsampling
d1 = conv2d(d0, self.gf)
d2 = conv2d(d1, self.gf*2)
d3 = conv2d(d2, self.gf*4)
d4 = conv2d(d3, self.gf*8)

# Upsampling
u1 = deconv2d(d4, d3, self.gf*4)
u2 = deconv2d(u1, d2, self.gf*2)
u3 = deconv2d(u2, d1, self.gf)

u4 = UpSampling2D(size=2)(u3)
output_img = Conv2D(self.channels, kernel_size=4, strides=1, padding='same', activation='tanh')(u4)

return Model(d0, output_img)
```



### 참고문서
Expand Down

0 comments on commit eb2fd90

Please sign in to comment.