Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from tensorflow.keras.preprocessing. image import ImageDataGenerator
from tensorflow.keras.callbacks import ModelCheckpoint
from tensorflow.keras.optimizers import Adam
checkpoint=ModelCheckpoint('best.h5', monitor='val_acc', verbose=1, save_best_only=True, mode="max")
epochs=20
lr=0.002
optimizer=Adam(lr=lr, decay=lr/(epochs*1.5))
model.compile(optimizer=optimizer, loss="sparse_categorical_crossentropy",metrics=["accuracy"])
datagenerator=ImageDataGenerator( rotation_range=9, zoom_range=0.25, width_shift_range=0.25, height_shift_range=0.25)
datagenerator.fit(x_train)
batch_size=32
history=model.fit_generator(datagenerator.flow(x_train, y_train, batch_size=batch_size), epochs=epochs, validation_data=(x_val, y_val), verbose=2,steps_per_epoch=x_train.shape[0]//batch_size, callbacks=[checkpoint])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment