Deep Learning Models -- A collection of various deep learning architectures, models, and tips for TensorFlow and PyTorch in Jupyter Notebooks.

In [1]:
%load_ext watermark
%watermark -a 'Sebastian Raschka' -v -p torch
Sebastian Raschka 

CPython 3.6.8
IPython 7.2.0

torch 1.0.0

Model Zoo -- Multilayer Perceptron From Scratch (Sigmoid activation, MSE Loss)

Implementation of a 1-hidden layer multi-layer perceptron from scratch using

  • sigmoid activation in the hidden layer
  • sigmoid activation in the output layer
  • Mean Squared Error loss function

Imports

In [2]:
import matplotlib.pyplot as plt
import pandas as pd
import torch
%matplotlib inline
In [3]:
import time
import numpy as np
from torchvision import datasets
from torchvision import transforms
from torch.utils.data import DataLoader
import torch.nn.functional as F
import torch

Settings and Dataset

In [4]:
##########################
### SETTINGS
##########################

RANDOM_SEED = 1
BATCH_SIZE = 100
NUM_EPOCHS = 50

##########################
### MNIST DATASET
##########################

# Note transforms.ToTensor() scales input images
# to 0-1 range
train_dataset = datasets.MNIST(root='data', 
                               train=True, 
                               transform=transforms.ToTensor(),
                               download=True)

test_dataset = datasets.MNIST(root='data', 
                              train=False, 
                              transform=transforms.ToTensor())


train_loader = DataLoader(dataset=train_dataset, 
                          batch_size=BATCH_SIZE, 
                          shuffle=True)

test_loader = DataLoader(dataset=test_dataset, 
                         batch_size=BATCH_SIZE, 
                         shuffle=False)

# Checking the dataset
for images, labels in train_loader:  
    print('Image batch dimensions:', images.shape)
    print('Image label dimensions:', labels.shape)
    break
Image batch dimensions: torch.Size([100, 1, 28, 28])
Image label dimensions: torch.Size([100])

Model Implementation

In [5]:
##########################
### MODEL
##########################

class MultilayerPerceptron():

    def __init__(self, num_features, num_hidden, num_classes):
        super(MultilayerPerceptron, self).__init__()
        
        self.num_classes = num_classes
        
        # hidden 1
        self.weight_1 = torch.zeros(num_hidden, num_features, 
                                    dtype=torch.float).normal_(0.0, 0.1)
        self.bias_1 = torch.zeros(num_hidden, dtype=torch.float)
        
        # output
        self.weight_o = torch.zeros(self.num_classes, num_hidden, 
                                    dtype=torch.float).normal_(0.0, 0.1)
        self.bias_o = torch.zeros(self.num_classes, dtype=torch.float)
        
    def forward(self, x):
        # hidden 1
        
        # input dim: [n_hidden, n_features] dot [n_features, n_examples] .T
        # output dim: [n_examples, n_hidden]
        z_1 = torch.mm(x, self.weight_1.t()) + self.bias_1
        a_1 = torch.sigmoid(z_1)

        # hidden 2
        # input dim: [n_classes, n_hidden] dot [n_hidden, n_examples] .T
        # output dim: [n_examples, n_classes]
        z_2 = torch.mm(a_1, self.weight_o.t()) + self.bias_o
        a_2 = torch.sigmoid(z_2)
        return a_1, a_2

    def backward(self, x, a_1, a_2, y):  
    
        #########################
        ### Output layer weights
        #########################
        
        # onehot encoding
        y_onehot = torch.FloatTensor(y.size(0), self.num_classes)
        y_onehot.zero_()
        y_onehot.scatter_(1, y.view(-1, 1).long(), 1)
        

        # Part 1: dLoss/dOutWeights
        ## = dLoss/dOutAct * dOutAct/dOutNet * dOutNet/dOutWeight
        ## where DeltaOut = dLoss/dOutAct * dOutAct/dOutNet
        ## for convenient re-use
        
        # input/output dim: [n_examples, n_classes]
        dloss_da2 = 2.*(a_2 - y_onehot) / y.size(0)

        # input/output dim: [n_examples, n_classes]
        da2_dz2 = a_2 * (1. - a_2) # sigmoid derivative

        # output dim: [n_examples, n_classes]
        delta_out = dloss_da2 * da2_dz2 # "delta (rule) placeholder"

        # gradient for output weights
        
        # [n_examples, n_hidden]
        dz2__dw_out = a_1
        
        # input dim: [n_classlabels, n_examples] dot [n_examples, n_hidden]
        # output dim: [n_classlabels, n_hidden]
        dloss__dw_out = torch.mm(delta_out.t(), dz2__dw_out)
        dloss__db_out = torch.sum(delta_out, dim=0)
        

        #################################        
        # Part 2: dLoss/dHiddenWeights
        ## = DeltaOut * dOutNet/dHiddenAct * dHiddenAct/dHiddenNet * dHiddenNet/dWeight
        
        # [n_classes, n_hidden]
        dz2__a1 = self.weight_o
        
        # output dim: [n_examples, n_hidden]
        dloss_a1 = torch.mm(delta_out, dz2__a1)
        
        # [n_examples, n_hidden]
        da1__dz1 = a_1 * (1. - a_1) # sigmoid derivative
        
        # [n_examples, n_features]
        dz1__dw1 = x
        
        # output dim: [n_hidden, n_features]
        dloss_dw1 = torch.mm((dloss_a1 * da1__dz1).t(), dz1__dw1)
        dloss_db1 = torch.sum((dloss_a1 * da1__dz1), dim=0)

        return dloss__dw_out, dloss__db_out, dloss_dw1, dloss_db1

Training

In [6]:
####################################################
##### Training and evaluation wrappers
###################################################

def to_onehot(y, num_classes):
    y_onehot = torch.FloatTensor(y.size(0), num_classes)
    y_onehot.zero_()
    y_onehot.scatter_(1, y.view(-1, 1).long(), 1).float()
    return y_onehot


def loss_func(targets_onehot, probas_onehot):
    return torch.mean(torch.mean((targets_onehot - probas_onehot)**2, dim=0))


def compute_mse(net, data_loader):
    curr_mse, num_examples = torch.zeros(model.num_classes).float(), 0
    with torch.no_grad():
        for features, targets in data_loader:
            features = features.view(-1, 28*28)
            logits, probas = net.forward(features)
            y_onehot = to_onehot(targets, model.num_classes)
            loss = torch.sum((y_onehot - probas)**2, dim=0)
            num_examples += targets.size(0)
            curr_mse += loss

        curr_mse = torch.mean(curr_mse/num_examples, dim=0)
        return curr_mse


def train(model, data_loader, num_epochs,
          learning_rate=0.1):
    
    minibatch_cost = []
    epoch_cost = []
    
    for e in range(num_epochs):
        
        for batch_idx, (features, targets) in enumerate(train_loader):
            
            features = features.view(-1, 28*28)
            
            #### Compute outputs ####
            a_1, a_2 = model.forward(features)

            #### Compute gradients ####
            dloss__dw_out, dloss__db_out, dloss_dw1, dloss_db1 = \
                model.backward(features, a_1, a_2, targets)

            #### Update weights ####
            model.weight_1 -= learning_rate * dloss_dw1
            model.bias_1 -= learning_rate * dloss_db1
            model.weight_o -= learning_rate * dloss__dw_out
            model.bias_o -= learning_rate * dloss__db_out
            
            #### Logging ####
            curr_cost = loss_func(to_onehot(targets, model.num_classes), a_2)
            minibatch_cost.append(curr_cost)
            if not batch_idx % 50:
                print ('Epoch: %03d/%03d | Batch %03d/%03d | Cost: %.4f' 
                       %(e+1, NUM_EPOCHS, batch_idx, 
                         len(train_loader), curr_cost))
        
        #### Logging ####        
        curr_cost = compute_mse(model, train_loader)
        epoch_cost.append(curr_cost)
        print('Epoch: %03d/%03d |' % (e+1, NUM_EPOCHS), end="")
        print(' Train MSE: %.5f' % curr_cost)

    return minibatch_cost, epoch_cost
In [7]:
####################################################
##### Training 
###################################################

torch.manual_seed(RANDOM_SEED)
model = MultilayerPerceptron(num_features=28*28,
                             num_hidden=50,
                             num_classes=10)

minibatch_cost, epoch_cost = train(model, 
                                   train_loader,
                                   num_epochs=NUM_EPOCHS,
                                   learning_rate=0.1)
Epoch: 001/050 | Batch 000/600 | Cost: 0.2471
Epoch: 001/050 | Batch 050/600 | Cost: 0.0885
Epoch: 001/050 | Batch 100/600 | Cost: 0.0880
Epoch: 001/050 | Batch 150/600 | Cost: 0.0877
Epoch: 001/050 | Batch 200/600 | Cost: 0.0847
Epoch: 001/050 | Batch 250/600 | Cost: 0.0838
Epoch: 001/050 | Batch 300/600 | Cost: 0.0808
Epoch: 001/050 | Batch 350/600 | Cost: 0.0801
Epoch: 001/050 | Batch 400/600 | Cost: 0.0766
Epoch: 001/050 | Batch 450/600 | Cost: 0.0740
Epoch: 001/050 | Batch 500/600 | Cost: 0.0730
Epoch: 001/050 | Batch 550/600 | Cost: 0.0730
Epoch: 001/050 | Train MSE: 0.06566
Epoch: 002/050 | Batch 000/600 | Cost: 0.0644
Epoch: 002/050 | Batch 050/600 | Cost: 0.0637
Epoch: 002/050 | Batch 100/600 | Cost: 0.0600
Epoch: 002/050 | Batch 150/600 | Cost: 0.0580
Epoch: 002/050 | Batch 200/600 | Cost: 0.0541
Epoch: 002/050 | Batch 250/600 | Cost: 0.0546
Epoch: 002/050 | Batch 300/600 | Cost: 0.0547
Epoch: 002/050 | Batch 350/600 | Cost: 0.0488
Epoch: 002/050 | Batch 400/600 | Cost: 0.0515
Epoch: 002/050 | Batch 450/600 | Cost: 0.0476
Epoch: 002/050 | Batch 500/600 | Cost: 0.0486
Epoch: 002/050 | Batch 550/600 | Cost: 0.0447
Epoch: 002/050 | Train MSE: 0.04302
Epoch: 003/050 | Batch 000/600 | Cost: 0.0413
Epoch: 003/050 | Batch 050/600 | Cost: 0.0404
Epoch: 003/050 | Batch 100/600 | Cost: 0.0374
Epoch: 003/050 | Batch 150/600 | Cost: 0.0351
Epoch: 003/050 | Batch 200/600 | Cost: 0.0374
Epoch: 003/050 | Batch 250/600 | Cost: 0.0371
Epoch: 003/050 | Batch 300/600 | Cost: 0.0347
Epoch: 003/050 | Batch 350/600 | Cost: 0.0359
Epoch: 003/050 | Batch 400/600 | Cost: 0.0373
Epoch: 003/050 | Batch 450/600 | Cost: 0.0305
Epoch: 003/050 | Batch 500/600 | Cost: 0.0333
Epoch: 003/050 | Batch 550/600 | Cost: 0.0318
Epoch: 003/050 | Train MSE: 0.03251
Epoch: 004/050 | Batch 000/600 | Cost: 0.0292
Epoch: 004/050 | Batch 050/600 | Cost: 0.0312
Epoch: 004/050 | Batch 100/600 | Cost: 0.0273
Epoch: 004/050 | Batch 150/600 | Cost: 0.0293
Epoch: 004/050 | Batch 200/600 | Cost: 0.0293
Epoch: 004/050 | Batch 250/600 | Cost: 0.0292
Epoch: 004/050 | Batch 300/600 | Cost: 0.0350
Epoch: 004/050 | Batch 350/600 | Cost: 0.0312
Epoch: 004/050 | Batch 400/600 | Cost: 0.0276
Epoch: 004/050 | Batch 450/600 | Cost: 0.0312
Epoch: 004/050 | Batch 500/600 | Cost: 0.0315
Epoch: 004/050 | Batch 550/600 | Cost: 0.0291
Epoch: 004/050 | Train MSE: 0.02692
Epoch: 005/050 | Batch 000/600 | Cost: 0.0282
Epoch: 005/050 | Batch 050/600 | Cost: 0.0264
Epoch: 005/050 | Batch 100/600 | Cost: 0.0231
Epoch: 005/050 | Batch 150/600 | Cost: 0.0242
Epoch: 005/050 | Batch 200/600 | Cost: 0.0260
Epoch: 005/050 | Batch 250/600 | Cost: 0.0215
Epoch: 005/050 | Batch 300/600 | Cost: 0.0294
Epoch: 005/050 | Batch 350/600 | Cost: 0.0220
Epoch: 005/050 | Batch 400/600 | Cost: 0.0246
Epoch: 005/050 | Batch 450/600 | Cost: 0.0229
Epoch: 005/050 | Batch 500/600 | Cost: 0.0289
Epoch: 005/050 | Batch 550/600 | Cost: 0.0240
Epoch: 005/050 | Train MSE: 0.02365
Epoch: 006/050 | Batch 000/600 | Cost: 0.0201
Epoch: 006/050 | Batch 050/600 | Cost: 0.0223
Epoch: 006/050 | Batch 100/600 | Cost: 0.0253
Epoch: 006/050 | Batch 150/600 | Cost: 0.0258
Epoch: 006/050 | Batch 200/600 | Cost: 0.0216
Epoch: 006/050 | Batch 250/600 | Cost: 0.0282
Epoch: 006/050 | Batch 300/600 | Cost: 0.0203
Epoch: 006/050 | Batch 350/600 | Cost: 0.0218
Epoch: 006/050 | Batch 400/600 | Cost: 0.0249
Epoch: 006/050 | Batch 450/600 | Cost: 0.0211
Epoch: 006/050 | Batch 500/600 | Cost: 0.0230
Epoch: 006/050 | Batch 550/600 | Cost: 0.0174
Epoch: 006/050 | Train MSE: 0.02156
Epoch: 007/050 | Batch 000/600 | Cost: 0.0186
Epoch: 007/050 | Batch 050/600 | Cost: 0.0223
Epoch: 007/050 | Batch 100/600 | Cost: 0.0208
Epoch: 007/050 | Batch 150/600 | Cost: 0.0231
Epoch: 007/050 | Batch 200/600 | Cost: 0.0219
Epoch: 007/050 | Batch 250/600 | Cost: 0.0206
Epoch: 007/050 | Batch 300/600 | Cost: 0.0227
Epoch: 007/050 | Batch 350/600 | Cost: 0.0249
Epoch: 007/050 | Batch 400/600 | Cost: 0.0214
Epoch: 007/050 | Batch 450/600 | Cost: 0.0203
Epoch: 007/050 | Batch 500/600 | Cost: 0.0209
Epoch: 007/050 | Batch 550/600 | Cost: 0.0160
Epoch: 007/050 | Train MSE: 0.02006
Epoch: 008/050 | Batch 000/600 | Cost: 0.0171
Epoch: 008/050 | Batch 050/600 | Cost: 0.0232
Epoch: 008/050 | Batch 100/600 | Cost: 0.0227
Epoch: 008/050 | Batch 150/600 | Cost: 0.0156
Epoch: 008/050 | Batch 200/600 | Cost: 0.0157
Epoch: 008/050 | Batch 250/600 | Cost: 0.0189
Epoch: 008/050 | Batch 300/600 | Cost: 0.0154
Epoch: 008/050 | Batch 350/600 | Cost: 0.0213
Epoch: 008/050 | Batch 400/600 | Cost: 0.0158
Epoch: 008/050 | Batch 450/600 | Cost: 0.0201
Epoch: 008/050 | Batch 500/600 | Cost: 0.0176
Epoch: 008/050 | Batch 550/600 | Cost: 0.0254
Epoch: 008/050 | Train MSE: 0.01892
Epoch: 009/050 | Batch 000/600 | Cost: 0.0195
Epoch: 009/050 | Batch 050/600 | Cost: 0.0214
Epoch: 009/050 | Batch 100/600 | Cost: 0.0255
Epoch: 009/050 | Batch 150/600 | Cost: 0.0153
Epoch: 009/050 | Batch 200/600 | Cost: 0.0184
Epoch: 009/050 | Batch 250/600 | Cost: 0.0247
Epoch: 009/050 | Batch 300/600 | Cost: 0.0151
Epoch: 009/050 | Batch 350/600 | Cost: 0.0165
Epoch: 009/050 | Batch 400/600 | Cost: 0.0171
Epoch: 009/050 | Batch 450/600 | Cost: 0.0136
Epoch: 009/050 | Batch 500/600 | Cost: 0.0206
Epoch: 009/050 | Batch 550/600 | Cost: 0.0142
Epoch: 009/050 | Train MSE: 0.01803
Epoch: 010/050 | Batch 000/600 | Cost: 0.0183
Epoch: 010/050 | Batch 050/600 | Cost: 0.0222
Epoch: 010/050 | Batch 100/600 | Cost: 0.0203
Epoch: 010/050 | Batch 150/600 | Cost: 0.0224
Epoch: 010/050 | Batch 200/600 | Cost: 0.0234
Epoch: 010/050 | Batch 250/600 | Cost: 0.0229
Epoch: 010/050 | Batch 300/600 | Cost: 0.0179
Epoch: 010/050 | Batch 350/600 | Cost: 0.0181
Epoch: 010/050 | Batch 400/600 | Cost: 0.0122
Epoch: 010/050 | Batch 450/600 | Cost: 0.0176
Epoch: 010/050 | Batch 500/600 | Cost: 0.0198
Epoch: 010/050 | Batch 550/600 | Cost: 0.0142
Epoch: 010/050 | Train MSE: 0.01727
Epoch: 011/050 | Batch 000/600 | Cost: 0.0156
Epoch: 011/050 | Batch 050/600 | Cost: 0.0178
Epoch: 011/050 | Batch 100/600 | Cost: 0.0102
Epoch: 011/050 | Batch 150/600 | Cost: 0.0188
Epoch: 011/050 | Batch 200/600 | Cost: 0.0177
Epoch: 011/050 | Batch 250/600 | Cost: 0.0196
Epoch: 011/050 | Batch 300/600 | Cost: 0.0115
Epoch: 011/050 | Batch 350/600 | Cost: 0.0109
Epoch: 011/050 | Batch 400/600 | Cost: 0.0212
Epoch: 011/050 | Batch 450/600 | Cost: 0.0162
Epoch: 011/050 | Batch 500/600 | Cost: 0.0139
Epoch: 011/050 | Batch 550/600 | Cost: 0.0144
Epoch: 011/050 | Train MSE: 0.01665
Epoch: 012/050 | Batch 000/600 | Cost: 0.0185
Epoch: 012/050 | Batch 050/600 | Cost: 0.0137
Epoch: 012/050 | Batch 100/600 | Cost: 0.0160
Epoch: 012/050 | Batch 150/600 | Cost: 0.0142
Epoch: 012/050 | Batch 200/600 | Cost: 0.0138
Epoch: 012/050 | Batch 250/600 | Cost: 0.0169
Epoch: 012/050 | Batch 300/600 | Cost: 0.0141
Epoch: 012/050 | Batch 350/600 | Cost: 0.0137
Epoch: 012/050 | Batch 400/600 | Cost: 0.0134
Epoch: 012/050 | Batch 450/600 | Cost: 0.0141
Epoch: 012/050 | Batch 500/600 | Cost: 0.0139
Epoch: 012/050 | Batch 550/600 | Cost: 0.0175
Epoch: 012/050 | Train MSE: 0.01609
Epoch: 013/050 | Batch 000/600 | Cost: 0.0197
Epoch: 013/050 | Batch 050/600 | Cost: 0.0134
Epoch: 013/050 | Batch 100/600 | Cost: 0.0213
Epoch: 013/050 | Batch 150/600 | Cost: 0.0172
Epoch: 013/050 | Batch 200/600 | Cost: 0.0149
Epoch: 013/050 | Batch 250/600 | Cost: 0.0155
Epoch: 013/050 | Batch 300/600 | Cost: 0.0224
Epoch: 013/050 | Batch 350/600 | Cost: 0.0177
Epoch: 013/050 | Batch 400/600 | Cost: 0.0125
Epoch: 013/050 | Batch 450/600 | Cost: 0.0191
Epoch: 013/050 | Batch 500/600 | Cost: 0.0196
Epoch: 013/050 | Batch 550/600 | Cost: 0.0167
Epoch: 013/050 | Train MSE: 0.01561
Epoch: 014/050 | Batch 000/600 | Cost: 0.0206
Epoch: 014/050 | Batch 050/600 | Cost: 0.0139
Epoch: 014/050 | Batch 100/600 | Cost: 0.0145
Epoch: 014/050 | Batch 150/600 | Cost: 0.0210
Epoch: 014/050 | Batch 200/600 | Cost: 0.0113
Epoch: 014/050 | Batch 250/600 | Cost: 0.0160
Epoch: 014/050 | Batch 300/600 | Cost: 0.0188
Epoch: 014/050 | Batch 350/600 | Cost: 0.0247
Epoch: 014/050 | Batch 400/600 | Cost: 0.0208
Epoch: 014/050 | Batch 450/600 | Cost: 0.0170
Epoch: 014/050 | Batch 500/600 | Cost: 0.0148
Epoch: 014/050 | Batch 550/600 | Cost: 0.0197
Epoch: 014/050 | Train MSE: 0.01518
Epoch: 015/050 | Batch 000/600 | Cost: 0.0138
Epoch: 015/050 | Batch 050/600 | Cost: 0.0183
Epoch: 015/050 | Batch 100/600 | Cost: 0.0117
Epoch: 015/050 | Batch 150/600 | Cost: 0.0123
Epoch: 015/050 | Batch 200/600 | Cost: 0.0114
Epoch: 015/050 | Batch 250/600 | Cost: 0.0116
Epoch: 015/050 | Batch 300/600 | Cost: 0.0199
Epoch: 015/050 | Batch 350/600 | Cost: 0.0165
Epoch: 015/050 | Batch 400/600 | Cost: 0.0199
Epoch: 015/050 | Batch 450/600 | Cost: 0.0143
Epoch: 015/050 | Batch 500/600 | Cost: 0.0148
Epoch: 015/050 | Batch 550/600 | Cost: 0.0130
Epoch: 015/050 | Train MSE: 0.01481
Epoch: 016/050 | Batch 000/600 | Cost: 0.0195
Epoch: 016/050 | Batch 050/600 | Cost: 0.0150
Epoch: 016/050 | Batch 100/600 | Cost: 0.0145
Epoch: 016/050 | Batch 150/600 | Cost: 0.0139
Epoch: 016/050 | Batch 200/600 | Cost: 0.0108
Epoch: 016/050 | Batch 250/600 | Cost: 0.0110
Epoch: 016/050 | Batch 300/600 | Cost: 0.0119
Epoch: 016/050 | Batch 350/600 | Cost: 0.0175
Epoch: 016/050 | Batch 400/600 | Cost: 0.0133
Epoch: 016/050 | Batch 450/600 | Cost: 0.0144
Epoch: 016/050 | Batch 500/600 | Cost: 0.0168
Epoch: 016/050 | Batch 550/600 | Cost: 0.0131
Epoch: 016/050 | Train MSE: 0.01447
Epoch: 017/050 | Batch 000/600 | Cost: 0.0128
Epoch: 017/050 | Batch 050/600 | Cost: 0.0160
Epoch: 017/050 | Batch 100/600 | Cost: 0.0183
Epoch: 017/050 | Batch 150/600 | Cost: 0.0136
Epoch: 017/050 | Batch 200/600 | Cost: 0.0144
Epoch: 017/050 | Batch 250/600 | Cost: 0.0109
Epoch: 017/050 | Batch 300/600 | Cost: 0.0104
Epoch: 017/050 | Batch 350/600 | Cost: 0.0146
Epoch: 017/050 | Batch 400/600 | Cost: 0.0099
Epoch: 017/050 | Batch 450/600 | Cost: 0.0096
Epoch: 017/050 | Batch 500/600 | Cost: 0.0145
Epoch: 017/050 | Batch 550/600 | Cost: 0.0160
Epoch: 017/050 | Train MSE: 0.01415
Epoch: 018/050 | Batch 000/600 | Cost: 0.0140
Epoch: 018/050 | Batch 050/600 | Cost: 0.0145
Epoch: 018/050 | Batch 100/600 | Cost: 0.0167
Epoch: 018/050 | Batch 150/600 | Cost: 0.0136
Epoch: 018/050 | Batch 200/600 | Cost: 0.0102
Epoch: 018/050 | Batch 250/600 | Cost: 0.0164
Epoch: 018/050 | Batch 300/600 | Cost: 0.0094
Epoch: 018/050 | Batch 350/600 | Cost: 0.0169
Epoch: 018/050 | Batch 400/600 | Cost: 0.0108
Epoch: 018/050 | Batch 450/600 | Cost: 0.0155
Epoch: 018/050 | Batch 500/600 | Cost: 0.0106
Epoch: 018/050 | Batch 550/600 | Cost: 0.0143
Epoch: 018/050 | Train MSE: 0.01386
Epoch: 019/050 | Batch 000/600 | Cost: 0.0226
Epoch: 019/050 | Batch 050/600 | Cost: 0.0175
Epoch: 019/050 | Batch 100/600 | Cost: 0.0165
Epoch: 019/050 | Batch 150/600 | Cost: 0.0118
Epoch: 019/050 | Batch 200/600 | Cost: 0.0174
Epoch: 019/050 | Batch 250/600 | Cost: 0.0132
Epoch: 019/050 | Batch 300/600 | Cost: 0.0136
Epoch: 019/050 | Batch 350/600 | Cost: 0.0090
Epoch: 019/050 | Batch 400/600 | Cost: 0.0064
Epoch: 019/050 | Batch 450/600 | Cost: 0.0168
Epoch: 019/050 | Batch 500/600 | Cost: 0.0135
Epoch: 019/050 | Batch 550/600 | Cost: 0.0166
Epoch: 019/050 | Train MSE: 0.01360
Epoch: 020/050 | Batch 000/600 | Cost: 0.0184
Epoch: 020/050 | Batch 050/600 | Cost: 0.0124
Epoch: 020/050 | Batch 100/600 | Cost: 0.0142
Epoch: 020/050 | Batch 150/600 | Cost: 0.0167
Epoch: 020/050 | Batch 200/600 | Cost: 0.0140
Epoch: 020/050 | Batch 250/600 | Cost: 0.0112
Epoch: 020/050 | Batch 300/600 | Cost: 0.0140
Epoch: 020/050 | Batch 350/600 | Cost: 0.0115
Epoch: 020/050 | Batch 400/600 | Cost: 0.0106
Epoch: 020/050 | Batch 450/600 | Cost: 0.0156
Epoch: 020/050 | Batch 500/600 | Cost: 0.0150
Epoch: 020/050 | Batch 550/600 | Cost: 0.0113
Epoch: 020/050 | Train MSE: 0.01335
Epoch: 021/050 | Batch 000/600 | Cost: 0.0127
Epoch: 021/050 | Batch 050/600 | Cost: 0.0100
Epoch: 021/050 | Batch 100/600 | Cost: 0.0183
Epoch: 021/050 | Batch 150/600 | Cost: 0.0138
Epoch: 021/050 | Batch 200/600 | Cost: 0.0120
Epoch: 021/050 | Batch 250/600 | Cost: 0.0115
Epoch: 021/050 | Batch 300/600 | Cost: 0.0125
Epoch: 021/050 | Batch 350/600 | Cost: 0.0085
Epoch: 021/050 | Batch 400/600 | Cost: 0.0121
Epoch: 021/050 | Batch 450/600 | Cost: 0.0140
Epoch: 021/050 | Batch 500/600 | Cost: 0.0098
Epoch: 021/050 | Batch 550/600 | Cost: 0.0145
Epoch: 021/050 | Train MSE: 0.01312
Epoch: 022/050 | Batch 000/600 | Cost: 0.0141
Epoch: 022/050 | Batch 050/600 | Cost: 0.0147
Epoch: 022/050 | Batch 100/600 | Cost: 0.0172
Epoch: 022/050 | Batch 150/600 | Cost: 0.0161
Epoch: 022/050 | Batch 200/600 | Cost: 0.0108
Epoch: 022/050 | Batch 250/600 | Cost: 0.0108
Epoch: 022/050 | Batch 300/600 | Cost: 0.0149
Epoch: 022/050 | Batch 350/600 | Cost: 0.0133
Epoch: 022/050 | Batch 400/600 | Cost: 0.0077
Epoch: 022/050 | Batch 450/600 | Cost: 0.0101
Epoch: 022/050 | Batch 500/600 | Cost: 0.0177
Epoch: 022/050 | Batch 550/600 | Cost: 0.0120
Epoch: 022/050 | Train MSE: 0.01291
Epoch: 023/050 | Batch 000/600 | Cost: 0.0165
Epoch: 023/050 | Batch 050/600 | Cost: 0.0132
Epoch: 023/050 | Batch 100/600 | Cost: 0.0169
Epoch: 023/050 | Batch 150/600 | Cost: 0.0135
Epoch: 023/050 | Batch 200/600 | Cost: 0.0133
Epoch: 023/050 | Batch 250/600 | Cost: 0.0137
Epoch: 023/050 | Batch 300/600 | Cost: 0.0149
Epoch: 023/050 | Batch 350/600 | Cost: 0.0185
Epoch: 023/050 | Batch 400/600 | Cost: 0.0091
Epoch: 023/050 | Batch 450/600 | Cost: 0.0141
Epoch: 023/050 | Batch 500/600 | Cost: 0.0170
Epoch: 023/050 | Batch 550/600 | Cost: 0.0096
Epoch: 023/050 | Train MSE: 0.01270
Epoch: 024/050 | Batch 000/600 | Cost: 0.0122
Epoch: 024/050 | Batch 050/600 | Cost: 0.0095
Epoch: 024/050 | Batch 100/600 | Cost: 0.0099
Epoch: 024/050 | Batch 150/600 | Cost: 0.0063
Epoch: 024/050 | Batch 200/600 | Cost: 0.0133
Epoch: 024/050 | Batch 250/600 | Cost: 0.0108
Epoch: 024/050 | Batch 300/600 | Cost: 0.0149
Epoch: 024/050 | Batch 350/600 | Cost: 0.0143
Epoch: 024/050 | Batch 400/600 | Cost: 0.0124
Epoch: 024/050 | Batch 450/600 | Cost: 0.0116
Epoch: 024/050 | Batch 500/600 | Cost: 0.0083
Epoch: 024/050 | Batch 550/600 | Cost: 0.0079
Epoch: 024/050 | Train MSE: 0.01251
Epoch: 025/050 | Batch 000/600 | Cost: 0.0147
Epoch: 025/050 | Batch 050/600 | Cost: 0.0104
Epoch: 025/050 | Batch 100/600 | Cost: 0.0120
Epoch: 025/050 | Batch 150/600 | Cost: 0.0127
Epoch: 025/050 | Batch 200/600 | Cost: 0.0094
Epoch: 025/050 | Batch 250/600 | Cost: 0.0085
Epoch: 025/050 | Batch 300/600 | Cost: 0.0138
Epoch: 025/050 | Batch 350/600 | Cost: 0.0086
Epoch: 025/050 | Batch 400/600 | Cost: 0.0130
Epoch: 025/050 | Batch 450/600 | Cost: 0.0136
Epoch: 025/050 | Batch 500/600 | Cost: 0.0135
Epoch: 025/050 | Batch 550/600 | Cost: 0.0155
Epoch: 025/050 | Train MSE: 0.01232
Epoch: 026/050 | Batch 000/600 | Cost: 0.0138
Epoch: 026/050 | Batch 050/600 | Cost: 0.0136
Epoch: 026/050 | Batch 100/600 | Cost: 0.0076
Epoch: 026/050 | Batch 150/600 | Cost: 0.0179
Epoch: 026/050 | Batch 200/600 | Cost: 0.0119
Epoch: 026/050 | Batch 250/600 | Cost: 0.0142
Epoch: 026/050 | Batch 300/600 | Cost: 0.0138
Epoch: 026/050 | Batch 350/600 | Cost: 0.0107
Epoch: 026/050 | Batch 400/600 | Cost: 0.0103
Epoch: 026/050 | Batch 450/600 | Cost: 0.0091
Epoch: 026/050 | Batch 500/600 | Cost: 0.0116
Epoch: 026/050 | Batch 550/600 | Cost: 0.0091
Epoch: 026/050 | Train MSE: 0.01215
Epoch: 027/050 | Batch 000/600 | Cost: 0.0085
Epoch: 027/050 | Batch 050/600 | Cost: 0.0065
Epoch: 027/050 | Batch 100/600 | Cost: 0.0102
Epoch: 027/050 | Batch 150/600 | Cost: 0.0152
Epoch: 027/050 | Batch 200/600 | Cost: 0.0162
Epoch: 027/050 | Batch 250/600 | Cost: 0.0079
Epoch: 027/050 | Batch 300/600 | Cost: 0.0118
Epoch: 027/050 | Batch 350/600 | Cost: 0.0111
Epoch: 027/050 | Batch 400/600 | Cost: 0.0081
Epoch: 027/050 | Batch 450/600 | Cost: 0.0100
Epoch: 027/050 | Batch 500/600 | Cost: 0.0103
Epoch: 027/050 | Batch 550/600 | Cost: 0.0117
Epoch: 027/050 | Train MSE: 0.01199
Epoch: 028/050 | Batch 000/600 | Cost: 0.0077
Epoch: 028/050 | Batch 050/600 | Cost: 0.0164
Epoch: 028/050 | Batch 100/600 | Cost: 0.0095
Epoch: 028/050 | Batch 150/600 | Cost: 0.0112
Epoch: 028/050 | Batch 200/600 | Cost: 0.0109
Epoch: 028/050 | Batch 250/600 | Cost: 0.0148
Epoch: 028/050 | Batch 300/600 | Cost: 0.0126
Epoch: 028/050 | Batch 350/600 | Cost: 0.0082
Epoch: 028/050 | Batch 400/600 | Cost: 0.0115
Epoch: 028/050 | Batch 450/600 | Cost: 0.0194
Epoch: 028/050 | Batch 500/600 | Cost: 0.0111
Epoch: 028/050 | Batch 550/600 | Cost: 0.0145
Epoch: 028/050 | Train MSE: 0.01181
Epoch: 029/050 | Batch 000/600 | Cost: 0.0112
Epoch: 029/050 | Batch 050/600 | Cost: 0.0137
Epoch: 029/050 | Batch 100/600 | Cost: 0.0192
Epoch: 029/050 | Batch 150/600 | Cost: 0.0105
Epoch: 029/050 | Batch 200/600 | Cost: 0.0107
Epoch: 029/050 | Batch 250/600 | Cost: 0.0081
Epoch: 029/050 | Batch 300/600 | Cost: 0.0079
Epoch: 029/050 | Batch 350/600 | Cost: 0.0126
Epoch: 029/050 | Batch 400/600 | Cost: 0.0135
Epoch: 029/050 | Batch 450/600 | Cost: 0.0062
Epoch: 029/050 | Batch 500/600 | Cost: 0.0121
Epoch: 029/050 | Batch 550/600 | Cost: 0.0091
Epoch: 029/050 | Train MSE: 0.01167
Epoch: 030/050 | Batch 000/600 | Cost: 0.0068
Epoch: 030/050 | Batch 050/600 | Cost: 0.0115
Epoch: 030/050 | Batch 100/600 | Cost: 0.0145
Epoch: 030/050 | Batch 150/600 | Cost: 0.0128
Epoch: 030/050 | Batch 200/600 | Cost: 0.0129
Epoch: 030/050 | Batch 250/600 | Cost: 0.0128
Epoch: 030/050 | Batch 300/600 | Cost: 0.0085
Epoch: 030/050 | Batch 350/600 | Cost: 0.0149
Epoch: 030/050 | Batch 400/600 | Cost: 0.0080
Epoch: 030/050 | Batch 450/600 | Cost: 0.0168
Epoch: 030/050 | Batch 500/600 | Cost: 0.0106
Epoch: 030/050 | Batch 550/600 | Cost: 0.0125
Epoch: 030/050 | Train MSE: 0.01152
Epoch: 031/050 | Batch 000/600 | Cost: 0.0137
Epoch: 031/050 | Batch 050/600 | Cost: 0.0080
Epoch: 031/050 | Batch 100/600 | Cost: 0.0122
Epoch: 031/050 | Batch 150/600 | Cost: 0.0121
Epoch: 031/050 | Batch 200/600 | Cost: 0.0125
Epoch: 031/050 | Batch 250/600 | Cost: 0.0120
Epoch: 031/050 | Batch 300/600 | Cost: 0.0123
Epoch: 031/050 | Batch 350/600 | Cost: 0.0166
Epoch: 031/050 | Batch 400/600 | Cost: 0.0099
Epoch: 031/050 | Batch 450/600 | Cost: 0.0099
Epoch: 031/050 | Batch 500/600 | Cost: 0.0103
Epoch: 031/050 | Batch 550/600 | Cost: 0.0099
Epoch: 031/050 | Train MSE: 0.01138
Epoch: 032/050 | Batch 000/600 | Cost: 0.0125
Epoch: 032/050 | Batch 050/600 | Cost: 0.0114
Epoch: 032/050 | Batch 100/600 | Cost: 0.0118
Epoch: 032/050 | Batch 150/600 | Cost: 0.0110
Epoch: 032/050 | Batch 200/600 | Cost: 0.0137
Epoch: 032/050 | Batch 250/600 | Cost: 0.0156
Epoch: 032/050 | Batch 300/600 | Cost: 0.0084
Epoch: 032/050 | Batch 350/600 | Cost: 0.0187
Epoch: 032/050 | Batch 400/600 | Cost: 0.0101
Epoch: 032/050 | Batch 450/600 | Cost: 0.0071
Epoch: 032/050 | Batch 500/600 | Cost: 0.0104
Epoch: 032/050 | Batch 550/600 | Cost: 0.0135
Epoch: 032/050 | Train MSE: 0.01126
Epoch: 033/050 | Batch 000/600 | Cost: 0.0159
Epoch: 033/050 | Batch 050/600 | Cost: 0.0126
Epoch: 033/050 | Batch 100/600 | Cost: 0.0077
Epoch: 033/050 | Batch 150/600 | Cost: 0.0093
Epoch: 033/050 | Batch 200/600 | Cost: 0.0092
Epoch: 033/050 | Batch 250/600 | Cost: 0.0128
Epoch: 033/050 | Batch 300/600 | Cost: 0.0095
Epoch: 033/050 | Batch 350/600 | Cost: 0.0108
Epoch: 033/050 | Batch 400/600 | Cost: 0.0116
Epoch: 033/050 | Batch 450/600 | Cost: 0.0082
Epoch: 033/050 | Batch 500/600 | Cost: 0.0151
Epoch: 033/050 | Batch 550/600 | Cost: 0.0097
Epoch: 033/050 | Train MSE: 0.01112
Epoch: 034/050 | Batch 000/600 | Cost: 0.0119
Epoch: 034/050 | Batch 050/600 | Cost: 0.0079
Epoch: 034/050 | Batch 100/600 | Cost: 0.0118
Epoch: 034/050 | Batch 150/600 | Cost: 0.0122
Epoch: 034/050 | Batch 200/600 | Cost: 0.0078
Epoch: 034/050 | Batch 250/600 | Cost: 0.0142
Epoch: 034/050 | Batch 300/600 | Cost: 0.0066
Epoch: 034/050 | Batch 350/600 | Cost: 0.0112
Epoch: 034/050 | Batch 400/600 | Cost: 0.0067
Epoch: 034/050 | Batch 450/600 | Cost: 0.0105
Epoch: 034/050 | Batch 500/600 | Cost: 0.0119
Epoch: 034/050 | Batch 550/600 | Cost: 0.0145
Epoch: 034/050 | Train MSE: 0.01099
Epoch: 035/050 | Batch 000/600 | Cost: 0.0100
Epoch: 035/050 | Batch 050/600 | Cost: 0.0072
Epoch: 035/050 | Batch 100/600 | Cost: 0.0071
Epoch: 035/050 | Batch 150/600 | Cost: 0.0111
Epoch: 035/050 | Batch 200/600 | Cost: 0.0096
Epoch: 035/050 | Batch 250/600 | Cost: 0.0089
Epoch: 035/050 | Batch 300/600 | Cost: 0.0098
Epoch: 035/050 | Batch 350/600 | Cost: 0.0116
Epoch: 035/050 | Batch 400/600 | Cost: 0.0128
Epoch: 035/050 | Batch 450/600 | Cost: 0.0091
Epoch: 035/050 | Batch 500/600 | Cost: 0.0093
Epoch: 035/050 | Batch 550/600 | Cost: 0.0103
Epoch: 035/050 | Train MSE: 0.01088
Epoch: 036/050 | Batch 000/600 | Cost: 0.0065
Epoch: 036/050 | Batch 050/600 | Cost: 0.0164
Epoch: 036/050 | Batch 100/600 | Cost: 0.0118
Epoch: 036/050 | Batch 150/600 | Cost: 0.0075
Epoch: 036/050 | Batch 200/600 | Cost: 0.0193
Epoch: 036/050 | Batch 250/600 | Cost: 0.0208
Epoch: 036/050 | Batch 300/600 | Cost: 0.0096
Epoch: 036/050 | Batch 350/600 | Cost: 0.0084
Epoch: 036/050 | Batch 400/600 | Cost: 0.0096
Epoch: 036/050 | Batch 450/600 | Cost: 0.0109
Epoch: 036/050 | Batch 500/600 | Cost: 0.0104
Epoch: 036/050 | Batch 550/600 | Cost: 0.0063
Epoch: 036/050 | Train MSE: 0.01076
Epoch: 037/050 | Batch 000/600 | Cost: 0.0092
Epoch: 037/050 | Batch 050/600 | Cost: 0.0120
Epoch: 037/050 | Batch 100/600 | Cost: 0.0107
Epoch: 037/050 | Batch 150/600 | Cost: 0.0139
Epoch: 037/050 | Batch 200/600 | Cost: 0.0127
Epoch: 037/050 | Batch 250/600 | Cost: 0.0082
Epoch: 037/050 | Batch 300/600 | Cost: 0.0073
Epoch: 037/050 | Batch 350/600 | Cost: 0.0072
Epoch: 037/050 | Batch 400/600 | Cost: 0.0083
Epoch: 037/050 | Batch 450/600 | Cost: 0.0087
Epoch: 037/050 | Batch 500/600 | Cost: 0.0187
Epoch: 037/050 | Batch 550/600 | Cost: 0.0128
Epoch: 037/050 | Train MSE: 0.01064
Epoch: 038/050 | Batch 000/600 | Cost: 0.0145
Epoch: 038/050 | Batch 050/600 | Cost: 0.0082
Epoch: 038/050 | Batch 100/600 | Cost: 0.0116
Epoch: 038/050 | Batch 150/600 | Cost: 0.0114
Epoch: 038/050 | Batch 200/600 | Cost: 0.0089
Epoch: 038/050 | Batch 250/600 | Cost: 0.0110
Epoch: 038/050 | Batch 300/600 | Cost: 0.0130
Epoch: 038/050 | Batch 350/600 | Cost: 0.0155
Epoch: 038/050 | Batch 400/600 | Cost: 0.0107
Epoch: 038/050 | Batch 450/600 | Cost: 0.0076
Epoch: 038/050 | Batch 500/600 | Cost: 0.0138
Epoch: 038/050 | Batch 550/600 | Cost: 0.0123
Epoch: 038/050 | Train MSE: 0.01054
Epoch: 039/050 | Batch 000/600 | Cost: 0.0106
Epoch: 039/050 | Batch 050/600 | Cost: 0.0153
Epoch: 039/050 | Batch 100/600 | Cost: 0.0108
Epoch: 039/050 | Batch 150/600 | Cost: 0.0097
Epoch: 039/050 | Batch 200/600 | Cost: 0.0116
Epoch: 039/050 | Batch 250/600 | Cost: 0.0123
Epoch: 039/050 | Batch 300/600 | Cost: 0.0082
Epoch: 039/050 | Batch 350/600 | Cost: 0.0114
Epoch: 039/050 | Batch 400/600 | Cost: 0.0083
Epoch: 039/050 | Batch 450/600 | Cost: 0.0162
Epoch: 039/050 | Batch 500/600 | Cost: 0.0108
Epoch: 039/050 | Batch 550/600 | Cost: 0.0110
Epoch: 039/050 | Train MSE: 0.01043
Epoch: 040/050 | Batch 000/600 | Cost: 0.0121
Epoch: 040/050 | Batch 050/600 | Cost: 0.0137
Epoch: 040/050 | Batch 100/600 | Cost: 0.0094
Epoch: 040/050 | Batch 150/600 | Cost: 0.0080
Epoch: 040/050 | Batch 200/600 | Cost: 0.0107
Epoch: 040/050 | Batch 250/600 | Cost: 0.0092
Epoch: 040/050 | Batch 300/600 | Cost: 0.0088
Epoch: 040/050 | Batch 350/600 | Cost: 0.0097
Epoch: 040/050 | Batch 400/600 | Cost: 0.0084
Epoch: 040/050 | Batch 450/600 | Cost: 0.0134
Epoch: 040/050 | Batch 500/600 | Cost: 0.0144
Epoch: 040/050 | Batch 550/600 | Cost: 0.0094
Epoch: 040/050 | Train MSE: 0.01033
Epoch: 041/050 | Batch 000/600 | Cost: 0.0112
Epoch: 041/050 | Batch 050/600 | Cost: 0.0063
Epoch: 041/050 | Batch 100/600 | Cost: 0.0117
Epoch: 041/050 | Batch 150/600 | Cost: 0.0126
Epoch: 041/050 | Batch 200/600 | Cost: 0.0181
Epoch: 041/050 | Batch 250/600 | Cost: 0.0158
Epoch: 041/050 | Batch 300/600 | Cost: 0.0140
Epoch: 041/050 | Batch 350/600 | Cost: 0.0109
Epoch: 041/050 | Batch 400/600 | Cost: 0.0105
Epoch: 041/050 | Batch 450/600 | Cost: 0.0130
Epoch: 041/050 | Batch 500/600 | Cost: 0.0081
Epoch: 041/050 | Batch 550/600 | Cost: 0.0126
Epoch: 041/050 | Train MSE: 0.01023
Epoch: 042/050 | Batch 000/600 | Cost: 0.0100
Epoch: 042/050 | Batch 050/600 | Cost: 0.0114
Epoch: 042/050 | Batch 100/600 | Cost: 0.0109
Epoch: 042/050 | Batch 150/600 | Cost: 0.0066
Epoch: 042/050 | Batch 200/600 | Cost: 0.0080
Epoch: 042/050 | Batch 250/600 | Cost: 0.0101
Epoch: 042/050 | Batch 300/600 | Cost: 0.0122
Epoch: 042/050 | Batch 350/600 | Cost: 0.0108
Epoch: 042/050 | Batch 400/600 | Cost: 0.0088
Epoch: 042/050 | Batch 450/600 | Cost: 0.0132
Epoch: 042/050 | Batch 500/600 | Cost: 0.0103
Epoch: 042/050 | Batch 550/600 | Cost: 0.0083
Epoch: 042/050 | Train MSE: 0.01013
Epoch: 043/050 | Batch 000/600 | Cost: 0.0097
Epoch: 043/050 | Batch 050/600 | Cost: 0.0103
Epoch: 043/050 | Batch 100/600 | Cost: 0.0144
Epoch: 043/050 | Batch 150/600 | Cost: 0.0095
Epoch: 043/050 | Batch 200/600 | Cost: 0.0108
Epoch: 043/050 | Batch 250/600 | Cost: 0.0124
Epoch: 043/050 | Batch 300/600 | Cost: 0.0125
Epoch: 043/050 | Batch 350/600 | Cost: 0.0117
Epoch: 043/050 | Batch 400/600 | Cost: 0.0085
Epoch: 043/050 | Batch 450/600 | Cost: 0.0097
Epoch: 043/050 | Batch 500/600 | Cost: 0.0163
Epoch: 043/050 | Batch 550/600 | Cost: 0.0099
Epoch: 043/050 | Train MSE: 0.01005
Epoch: 044/050 | Batch 000/600 | Cost: 0.0090
Epoch: 044/050 | Batch 050/600 | Cost: 0.0079
Epoch: 044/050 | Batch 100/600 | Cost: 0.0089
Epoch: 044/050 | Batch 150/600 | Cost: 0.0110
Epoch: 044/050 | Batch 200/600 | Cost: 0.0072
Epoch: 044/050 | Batch 250/600 | Cost: 0.0089
Epoch: 044/050 | Batch 300/600 | Cost: 0.0138
Epoch: 044/050 | Batch 350/600 | Cost: 0.0069
Epoch: 044/050 | Batch 400/600 | Cost: 0.0086
Epoch: 044/050 | Batch 450/600 | Cost: 0.0100
Epoch: 044/050 | Batch 500/600 | Cost: 0.0076
Epoch: 044/050 | Batch 550/600 | Cost: 0.0076
Epoch: 044/050 | Train MSE: 0.00995
Epoch: 045/050 | Batch 000/600 | Cost: 0.0098
Epoch: 045/050 | Batch 050/600 | Cost: 0.0064
Epoch: 045/050 | Batch 100/600 | Cost: 0.0097
Epoch: 045/050 | Batch 150/600 | Cost: 0.0077
Epoch: 045/050 | Batch 200/600 | Cost: 0.0136
Epoch: 045/050 | Batch 250/600 | Cost: 0.0181
Epoch: 045/050 | Batch 300/600 | Cost: 0.0085
Epoch: 045/050 | Batch 350/600 | Cost: 0.0102
Epoch: 045/050 | Batch 400/600 | Cost: 0.0058
Epoch: 045/050 | Batch 450/600 | Cost: 0.0099
Epoch: 045/050 | Batch 500/600 | Cost: 0.0061
Epoch: 045/050 | Batch 550/600 | Cost: 0.0077
Epoch: 045/050 | Train MSE: 0.00986
Epoch: 046/050 | Batch 000/600 | Cost: 0.0074
Epoch: 046/050 | Batch 050/600 | Cost: 0.0109
Epoch: 046/050 | Batch 100/600 | Cost: 0.0090
Epoch: 046/050 | Batch 150/600 | Cost: 0.0079
Epoch: 046/050 | Batch 200/600 | Cost: 0.0085
Epoch: 046/050 | Batch 250/600 | Cost: 0.0104
Epoch: 046/050 | Batch 300/600 | Cost: 0.0121
Epoch: 046/050 | Batch 350/600 | Cost: 0.0101
Epoch: 046/050 | Batch 400/600 | Cost: 0.0091
Epoch: 046/050 | Batch 450/600 | Cost: 0.0114
Epoch: 046/050 | Batch 500/600 | Cost: 0.0082
Epoch: 046/050 | Batch 550/600 | Cost: 0.0104
Epoch: 046/050 | Train MSE: 0.00978
Epoch: 047/050 | Batch 000/600 | Cost: 0.0109
Epoch: 047/050 | Batch 050/600 | Cost: 0.0111
Epoch: 047/050 | Batch 100/600 | Cost: 0.0075
Epoch: 047/050 | Batch 150/600 | Cost: 0.0144
Epoch: 047/050 | Batch 200/600 | Cost: 0.0092
Epoch: 047/050 | Batch 250/600 | Cost: 0.0080
Epoch: 047/050 | Batch 300/600 | Cost: 0.0118
Epoch: 047/050 | Batch 350/600 | Cost: 0.0110
Epoch: 047/050 | Batch 400/600 | Cost: 0.0038
Epoch: 047/050 | Batch 450/600 | Cost: 0.0159
Epoch: 047/050 | Batch 500/600 | Cost: 0.0084
Epoch: 047/050 | Batch 550/600 | Cost: 0.0110
Epoch: 047/050 | Train MSE: 0.00969
Epoch: 048/050 | Batch 000/600 | Cost: 0.0071
Epoch: 048/050 | Batch 050/600 | Cost: 0.0095
Epoch: 048/050 | Batch 100/600 | Cost: 0.0093
Epoch: 048/050 | Batch 150/600 | Cost: 0.0144
Epoch: 048/050 | Batch 200/600 | Cost: 0.0123
Epoch: 048/050 | Batch 250/600 | Cost: 0.0070
Epoch: 048/050 | Batch 300/600 | Cost: 0.0107
Epoch: 048/050 | Batch 350/600 | Cost: 0.0123
Epoch: 048/050 | Batch 400/600 | Cost: 0.0064
Epoch: 048/050 | Batch 450/600 | Cost: 0.0129
Epoch: 048/050 | Batch 500/600 | Cost: 0.0065
Epoch: 048/050 | Batch 550/600 | Cost: 0.0121
Epoch: 048/050 | Train MSE: 0.00961
Epoch: 049/050 | Batch 000/600 | Cost: 0.0031
Epoch: 049/050 | Batch 050/600 | Cost: 0.0115
Epoch: 049/050 | Batch 100/600 | Cost: 0.0046
Epoch: 049/050 | Batch 150/600 | Cost: 0.0104
Epoch: 049/050 | Batch 200/600 | Cost: 0.0070
Epoch: 049/050 | Batch 250/600 | Cost: 0.0056
Epoch: 049/050 | Batch 300/600 | Cost: 0.0114
Epoch: 049/050 | Batch 350/600 | Cost: 0.0099
Epoch: 049/050 | Batch 400/600 | Cost: 0.0110
Epoch: 049/050 | Batch 450/600 | Cost: 0.0077
Epoch: 049/050 | Batch 500/600 | Cost: 0.0071
Epoch: 049/050 | Batch 550/600 | Cost: 0.0120
Epoch: 049/050 | Train MSE: 0.00953
Epoch: 050/050 | Batch 000/600 | Cost: 0.0113
Epoch: 050/050 | Batch 050/600 | Cost: 0.0132
Epoch: 050/050 | Batch 100/600 | Cost: 0.0060
Epoch: 050/050 | Batch 150/600 | Cost: 0.0071
Epoch: 050/050 | Batch 200/600 | Cost: 0.0069
Epoch: 050/050 | Batch 250/600 | Cost: 0.0151
Epoch: 050/050 | Batch 300/600 | Cost: 0.0106
Epoch: 050/050 | Batch 350/600 | Cost: 0.0122
Epoch: 050/050 | Batch 400/600 | Cost: 0.0081
Epoch: 050/050 | Batch 450/600 | Cost: 0.0095
Epoch: 050/050 | Batch 500/600 | Cost: 0.0122
Epoch: 050/050 | Batch 550/600 | Cost: 0.0075
Epoch: 050/050 | Train MSE: 0.00945

Evaluation

In [8]:
plt.plot(range(len(minibatch_cost)), minibatch_cost)
plt.ylabel('Mean Squared Error')
plt.xlabel('Minibatch')
plt.show()

plt.plot(range(len(epoch_cost)), epoch_cost)
plt.ylabel('Mean Squared Error')
plt.xlabel('Epoch')
plt.show()
In [9]:
def compute_accuracy(net, data_loader):
    correct_pred, num_examples = 0, 0
    with torch.no_grad():
        for features, targets in data_loader:
            features = features.view(-1, 28*28)
            _, outputs = net.forward(features)
            predicted_labels = torch.argmax(outputs, 1)
            num_examples += targets.size(0)
            correct_pred += (predicted_labels == targets).sum()
        return correct_pred.float()/num_examples * 100
    
print('Training Accuracy: %.2f' % compute_accuracy(model, train_loader))
print('Test Accuracy: %.2f' % compute_accuracy(model, test_loader))
Training Accuracy: 94.72
Test Accuracy: 94.49

Visual Inspection

In [10]:
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
In [11]:
for features, targets in test_loader:
    break
    
fig, ax = plt.subplots(1, 4)
for i in range(4):
    ax[i].imshow(features[i].view(28, 28), cmap=matplotlib.cm.binary)

plt.show()
In [12]:
_, predictions = model.forward(features[:4].view(-1, 28*28))
predictions = torch.argmax(predictions, dim=1)
print('Predicted labels', predictions)
Predicted labels tensor([7, 2, 1, 0])