Created
September 4, 2021 09:21
-
-
Save siddharthganjoo/e38ad2a9a317ed454ab995b94b67fd15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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