-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassification.py
More file actions
33 lines (27 loc) · 1.08 KB
/
Copy pathclassification.py
File metadata and controls
33 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import torch
from torch import optim
from datasets.mnist_dataset import MNISTDataset
from models.models import Classifier, ClassifierVariableLayers
from options.classification_options import ClassificationOptions
from utilities import utils
from utilities.utils import init_pytorch, test_classification_model, train_classification_model, classify_images
if __name__ == "__main__":
options = ClassificationOptions()
init_pytorch(options)
# create and visualize the MNIST dataset
dataset = MNISTDataset(options)
dataset.show_examples()
"""START TODO: fill in the missing parts"""
# create a Classifier instance named model
model = Classifier(options)
# define the opimizer
optimizer = optim.SGD(model.parameters(), lr=options.lr, momentum=0.9)
# train the model
train_classification_model(model,optimizer,dataset,options)
"""END TODO"""
# Test the model
print("The Accuracy of the model is: ")
test_classification_model(model, dataset, options)
classify_images(model, dataset, options)
# save the model
utils.save(model, options)