# load train and test data print('loading data ...') # (x_train, y_train), (x_test, y_test) = Funcs.load_data(dirs, target_size, gray=gray, classes=classes) (x_train, y_train), (x_test, y_test) = load_data() (x_train, y_train) = Funcs.trans_data(x_train, y_train, classes) (x_test, y_test) = Funcs.trans_data(x_test, y_test, classes) print('loading data done') # define callbacks for models to render model performance better checkpoint = ModelCheckpoint(model_save_path, monitor='val_acc', save_best_only=True, verbose=0) lrschedual = LearningRateScheduler( lambda epoch: Funcs.lr_schedual(epoch, epochs=epochs), verbose=0) # whether load existent model if load_existent_model and os.path.exists(model_load_path): model = load_model(model_load_path) else: model = model_design(x_train.shape[1:], classes) # train the model start_time = datetime.datetime.now() model.fit(x_train, y_train, epochs=epochs, batch_size=batch_size, validation_data=(x_test, y_test), callbacks=[checkpoint, lrschedual],
gray = False load_existent_model = False # load train and test data print('loading data ...') (images, labels, counts) = Funcs.read_images_from_directories(dirs, target_size, get_counts=True, init_json=True, shuffle=True) classes = len(counts) (x_train, y_train), (x_test, y_test) = Funcs.split_train_test(images, labels, counts) (x_train, y_train) = Funcs.trans_data(x_train, y_train, classes) (x_test, y_test) = Funcs.trans_data(x_test, y_test, classes) print('loading data done') # define callbacks for models to render model performance better checkpoint = ModelCheckpoint(model_save_path, monitor='val_acc', save_best_only=True, verbose=0) lrschedual = LearningRateScheduler(lambda epoch: Funcs.lr_schedual(epoch, epochs=epochs), verbose=0) # whether load existent model if load_existent_model and os.path.exists(model_load_path): model = load_model(model_load_path) else: model = model_design(x_train.shape[1:], classes) # train the model start_time = datetime.datetime.now() model.fit(x_train, y_train, epochs=epochs, batch_size=batch_size, validation_data=(x_test, y_test), callbacks=[checkpoint, lrschedual], verbose=1) # fine tune last conv parameters # for layer in model.layers[:15]: # layer.trainable = False