我定义了我的模型,然后将我的模型保存在一个文件夹中。但是,我正在尝试加载我的模型,但我不明白如何解决这个形状问题。
num_classes = len(class_names)
model = tf.keras.Sequential([
layers.experimental.preprocessing.Rescaling(1./255),
layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(32, (3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(32, (3, 3), activation='relu'),
layers.MaxPooling2D((2,2)),
layers.Flatten(),
layers.Dense(64, activation='relu'),
#layers.Dense(128, activation='relu'),
layers.Dense(num_classes)
])
model.compile(
#loss='binary_crossentropy',
optimizer='adam',
loss=tf.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy']
)
history = model.fit(
train_ds,
validation_data=validation_ds,
epochs=20,
batch_size=32,
verbose=0
)
model.summary()
tf.saved_model.save(model, '/content/drive/MyDrive/Colab Notebooks/Archivos para CodeChallenge2/trained_waldo_model')