loader.set_description( (f'epoch: {epoch + 1}; loss: {loss.item():.5f}; ' f'acc: {accuracy:.5f}') ) class PixelTransform: def __init__(self): pass def __call__(self, input): ar = np.array(input) return torch.from_numpy(ar).long() if __name__ == '__main__': device = 'cuda' epoch = 10 dataset = datasets.MNIST('.', transform=PixelTransform(), download=True) loader = DataLoader(dataset, batch_size=32, shuffle=True, num_workers=4) model = PixelSNAIL([28, 28], 256, 128, 5, 2, 4, 128) model = model.to(device) optimizer = optim.Adam(model.parameters(), lr=1e-3) for i in range(10): train(i, loader, model, optimizer, device) torch.save(model.state_dict(), f'checkpoint/mnist_{str(i + 1).zfill(3)}.pt')
(f'epoch: {epoch + 1}; loss: {loss.item():.5f}; ' f'acc: {accuracy:.5f}')) class PixelTransform: def __init__(self): pass def __call__(self, input): ar = np.array(input) return torch.from_numpy(ar).long() if __name__ == '__main__': device = 'cuda' epoch = 10 dataset = datasets.MNIST('.', transform=PixelTransform(), download=True) loader = DataLoader(dataset, batch_size=32, shuffle=True, num_workers=4) model = PixelSNAIL([28, 28], 256, 128, 5, 2, 4, 128) model = model.to(device) optimizer = optim.Adam(model.parameters(), lr=1e-3) for i in range(10): train(i, loader, model, optimizer, device) torch.save(model.state_dict(), f'checkpoint/mnist_{str(i + 1).zfill(3)}.pt')