def main(): # hyperparams epochs = 1000 lr = 0.02 ls = 128 size = 1000 # collect data and split with sklearn # data types: "moons", "multi", "diabetes", "digit" data_type = "digit" features, labels = get_data(size, data_type) one_hot_target = pd.get_dummies(labels) train_x, x_val, train_y, y_val = train_test_split(features, one_hot_target, test_size=0.1, random_state=20) train_y = np.array(train_y) y_val = np.array(y_val) # training model = Net(train_x, train_y, epochs, ls, lr) model.train() # testing if data_type != "digit": plt.subplot(2,1,1) plt.title('Training Batch') print("Training accuracy: ", test(model, train_x, train_y, data_type)) if data_type != "digit": plt.tight_layout(pad=3.0) plt.subplot(2,1,2) print("Test accuracy: ", test(model, x_val, np.array(y_val), data_type)) if data_type != "digit": plt.title('Testing Batch') plt.show()
def train(flags=FLAGS, hps=HPS): from Network import Net net = Net(flags, hps) for g in range(flags.global_epoch): with timer(f'Global epoch #{g}'): logger.debug(f'Start global epoch {g}') net.train(porportion=0.01) l, acc = net.test(porportion=0.1) logger.debug(f'Finish global epoch {g}') net.save_model(name=f'{l:.4f}-{acc:.4f}') logger.info('All done')