text_plain_output_1.png
import numpy as np
import pandas as pd
import os
print(os.listdir('../input'))
import operator
from pathlib import Path
from IPython.core.debugger import set_trace
from fastai import datasets
import pickle, gzip, math, torch, matplotlib as mpl
import matplotlib.pyplot as plt
from torch import tensor, nn
import torch.nn.functional as F
def test(a, b, cmp, cname=None):
    if cname is None:
        cname = cmp.__name__
    assert cmp(a, b), f'{cname}:\n{a}\n{b}'
def test_eq(a, b):
    test(a, b, operator.eq, '==')
def near(a, b):
    return torch.allclose(a, b, 0.001, 1e-05)
def test_near(a, b):
    test(a, b, near)
MNIST_URL = 'http://deeplearning.net/data/mnist/mnist.pkl'
def get_data():
    path = datasets.download_data(MNIST_URL, ext='.gz')
    with gzip.open(path, 'rb') as f:
        (x_train, y_train), (x_valid, y_valid), _ = pickle.load(f, encoding='latin-1')
    return map(tensor, (x_train, y_train, x_valid, y_valid))
def normalize(x, m, s):
    return (x - m) / s