方法简单 但是日志怎么不能读
from tensorflow.keras.preprocessing import image_dataset_from_directory
from tensorflow.keras import models,layers,metrics,optimizers,losses,callbacks
train_data=image_dataset_from_directory("cats_and_dogs_filtered/train",label_mode='categorical',image_size=(32,32),shuffle=True,seed=123,batch_size=128)
test_data=image_dataset_from_directory("cats_and_dogs_filtered/validation",label_mode='categorical',image_size=(32,32),shuffle=True,seed=123,batch_size=128)
def my_model():
model=models.Sequential([
layers.InputLayer((32,32,3)),
layers.Conv2D(32,(3,3),padding="same",activation="relu"),
layers.MaxPooling2D((2,2),2),
layers.Conv2D(64, (3, 3), padding="same", activation="relu"),
layers.MaxPooling2D((2, 2), 2),
layers.Conv2D(128, (3, 3), padding="same", activation="relu"),
layers.MaxPooling2D((2, 2), 2),
layers.BatchNormalization(),
layers.Flatten(),
layers.Dense(128,activation="relu"),
layers.Dense(2,activation="softmax")
])
model.summary()
model.compile(optimizer=optimizers.Adam(),
loss=losses.categorical_crossentropy,
metrics=['accuracy'])
return model
if __name__ == '__main__':
model=my_model()
callbacks = [
callbacks.TensorBoard(log_dir="log")
]
model.fit_generator(train_data,epochs=10,validation_data=test_data)
|