code for saving the model is added

This commit is contained in:
yunjey
2017-03-11 14:54:46 +09:00
parent 278c13513f
commit 86a0872430
17 changed files with 630 additions and 37 deletions

View File

@ -14,12 +14,12 @@ transform = transforms.Compose([
transforms.ToTensor()])
# CIFAR-10 Dataset
train_dataset = dsets.CIFAR10(root='./data/',
train_dataset = dsets.CIFAR10(root='../data/',
train=True,
transform=transform,
download=True)
test_dataset = dsets.CIFAR10(root='./data/',
test_dataset = dsets.CIFAR10(root='../data/',
train=False,
transform=transforms.ToTensor())
@ -130,6 +130,7 @@ for epoch in range(80):
optimizer = torch.optim.Adam(resnet.parameters(), lr=lr)
# Test
resnet.eval()
correct = 0
total = 0
for images, labels in test_loader:
@ -139,4 +140,7 @@ for images, labels in test_loader:
total += labels.size(0)
correct += (predicted == labels).sum()
print('Accuracy of the model on the test images: %d %%' % (100 * correct / total))
print('Accuracy of the model on the test images: %d %%' % (100 * correct / total))
# Save the Model
torch.save(resnet, 'resnet.pkl')