Post

[KT Aivle 3기 AI] 22일차. 딥러닝 (4) Functional API 활용 실습

KT Aivle School 3기 AI 22일차

  • 강사 : 김건영 강사님
  • 주제 : 딥러닝 공부를 위한 기본 토대 쌓기
  • 내용 :
    • Functional API를 사용한 Connection Layer(Concatenate, Add) 구현
    • Functional API를 사용한 실습 (Iris, Breast_cancer)

딥러닝 Connection

  • 특징들을 종류 별로 따로 연결하여 연결된 정보를 Concatenate or Add하는 Layer 추가.
  • Add는 shape이 맞아야 연산 가능
  • 코드 예시
1
2
3
4
5
6
7
8
9
10
11
12
13
14
input_layer1 = keras.layers.Input(shape=(2, )) # ex) 특징을 구분하여 따로 넣어줌
input_layer2 = keras.layers.Input(shape=(2, )) # ex) 특징을 구분하여 따로 넣어줌

input_layer3 = keras.layers.Input(shape=(4, )) # ex) 전체 특징

hl_1 = keras.layers.Dense(2, activation='relu')(input_layer1)
hl_2 = keras.layers.Dense(2, activation='relu')(input_layer2)

add_layer = keras.layers.Add()([hl_1, hl_2])
concat_layer = keras.layers.Concatenate()([add_layer, input_layer3])

output_layer = keras.layers.Dense(1, activation='sigmoid')(concat_layer)

model = keras.models.Model([input_layer1, input_layer2, input_layer3], output_layer)

모델 구조 시각화

  • keras에는 모델 구조를 이미지로 시각화 해볼 수 있는 Tool이 존재
  • model.summary()로 간단하게 확인할 수 있지만, 표로 더 직관적으로 확인할 수 있다.
  • 코드
1
2
3
from tensorflow.keras.utils import plot_model

plot_model(model, show_shapes=True)

image

Iris, Breast Cancer, Wine 데이터 실습

This post is licensed under CC BY 4.0 by the author.

[KT Aivle 3기 AI] 21일차. 딥러닝 (3) MNIST, CIFAR 10 실습

[KT Aivle 3기 AI] 23일차. 미니프로젝트 2차 (1)