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
| import tensorflow as tf | |
| from keras import Sequential | |
| from keras.layers import Conv2D | |
| model = Sequential() | |
| model.add(Conv2D(32, (3,3), activation='relu', input_shape=(28,28,1))) | |
| model.summary() |
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
| # Set dropout rate | |
| DROPOUT = 0.1 # Drop 10% | |
| # Build model | |
| model = tf.keras.Sequential() | |
| model.add(keras.layers.Dense(HIDDEN_NEURON, input_shape=(RESHAPED, ), | |
| name='dense_layer', activation='relu')) | |
| model.add(keras.layers.Dropout(DROPOUT)) | |
| model.add(keras.layers.Dense(HIDDEN_NEURON, | |
| name='dense_layer_2', activation='relu')) |
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
| EPOCHS = 300 | |
| BATCH_SIZE = 128 | |
| VERBOSE = 1 | |
| NB_CLASSES = 10 | |
| HIDDEN_NEURON = 128 | |
| VALIDATION_SPLIT = 0.2 | |
| # Build model | |
| from keras import Sequential | |
| from keras.layers import Dense |
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
| %tensorboard --logdir drive/MyDrive/logs/tf_simple |
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
| # Model evaluation | |
| test_loss, test_acc = model.evaluate(X_test, Y_test) | |
| print('Test accuracy:', test_acc) |
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
| # Model train | |
| # Create new TensorBoard session everytime we train a model | |
| tensorboard = create_tensorboard_callback() | |
| model.fit(X_train, Y_train, batch_size=BATCH_SIZE, | |
| epochs=EPOCHS, verbose=VERBOSE, validation_split=VALIDATION_SPLIT,callbacks=[tensorboard]) |
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
| # Model compile | |
| model.compile(optimizer='SGD', | |
| loss='categorical_crossentropy', | |
| metrics=['accuracy']) | |
| model.summary() |
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
| # Build model | |
| from keras import Sequential | |
| from keras.layers import Dense | |
| model = Sequential() | |
| model.add(Dense(NB_CLASSES, input_shape=(RESHAPED, ), | |
| name='dense_layer', activation='softmax')) |
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
| %load_ext tensorboard | |
| import datetime | |
| # Create a function to build a TensorBoard callback | |
| def create_tensorboard_callback(): | |
| # Create a log directory for storing TensorBoard logs | |
| logdir = os.path.join('drive/MyDrive/logs/tf_simple', | |
| # Make it so the logs get tracked whenever we run an experiment | |
| datetime.datetime.now().strftime("%Y%m%d-%H%M%S")) | |
| return tf.keras.callbacks.TensorBoard(logdir) |
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
| import tensorflow as tf | |
| import numpy as np | |
| import os | |
| from tensorflow import keras | |
| # Neural network and train variables | |
| EPOCHS = 200 | |
| BATCH_SIZE = 128 | |
| VERBOSE = 1 | |
| NB_CLASSES = 10 # Num of outputs |