Sequential 모델을 넘어서: 케라스의 함수형 API

https://drive.google.com/uc?id=18xpH16FMRyT--YEoT2uYn13B5K2l_BcD

https://drive.google.com/uc?id=1cXk1_dlHant78ERlfye9sN1jayKlLLUB

https://drive.google.com/uc?id=1o8RbNSTlmPEzZ7b05CnsGG412Sub8GXH

https://drive.google.com/uc?id=1sSadnKiUhrs06doJlGmli4XLTSimXwYf

https://drive.google.com/uc?id=1eJBwbYP6mGWFLYZ75b17hFctoQcntTU2

함수형 API 소개

from keras import Input, layers

input_tensor = Input(shape=(32,))
dense = layers.Dense(32, activation='relu')
output_tensor = dense(input_tensor)
from keras.models import Sequential, Model

# Sequential 모델
seq_model = Sequential()
seq_model.add(layers.Dense(32, activation='relu', input_shape=(64,)))
seq_model.add(layers.Dense(32, activation='relu'))
seq_model.add(layers.Dense(10, activation='softmax'))

# 함수형 API로 만든 모델
input_tensor = Input(shape=(64,))
x = layers.Dense(32, activation='relu')(input_tensor)
x = layers.Dense(32, activation='relu')(x)
output_tensor = layers.Dense(10, activation='softmax')(x)

model = Model(input_tensor, output_tensor)
model.summary()
---
Layer (type)                 Output Shape              Param #
=================================================================
input_2 (InputLayer)         (None, 64)                0
_________________________________________________________________
dense_5 (Dense)              (None, 32)                2080
_________________________________________________________________
dense_6 (Dense)              (None, 32)                1056
_________________________________________________________________
dense_7 (Dense)              (None, 10)                330
=================================================================
Total params: 3,466
Trainable params: 3,466
Non-trainable params: 0