import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
(trainX, trainY), (testX, testY) = tf.keras.datasets.fashion_mnist.load_data()
trainX = trainX / 255.0
testX = testX / 255.0
trainX = trainX.reshape( (trainX.shape[0], 28,28,1) )
testX = testX.reshape( (testX.shape[0], 28,28,1) )
# 중간에 레이어를 두개 합치기 섞고 비비고 할수있는 방법이 있음 - Functional API쓰면 가능
# 기존에 썻던 Sequential 은 차례대로 하는것 밖에 안됨
model = tf.keras.Sequential([
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax'),
])
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
# model.fit(trainX, trainY, validation_data=(testX, testY), epochs=3)
from tensorflow.keras.utils import plot_model
plot_model(model, to_file='model.png', show_shapes=True, show_layer_names=True) # 모델을 그림으로 미리보기 가능
이거 에러나네요. colab환경에서 하고있는데 아래처럼 뜨네요.
ValueError Traceback (most recent call last)
<ipython-input-8-8a648e7c2536> in <cell line: 29>()
27 from tensorflow.keras.utils import plot_model
28
---> 29 plot_model(model, to_file='model.png', show_shapes=True, show_layer_names=True) # 모델을 그림으로 미리보기 가능
/usr/local/lib/python3.9/dist-packages/keras/utils/vis_utils.py in plot_model(model, to_file, show_shapes, show_dtype, show_layer_names, rankdir, expand_nested, dpi, layer_range, show_layer_activations, show_trainable)
443
444 if not model.built:
--> 445 raise ValueError(
446 "This model has not yet been built. "
447 "Build the model first by calling `build()` or by calling "
ValueError: This model has not yet been built. Build the model first by calling `build()` or by calling the model on a batch of data.