X_train, X_test, y_train, y_test = train_test_split(input, y, test_size=0.1, random_state=42) model = NASNetMobile(weights=None, classes=7) model.summary() model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy']) time_callback = TimeHistory() model.fit(X_train, y_train, epochs=5, batch_size=32, validation_data=(X_test, y_test), callbacks=[time_callback]) name = 'results/UHCS_NASNetMobile_Weights' score = model.evaluate(X_test, y_test) print('Test score:', score[0]) print('Test accuracy:', score[1]) model.save_weights(name + '.h5') times = time_callback.times file = open('NASNetMobile.txt', 'w') file.write('Test score:' + str(score[0]) + '\n') file.write('Test accuracy:' + str(score[1]) + '\n') file.write(str(times)) file.close()
# opt = keras.optimizers.Adadelta(lr=1.0, rho=0.95, epsilon=None, decay=0.0) opt = keras.optimizers.Adamax(lr=0.002, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0) model.compile(loss='categorical_crossentropy', optimizer=opt, metrics=['accuracy']) log_path = '/tmp/tflearn_logs/NASNetMobile_LCZ42_Adadelta' callback = TensorBoard(log_path) callback.set_model(model) model.fit( x_train, y_train, batch_size=1024, # 128,1024 epochs=10, shuffle="batch", validation_data=(x_test, y_test)) modelpath = 'NASNetMobile_Adadelta_epochs_10.h5' model.save(modelpath) print('Saved trained model at %s ' % modelpath) # Score trained model. scores = model.evaluate(x_test, y_test, verbose=1) print('Test loss:', scores[0]) print('Test accuracy:', scores[1])