def main(): batch_size = 128 lr, eps = .0001, 1e-3 # lr, eps = .0001, 1e-1 root = '../../Datasets' train_iter, test_iter = fmnist.load_data(batch_size, 224, root) net = custom.VGG11(4) optimizer = torch.optim.Adam(net.parameters(), lr) ckpt_path = '../../checkpoint/vgg.pt' ckpt = None if os.path.exists(ckpt_path): ckpt = torch.load(ckpt_path) net.load_state_dict(ckpt['net']) optimizer.load_state_dict(ckpt['optimizer']) loss = nn.CrossEntropyLoss() base.train(net, train_iter, test_iter, loss, eps=eps, optimizer=optimizer, checkpoint_path=ckpt_path, checkpoint=ckpt)
def main(): batch_size = 256 num_inputs, num_outputs = 784, 10 eps = 1e-3 # eps = 1e-1 root = '../../Datasets' train_iter, test_iter = fmnist.load_data(batch_size, root=root) X, y = next(iter(test_iter)) true_labels = fmnist.get_labels(y.numpy()) net = train(num_inputs, num_outputs, train_iter, test_iter, eps) pred_labels = fmnist.get_labels(net(X).argmax(dim=1).numpy()) titles = [] for true, pred in zip(true_labels, pred_labels): title = true + '\n' if true != pred: title += 'X: ' + pred titles.append(title) fmnist.show(X, nrows=5, ncols=10, titles=titles)
def main(): batch_size = 256 num_inputs, num_outputs, num_hiddens = 784, 10, 256 eps = 1e-3 # eps = 1e-1 root = '../../Datasets' train_iter, test_iter = fmnist.load_data(batch_size, root=root) train(num_inputs, num_hiddens, num_outputs, train_iter, test_iter, eps)
def main(): batch_size = 256 lr, eps = .001, 1e-3 # lr, eps = .001, 1e-1 root = '../../Datasets' train_iter, test_iter = fmnist.load_data(batch_size, root=root) net = custom.LeNet() optimizer = torch.optim.Adam(net.parameters(), lr) loss = nn.CrossEntropyLoss() base.train(net, train_iter, test_iter, loss, eps=eps, num_epochs=50, optimizer=optimizer)