tf.keras.Sequential() API보다 더 유연한 모델을 생성하는 방법.
Sequential()과 다르게 여러 입출력 모델을 처리할 수 있음. + skip connection과 같은 연결도 처리가 가능
1. tf.keras.Input(shape=(128, 128, 3))
: input 노드 생성.
input_img = tf.keras.Input(shape=input_shape)
2. model layer 구성하기
def convolution_model(input_shape):
input_img = tf.keras.Input(shape=input_shape)
output = tfl.Conv2D(filters=8, kernel_size=4, padding="same")(input_img)
.
.
.
.
outputs = tfl.Dense(6, activation="softmax")(output)
model = tf.keras.Model(inputs=input_img, outputs=outputs)
return model
이런 식으로 모델 쌓아서 모델을 설계할 수 있고
conv_model = convolution_model((64, 64, 3))
conv_model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
conv_model.summary()
Sequential model과 유사하게, model 초기화하고 compile할 수 있음.
3. history 확인하기
history = conv_model.fit(train_dataset, epochs=100, validation_data=test_dataset)
history.history
history.history를 통해서 loss, accuracy와 같은 정보를 확인할 수 있음
'기술 정보' 카테고리의 다른 글
| [Selenium] 웹 스크래핑, 웹 크롤링하는 법 (0) | 2023.12.12 |
|---|---|
| [Tensorflow] CNN만들기 - tf.keras.Sequential() (0) | 2023.10.02 |
| [Tensorflow] NN 설계를 위한 tensorflow 기본 함수들 (0) | 2023.09.19 |
| [Colab] Drive mount 하는 법, 경로 설정하는 법 (0) | 2023.09.19 |
| [scikit-learn] feature_extraction.text / CountVectorizer (0) | 2023.09.11 |