from utils.load_batch import load_batch
from utils.handle_data import data_split
from utils import train
from utils.lrate import StepLR
from utils.lrate import CyclicLR
from clsr.nn_kl import KLayerNeuralNetwork
from utils.preprocess import StandardScaler

if __name__ == "__main__":
    train_data = load_batch("cifar-10-batches-py/data_batch_1")
    net = KLayerNeuralNetwork(n_hidden_nodes=[50, 50],
                              p_dropout=0.0,
                              batch_norm=False,
                              batch_norm_momentum=.9)

    scaler = StandardScaler()
    scaler.fit(train_data['pixel_data'])
    train_data['pixel_data'] = scaler.transform(train_data['pixel_data'])

    batch_size = 100
    train_loader = cifar10_DataLoader(train_data,
                                      batch_size=batch_size,
                                      shuffle=False)

    ntrain = train_data['labels'].shape[0]
    n_epoch = 200
    scheduler = StepLR(0.05, 20, gamma=.5)
    # scheduler = CyclicLR(eta_min=1e-5, eta_max=1e-1, step_size=1000)
    for epoch in range(n_epoch):
        train(train_loader, net, 0.0, scheduler)
Exemplo n.º 2
0
from utils.img_jitter import ImageJitter
from scipy.special import softmax


if __name__ == "__main__":

    # config:
    is_jiter = True

    merged_data = get_all_train_data("cifar-10-batches-py")
    train_data, valid_data = data_split(merged_data, n_valid=1000)
    test_data = load_batch("cifar-10-batches-py/test_batch")

    scaler = StandardScaler()
    scaler.fit(train_data['pixel_data'])
    valid_data['pixel_data'] = scaler.transform(valid_data['pixel_data'])
    test_data['pixel_data'] = scaler.transform(test_data['pixel_data'])
    print("Done preprocessing!")
    # ==================================================================
    # make dataloader
    batch_size = 100
    train_loader = cifar10_DataLoader(train_data, batch_size=batch_size)
    valid_loader = cifar10_DataLoader(valid_data, batch_size=batch_size)
    test_loader = cifar10_DataLoader(test_data, batch_size=batch_size)
    # ==================================================================
    net = TwoLayerNeuralNetwork(n_hidden_nodes=[50], p_dropout=0.0)
    # net = TwoLayerNeuralNetwork(n_hidden_nodes=[768])
    ntrain = train_data['labels'].shape[0]
    n_step_per_cycle = 2
    ncycle = 2
    n_epoch = ncycle*n_step_per_cycle*2