-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0.py
68 lines (58 loc) · 2.16 KB
/
0.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from torch.nn import *
import torch
import torch.nn as nn
import torchvision
import torchvision.transforms as transforms
import torch.nn.functional as F
import matplotlib.pyplot as plt
import pytorch_lightning as pl
from pytorch_lightning import Trainer
from tqdm import tqdm
from torch.utils.data import DataLoader, Dataset
import wandb, os
PROJECT_NAME = "Intel-Image-Classification-Learning-PyTorch-Lightning"
criterion = MSELoss()
class Model(Module):
def __init__(self):
super().__init__()
self.activation = ReLU()
self.linear1 = Linear(3 * 5 * 5, 256)
self.linear2 = Linear(256, 512)
self.linear3 = Linear(512, 1024)
self.linear4 = Linear(1024, 10)
def training_step(self, batch, batch_idx):
images, labels = batch
preds = self.activation(self.linear1(images))
preds = self.activation(self.linear2(preds))
preds = self.activation(self.linear3(preds))
preds = self.activation(self.linear4(preds))
loss = criterion(preds, labels)
wandb.log({"Loss": loss.item()})
return {"train_loss": loss.item()}
def validation_step(self, batch, batch_idx):
images, labels = batch
preds = self.activation(self.linear1(images))
preds = self.activation(self.linear2(preds))
preds = self.activation(self.linear3(preds))
preds = self.activation(self.linear4(preds))
loss = criterion(preds, labels)
wandb.log({"Val Loss": loss.item()})
return {"val_loss": loss.item()}
def train_dataloader(self):
dataset = torchvision.datasets.MNIST(
"./data/",
download=True,
)
data_loader = DataLoader(dataset, batch_size=32, shuffle=True)
return data_loader
def val_dataloader(self):
dataset = torchvision.datasets.MNIST("./data/", download=True, train=False)
data_loader = DataLoader(dataset, batch_size=32, shuffle=True)
return data_loader
def configure_optimizers(self):
return torch.optim.Adam(self.parameters(), lr=0.001)
model = Model()
wandb.init(project=PROJECT_NAME, name="baseline")
trainer = Trainer()
trainer.fit(model)
wandb.finish()