17_딥러닝이론및응용 HW #4

2. [그림 4-15]는 3차원 구조를 가진 데이터이다. [그림 4-15(a)]와 [그림 4-15(b)]를 위한 컨볼루션 수식을 식 (4.11)을 참조하여 각각 제시하시오.

Answer

1D Convolution

2D Convolution

3D Convolution

5. 다음은 은직층이 3개인 DMLP이다.

(1) 가중치 행렬을 쓰시오.

(2) 로지스틱 시그모드의 출력을 구하시오.

(3) ReLU의 출력을 구하시오.

(4) 가중치를 줄일경우, 오차에 어떤 영향을 미치는 지 설명하시오.

7. 그림 [4-14]에서 나머지 8개 화소의 값을 계산하시오.

2D Convolution on multiple frames
@tf.function
def forward():
  in_channels = 3 # 3 for RGB, 32, 64, 128, ... 
  out_channels = 1 # 128, 256, ...

  ones_3d = np.array([
      [[1,2,0],[1,2,3],[1,2,0]],
      [[2,1,1],[1,0,0],[3,1,1]],
      [[0,0,1],[1,0,0],[0,1,0]],          
  ])

  weight_4d = np.array([
      [[0,0,1],[0,2,0],[0,0,0]],
      [[0,0,0],[0,2,2],[1,0,0]],
      [[0,0,0],[1,2,0],[0,0,1]],          
  ])
  strides_2d = [1, 1, 1, 1]

  in_3d = tf.constant(ones_3d, dtype=tf.float32)
  filter_4d = tf.constant(weight_4d, dtype=tf.float32)

  in_width = int(in_3d.shape[0])
  in_height = int(in_3d.shape[1])

  filter_width = int(filter_4d.shape[0])
  filter_height = int(filter_4d.shape[1])

  input_3d   = tf.reshape(in_3d, [1, in_height, in_width, in_channels])
  kernel_4d = tf.reshape(filter_4d, [filter_height, filter_width, in_channels, out_channels])

  #output stacked shape is 3D = 2D x N matrix
  output_3d = tf.nn.conv2d(input_3d, kernel_4d, strides=strides_2d, padding='SAME')
  return output_3d
result = forward()

8. 0 덧대기를 하고 바이어스로 0.5를 사용하시오.

@tf.function
def forward():
  in_channels = 1 # 3 for RGB, 32, 64, 128, ... 
  out_channels = 1 # 128, 256, ...
  bias = np.array([0.5
  ])
  ones_3d = np.array([
       [2,2,2,2,2,1,1,1],
       [2,2,2,2,2,1,1,1],
       [2,2,2,2,2,1,1,1],
       [2,2,2,2,2,1,1,1],
       [2,2,2,9,9,9,9,9],
       [2,2,2,9,9,9,9,9],
       [2,2,2,9,9,9,9,9],
       [2,2,2,9,9,9,9,9]
               
])

  weight_4d = np.array([
      [-1,-1,0],
      [0,0,0],
      [1,1,1],          
  ])
  strides_2d = [1, 1, 1, 1]

  in_3d = tf.constant(ones_3d, dtype=tf.float32)
  filter_4d = tf.constant(weight_4d, dtype=tf.float32)

  in_width = int(in_3d.shape[0])
  in_height = int(in_3d.shape[1])

  filter_width = int(filter_4d.shape[0])
  filter_height = int(filter_4d.shape[1])

  input_3d   = tf.reshape(in_3d, [1, in_height, in_width, in_channels])
  kernel_4d = tf.reshape(filter_4d, [filter_height, filter_width, in_channels, out_channels])

  #output stacked shape is 3D = 2D x N matrix
  output_3d = tf.nn.conv2d(input_3d, kernel_4d, strides=strides_2d, padding='SAME')
  output_3d = tf.nn.bias_add(output_3d, bias)
  return output_3d
result = forward()
print(result)

9. 보폭을 2로 설정했을 때 컨볼루션 결과

Last updated