import torch.optim as optim import torch.nn as nn import torch.nn.functional as F from datasets import mnist, loader from logger import struct, Logger from train import train, acc_metric, nll_metric import numpy as np H_proto = struct( batch_size=64, val_batch_size=1000, epochs=10, lr=0.01, caps=[10, 20, 50, 70, 100, 200, 500], momentum=0.5, ) S_proto = struct(epoch=0, bn=0) log = Logger('mnist_capacity_nodrop', H_proto, S_proto, load=True, metric_show_freq=1) tn_loader, val_loader = loader(mnist(), H_proto.batch_size, H_proto.val_batch_size) for epoch in range(S_proto.epoch, len(H_proto.caps)): S_proto.epoch = epoch log.flush() cap = H_proto.caps[epoch]
from logger import Logger, struct import matplotlib.pyplot as plt # from pprint import pprint H = struct() S = struct() log = Logger('mnist_momentum', H, S, load=True) losses = [m.best_loss for m in log.metrics()] # pprint(log.metrics()) # pprint(H.momenta) plt.plot(H.momenta, losses) plt.xscale('log') plt.yscale('log') plt.show()
import torch.optim as optim import torch.nn as nn import torch.nn.functional as F from datasets import cifar10, loader from logger import struct, Logger from train import train, acc_metric, nll_metric from models import vgg H = struct( batch_size=128, val_batch_size=100, epochs=10, lr=0.1, momentum=0.9, ) S = struct(epoch=1, bn=1) log = Logger('cifar10_standard', H, S, overwrite=True, metric_show_freq=100) tn_loader, val_loader = loader(cifar10(), H.batch_size, H.val_batch_size) class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.features = vgg('vgg11') self.classifier = nn.Linear(512, 10) def forward(self, x): out = self.features(x) out = out.view(out.size(0), -1)
from logger import Logger, struct import matplotlib.pyplot as plt from pprint import pprint H = struct() S = struct() log = Logger('mnist_capacity', H, S, load=True) losses = [m.best_loss for m in log.metrics()] H_nodrop = struct() S_nodrop = struct() log_nodrop = Logger('mnist_capacity_nodrop', H_nodrop, S_nodrop, load=True) losses_nodrop = [m.best_loss for m in log_nodrop.metrics()] H_mlp = struct() S_mlp = struct() log_mlp = Logger('mnist_capacity_mlp', H_mlp, S_mlp, load=True) losses_mlp = [m.best_loss for m in log_mlp.metrics()] pprint(log.metrics()) pprint(log_nodrop.metrics()) # pprint(H.caps) plt.plot(H.caps, losses, label='dropout') plt.plot(H_nodrop.caps, losses_nodrop, label='nodrop') plt.plot(H_mlp.caps, losses_mlp, label='mlp') plt.xscale('log') plt.yscale('log') plt.legend(loc='best') plt.show()
import torch.optim as optim import torch.nn as nn import torch.nn.functional as F import numpy as np from datasets import mnist, loader from logger import struct, Logger from train import train, acc_metric, nll_metric H_proto = struct( batch_size=64, val_batch_size=1000, epochs=10, lrs=[ 0.001, 0.003, 0.005, 0.01, 0.02, 0.03, 0.04, 0.05, 0.07, 0.1, 0.3, 0.5, 1 ], momentum=0.5, ) S_proto = struct(epoch=0, bn=0) log = Logger('mnist_lr2', H_proto, S_proto, load=True, metric_show_freq=1) S_proto.epoch = 0 tn_loader, val_loader = loader(mnist(), H_proto.batch_size, H_proto.val_batch_size) for epoch in range(S_proto.epoch, len(H_proto.lrs)): S_proto.epoch = epoch log.flush() lr = H_proto.lrs[epoch] H = H_proto.copy()
import torch.optim as optim import torch.nn as nn import torch.nn.functional as F from datasets import mnist, loader from logger import struct, Logger from train import train H = struct( batch_size=64, val_batch_size=1000, epochs=2, lr=0.01, momentum=0.5, ) S = struct(epoch=1, bn=1) log = Logger('mnist_scratch', H, S, overwrite=True, metric_show_freq=100) tn_loader, val_loader = loader(mnist(), H.batch_size, H.val_batch_size) class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.conv1 = nn.Conv2d(1, 10, kernel_size=5) self.conv2 = nn.Conv2d(10, 20, kernel_size=5) self.conv2_drop = nn.Dropout2d() self.fc1 = nn.Linear(320, 50) self.fc2 = nn.Linear(50, 10) def forward(self, x):
import torch.optim as optim import torch.nn as nn import torch.nn.functional as F from datasets import mnist, loader from logger import struct from train import (cycle_hyperparams, acc_metric, nll_metric, max_metametric, argmax_metametric, min_metametric, argmin_metametric) H_proto = struct(batch_size=64, val_batch_size=1000, epochs=10, lr=0.01, momenta=[0.0, 0.1, 0.3, 0.5, 0.7, 0.9, 0.95, 0.99]) def model(H): class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.conv1 = nn.Conv2d(1, 10, kernel_size=5) self.conv2 = nn.Conv2d(10, 20, kernel_size=5) self.conv2_drop = nn.Dropout2d() self.fc1 = nn.Linear(320, 50) self.fc2 = nn.Linear(50, 10) def forward(self, x): x = F.relu(F.max_pool2d(self.conv1(x), 2)) x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2)) x = x.view(-1, 320) x = F.relu(self.fc1(x)) x = F.dropout(x, training=self.training)
import torch.optim as optim import torch.nn as nn import torch.nn.functional as F from datasets import mnist, loader from logger import struct from train import (cycle_hyperparams, acc_metric, nll_metric, max_metametric, argmax_metametric, min_metametric, argmin_metametric) H_proto = struct(batch_size=64, val_batch_size=1000, epochs=10, lr=0.01, caps=[10, 20, 50, 70, 100, 200, 500], momentum=0.5) def model(H): class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.conv1 = nn.Conv2d(1, 10, kernel_size=5) self.conv2 = nn.Conv2d(10, 20, kernel_size=5) self.conv2_drop = nn.Dropout2d() self.fc1 = nn.Linear(320, H.cap) self.fc2 = nn.Linear(H.cap, 10) def forward(self, x): x = F.relu(F.max_pool2d(self.conv1(x), 2)) x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2)) x = x.view(-1, 320) x = F.relu(self.fc1(x))
import torch.optim as optim import torch.nn as nn import torch.nn.functional as F from datasets import mnist, loader from logger import struct from train import (cycle_hyperparams, acc_metric, nll_metric, max_metametric, argmax_metametric, min_metametric, argmin_metametric) H_proto = struct(batch_size=64, val_batch_size=1000, epochs=10, lrs=[ 0.001, 0.003, 0.005, 0.01, 0.02, 0.03, 0.04, 0.05, 0.07, 0.1, 0.3, 0.5, 1 ], momentum=0.5) def model(H): class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.conv1 = nn.Conv2d(1, 10, kernel_size=5) self.conv2 = nn.Conv2d(10, 20, kernel_size=5) self.conv2_drop = nn.Dropout2d() self.fc1 = nn.Linear(320, 50) self.fc2 = nn.Linear(50, 10) def forward(self, x): x = F.relu(F.max_pool2d(self.conv1(x), 2)) x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2))