def weight_decay_test(): epoch_list = [x for x in range(1000, 15001) if x % 1000 == 0] # test_errors = {} train_errors = {} test_rate = [] for epochs in epoch_list: train_err = [] cnn = CifarLeNet(lr=0.001, epochs=epochs, batch_size=128, train_data=cifar_train, test_data=cifar_test, wd=0.004, decay_lr=False, decay_w=True, optimizer='adam', seed=100) cnn.train(train_err) train_errors[str(epochs)] = train_err cnn.test_eval(epochs, test_rate) cnn.reset() with open('pickled_data/test_acc_epochs_wd', 'wb') as f: pickle.dump([train_errors, test_rate], f) return test_rate
def batch_sizes(): sizes = [10, 25, 50, 64, 100, 200, 300, 400, 500, 750, 1000, 2000] # test_errors = {} train_errors = {} test_rate = [] for bs in sizes: train_err = [] cnn = CifarLeNet(lr=0.001, epochs=10000, batch_size=bs, test_data=cifar_test, train_data=cifar_train, wd=0.004, decay_lr=False, decay_w=True, optimizer='adam', seed=100) cnn.train(train_err) train_errors[str(bs)] = train_err cnn.test_eval(bs, test_rate) cnn.reset() with open('pickled_data/test_acc_bs', 'wb') as f: pickle.dump([train_errors, test_rate], f) return test_rate
def lr_test(): lr_rates = [0.001, 0.01, 0.1, 0.5, 1.0] # test_errors = {} train_errors = {} test_rate = [] for rate in lr_rates: train_err = [] cnn = CifarLeNet(lr=rate, epochs=10000, batch_size=128, train_data=cifar_train, test_data=cifar_test, wd=0.004, decay_lr=False, decay_w=True, optimizer='adam', seed=100) cnn.train(train_err) train_errors[str(rate)] = train_err cnn.test_eval(rate, test_rate) cnn.reset() with open('pickled_data/test_acc_lrs', 'wb') as f: pickle.dump([train_errors, test_rate], f) return test_rate
def lrs(rates, filename): train_errors = {} for lr_rate in rates: acc_list = [] cnn = CifarLeNet(lr=lr_rate, epochs=5000, batch_size=500, train_data=cifar_train, test_data=cifar_test, wd=0.004, decay_lr=False, decay_w=False, optimizer='adam', seed=100) cnn.train(acc_list) cnn.reset() train_errors[str(lr_rate)] = acc_list with open('pickled_data/' + filename, 'wb') as f: pickle.dump(train_errors, f)
def decay_lr(filename, start_rate=0.01): train_errors = {} print('Decay') acc_list = [] cnn = CifarLeNet(lr=start_rate, epochs=10000, batch_size=128, train_data=cifar_train, test_data=cifar_test, wd=0.004, decay_lr=True, decay_w=False, optimizer='adam', seed=100) cnn.train(acc_list) cnn.reset() train_errors['decay'] = acc_list with open('pickled_data/' + filename, 'wb') as f: pickle.dump(train_errors, f) return train_errors
def algos(optimizers, filename, m=False, m_val=0.5): if not m: train_errors = {} for algo in optimizers: acc_list = [] cnn = CifarLeNet(lr=0.0001, epochs=5000, batch_size=500, train_data=cifar_train, test_data=cifar_test, wd=0.004, decay_lr=False, decay_w=False, optimizer=algo, seed=100) cnn.train(acc_list) cnn.reset() train_errors[algo] = acc_list with open('pickled_data/' + filename, 'wb') as f: pickle.dump(train_errors, f) else: train_errors = {} for value in m_val: acc_list = [] cnn = CifarLeNet(lr=0.0001, epochs=5000, batch_size=500, train_data=cifar_train, test_data=cifar_test, wd=0.004, decay_lr=False, decay_w=False, optimizer='momentum', seed=100, momentum=value) cnn.train(acc_list) cnn.reset() train_errors['momentum' + str(value)] = acc_list with open('pickled_data/' + filename, 'wb') as f: pickle.dump(train_errors, f)