from timeit import default_timer as timer from collections import defaultdict from BBalpha_dropout import * if len(sys.argv) != 3: print("Call this program like this:\n" " ./mnist-mlp-train.py alpha run\n" " e.g. ./mnist-mlp-train.py 0.5 1") exit() # extract command line arguments alpha = float(sys.argv[1]) run = sys.argv[2] # get dataset train, validation, _ = load_mnist(flatten=True) # constants nb_train = train[0].shape[0] nb_val = validation[0].shape[0] input_dim = train[0].shape[1] nb_classes = train[1].shape[1] batch_size = 128 nb_layers = 2 nb_units = 100 p = 0.5 wd = 1e-6 K_mc = 10
import sys import os if len(sys.argv) != 3: print("Call this program like this:\n" " ./mnist-cnn-train.py alpha run\n" " e.g. ./mnist-cnn-train.py 0.5 1" ) exit() # extract command line arguments alpha = float(sys.argv[1]) run = sys.argv[2] # get dataset train, validation, _ = load_mnist(flatten=False, channels_first=True) # constants assert train[0].shape[2] == train[0].shape[3], 'Input image not square' input_size = train[0].shape[2] in_channels = train[0].shape[1] nb_train = train[0].shape[0] nb_val = validation[0].shape[0] input_dim = train[0].shape[1] nb_classes = train[1].shape[1] batch_size = 128 val_batch_size = nb_val # nb_layers = 2 nb_units = 100 p = 0.5
if len(sys.argv) != 3: print("Call this program like this:\n" " ./cnn-train.py dataset run\n" " e.g. ./cnn-train.py mnist 1\n" "Dataset is either ['mnist', 'cifar10', 'svhn']" ) exit() # extract command line arguments dataset = sys.argv[1] run = sys.argv[2] # get dataset if dataset == 'mnist': train, validation, _ = load_dataset.load_mnist(flatten=False, channels_first=False) elif dataset == 'cifar10': train, validation, _ = load_dataset.load_cifar10(channels_first=False) elif dataset == 'svhn': train, validation, _ = load_dataset.load_svhn(channels_first=False) else: print("Unrecognized dataset, use 'mnist', 'cifar10', or 'svhn'") print("Exiting...") exit() # otherwise TF grabs all available gpu memory if not hasattr(K, "tf"): raise RuntimeError("This code requires keras to be configured" " to use the TensorFlow backend.") config = tf.ConfigProto()