이어서 확장 경로, U-Net 모델을 완성해보겠습니다.
up_stack = [
pix2pix.upsample(512, 3), # 4x4 -> 8x8
pix2pix.upsample(256, 3), # 8x8 -> 16x16
pix2pix.upsample(128, 3), # 16x16 -> 32x32
pix2pix.upsample(64, 3), # 32x32 -> 64x64
] # ①
def U-NET_model(output_channels:int): # ②
inputs = tf.keras.layers.Input(shape=[128, 128, 3])
skips = down_stack(inputs)
x = skips[-1] # ③
skips = reversed(skips[:-1])
for up, skip in zip(up_stack, skips):
x = up(x)
concat = tf.keras.layers.Concatenate()
x = concat([x, skip])
last = tf.keras.layers.Conv2DTranspose(
filters=output_channels, kernel_size=3, strides=2, padding='same') # ④
# 64x64 -> 128x128
x = last(x)