def model(request): mdl = cnn.NgnCnn(layer_size=10) mdl.to(device) def fin(): print("Teardown model") request.addfinalizer(fin) return mdl
def train_evaluation(parameters): # TODO nfolds = 3 results = np.zeros(nfolds) for i in range(nfolds): net = cnn.NgnCnn(args.neurons, seed=i, excite=parameters["excite"]) net.to(DEVICE) train(net, data_loader, datatype, DEVICE, parameters) result = evaluate(net, data_loader, DEVICE) results[i] = result["Loss"][0] return {"cross_entropy": (results.mean(), results.std())}
}, } results = pd.DataFrame( index=range(REPEATS * len(group_config)), columns=["Group", "Train Accuracy", "Test Accuracy", "Repeat"], ) counter = 0 # DATASET data_loader = cnn.Cifar10_data(mode="test", batch_size=BATCH_SIZE) for i in range(REPEATS): print(f"Running trial {i+1}/{REPEATS}") net = cnn.NgnCnn(args.neurons, seed=i) for group in group_config: net_copy = copy.deepcopy(net) if "Dropout" in group: net_copy.dropout = 0.2 if "Neural Noise" in group: net_copy.neural_noise = (-0.2, 0.5) net_copy.to(device) parameters = group_config[group] log, _ = cnn.train_model( model=net_copy, dataset=data_loader, dtype=dtype, device=device, **parameters, )
results = pd.DataFrame( index=range(REPEATS * len(group_config)), columns=list(range(EPOCHS)) + ["Group", "Test Accuracy", "Repeat"], ) counter = 0 mode = 'targetted' if args.targetted else 'random' # DATASET data_loader = cnn.Cifar10_data(mode="test", batch_size=BATCH_SIZE) dfs = [] for i in range(REPEATS): print(f"Running trial {i+1}/{REPEATS}") net = cnn.NgnCnn(args.neurons, seed=i, excite=args.excite) for group in group_config: net_copy = copy.deepcopy(net) net_copy.to(device) parameters = group_config[group] log = cnn.train_model( model=net_copy, dataset=data_loader, dtype=dtype, device=device, **parameters, ) # accuracy['Accuracy'][0] accuracy = cnn.predict(net_copy, data_loader)['Accuracy'][0] start = cnn.predict(net_copy, data_loader, train=True)['Accuracy'][0]
"epochs": EPOCHS, "neurogenesis": 0, "early_stop": False, "optim_args":{ "lr": LR, } }, } # DATASET data_loader = cnn.Cifar10_data(mode="validation", data_folder=DATA_DIR, batch_size=BATCH_SIZE, num_workers=16) REPEATS = 1 for i in range(REPEATS): print(f"Running trial {i+1}/{REPEATS}") net = cnn.NgnCnn(args.neurons, channels=3, seed=i, excite=True) for group in group_config: net_copy = copy.deepcopy(net) net_copy.to(device) if group == 'Dropout': net_copy.dropout = 0.2 parameters = group_config[group] log, optimizer = cnn.train_model( model=net_copy, dataset=data_loader, dtype=dtype, device=device, **parameters, ) accuracy = cnn.predict(net_copy, data_loader, device=device, valid=True)
}, } # DATASET data_loader = cnn.Cifar10_data(mode="validation", data_folder=DATA_DIR, batch_size=BATCH_SIZE, num_workers=16) REPEATS = 20 results = pd.DataFrame(index=range(REPEATS * len(group_config)), columns=['Group', 'Test Accuracy', 'Repeat']) counter = 0 for i in range(REPEATS): print(f"Running trial {i+1}/{REPEATS}") net = cnn.NgnCnn(args.neurons, channels=3, seed=i, neural_noise=(-0.2, 1)) for group in group_config: net_copy = copy.deepcopy(net) net_copy.to(device) parameters = group_config[group] log, optimizer = cnn.train_model( model=net_copy, dataset=data_loader, dtype=dtype, device=device, **parameters, ) accuracy = cnn.predict(net_copy, data_loader, device=device,
def train_evaluation(parameters, nfolds=5): net = cnn.NgnCnn(args.neurons, seed) net.to(DEVICE) train(net, data_loader, datatype, DEVICE, parameters) return evaluate(net, data_loader, DEVICE)