[TensorFlow] UpSampling2D 레이어 예제

tf.keras.layers.UpSampling2D 레이어는 이미지나 특성 맵의 크기를 확대하는 데 사용됩니다. 이를 통해 더 높은 해상도로 정보를 복원하거나, 이미지 생성 작업에서 사용될 수 있습니다. 아래는 tf.keras.layers.UpSampling2D 레이어를 사용한 예제입니다.

import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import UpSampling2D, Conv2D, Input

## 더미 이미지 데이터 생성
dummy_input = tf.random.normal(shape=(4, 8, 8, 3))  # 4개의 이미지, 각 이미지 크기: 8x8, 채널 개수: 3

## UpSampling2D 레이어 정의
upsample_layer = UpSampling2D(size=(2, 2))

## UpSampling2D 레이어 실행
upsampled_data = upsample_layer(dummy_input)

print("Input shape:", dummy_input.shape)
print("Upsampled data shape:", upsampled_data.shape)` 

위 예제에서는 tf.keras.layers.UpSampling2D 레이어를 사용하여 4개의 이미지에 대한 레이어를 정의하고 실행합니다. size 매개변수로 확대할 크기를 지정합니다.

실행 결과 예시:

Input shape: (4, 8, 8, 3)
Upsampled data shape: (4, 16, 16, 3)` 

위에서 확인할 수 있듯이, 입력 데이터의 공간 차원이 2배로 확대되었습니다. tf.keras.layers.UpSampling2D 레이어를 사용하여 이미지나 특성 맵의 해상도를 높일 수 있습니다.