Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import torch
import torchvision
import torch.nn as nn
import torch.nn.functional as F
from torchvision import datasets, transforms
import mlflow
import mlflow.pytorch
class Params(object):
def __init__(self, batch_size, epochs, seed, interval):
self.batch_size = batch_size
self.epochs = epochs
self.seed = seed
self.interval = interval
args = Params(256, 4, 0, 20)
C:\ProgramData\Anaconda3\envs\torchEnv\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
and should_run_async(code)
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.1307,), (0.3081, ))
])
trainset = datasets.MNIST(root='./', train=True, download=True, transform=transform)
testset = datasets.MNIST(root='./', train=False, download=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=args.batch_size, shuffle=True)
testloader = torch.utils.data.DataLoader(testset, batch_size=args.batch_size, shuffle=False)
class Model(nn.Module):
def __init__(self, nh=32):
super(Model, self).__init__()
self.classifier = nn.Sequential(
nn.Linear(784, nh),
nn.ReLU(),
nn.Linear(nh, 10))
def forward(self, x):
x = x.view(x.size(0), -1)
return self.classifier(x)