Created
December 21, 2019 03:27
-
-
Save rfalaize/50f450080562c9a2368ceb286f342bec to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # choose a loss function and an optimizer | |
| model.compile(loss=tf.keras.losses.categorical_crossentropy, | |
| optimizer=tf.keras.optimizers.Adam(), | |
| metrics=['accuracy']) | |
| # (optional) configure tensorboard to collect training stats | |
| log_dir = "C:\\temp\\tensorboard\\{}".format(datetime.now().strftime("%Y%m%d-%H%M%S")) | |
| os.mkdir(log_dir) | |
| tensorboardCallback = tf.keras.callbacks.TensorBoard(log_dir=log_dir) | |
| # start training | |
| print("Start training model...") | |
| model.fit(X_train, y_train, | |
| batch_size=512, | |
| epochs=10, | |
| verbose=1, | |
| validation_data=(X_test, y_test), | |
| callbacks=[tensorboardCallback]) | |
| # evaluate the trained model | |
| print("Model trained. Evaluating on test set...") | |
| score = model.evaluate(X_test, y_test, verbose=0) | |
| print('Test loss:', score[0]) | |
| print('Test accuracy:', score[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment