if __name__ == "__main__": 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']) train_data['pixel_data'] = scaler.transform(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=[800], p_dropout=0.0) # net = TwoLayerNeuralNetwork(n_hidden_nodes=[768]) ntrain = train_data['labels'].shape[0] n_step_per_cycle = 3 ncycle = 3 n_epoch = ncycle * n_step_per_cycle * 2 iter_per_epoch = int(np.ceil(ntrain / batch_size)) step_size = n_step_per_cycle * iter_per_epoch # weight_decay = 0.004454 # weight_decay = 0.005 weight_decay = 0.000 scheduler = CyclicLR(eta_min=1e-5, eta_max=1e-1, step_size=step_size)
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)
import numpy as np import utils import utils.load_batch from utils.load_batch import load_batch from utils.load_batch import cifar10_DataLoader from utils.handle_data import data_split from utils.handle_data import get_all_train_data from utils.preprocess import StandardScaler from clsr.nn_2l import TwoLayerNeuralNetwork if __name__ == "__main__": merged_data = get_all_train_data("cifar-10-batches-py") test_data = load_batch("cifar-10-batches-py/test_batch") loader = cifar10_DataLoader(test_data, batch_size=100) cnt = 0 for inputs, labels in loader: cnt += labels.shape[0] print(cnt) cnt = 0 for inputs, labels in loader: cnt += labels.shape[0] print(cnt)