This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fire | |
import matplotlib.pyplot as plt | |
from matplotlib import rcParams | |
default_style = { | |
'font.family': 'monospace', | |
'font.size': 18, | |
'figure.figsize': (8, 6) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""plotter.py generates simple plots configured from standard input or JSON. | |
A user is required to provide list of points to be plotted and canvas | |
parameters to define image rendering style properties. | |
examples: | |
$ python plotter.py stdin -p '1,2;2,3' | |
$ python plotter.py stdin -p '1,1;2,2;3,3' -o plot -f svg --show-grid | |
$ python plotter.py json -j path/to/the/config.json | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from argparse import ArgumentParser, ArgumentError, ArgumentTypeError | |
from functools import partial | |
import json | |
from os.path import exists | |
import matplotlib.pyplot as plt | |
def main(): | |
parser = create_parser() | |
args = parser.parse_args() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from argparse import ArgumentParser, ArgumentTypeError | |
import matplotlib.pyplot as plt | |
def main(): | |
parser = ArgumentParser() | |
parser.add_argument( | |
'-p', '--points', | |
type=list_of_points, | |
metavar='PTS', required=True, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import matplotlib.pyplot as plt | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
'-p', '--points', | |
metavar='PTS', required=True, | |
help='List of points to plot' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StreamLogger(Callback): | |
def __init__(self, streams=None, log_every=1): | |
self.streams = streams or [sys.stdout] | |
self.log_every = log_every | |
def epoch_ended(self, phases, epoch, **kwargs): | |
if epoch % self.log_every != 0: | |
return | |
metrics = merge_dicts([phase.last_metrics for phase in phases]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data_path = Path.home()/'data'/'mnist' | |
mnist_stats = ((0.15,), (0.15,)) | |
epochs = 3 | |
train_ds = MNIST( | |
data_path, | |
train=True, | |
download=True, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OneCycleSchedule: | |
def __init__(self, t, linear_pct=0.2, eta_max=1.0, eta_min=None, | |
div_factor=100, decay_to_zero=True): | |
if eta_min is None: | |
eta_min = eta_max / div_factor | |
self.t = t | |
self.linear_pct = linear_pct |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CosineAnnealingSchedule: | |
""" | |
The schedule class that returns a learning rate multiplier from range [0.0, 1.0] | |
""" | |
def __init__(self, eta_min=0.0, eta_max=1.0, t_max=100, t_mult=2): | |
self.eta_min = eta_min | |
self.eta_max = eta_max | |
self.t_max = t_max | |
self.t_mult = t_mult | |
self.iter = 0 |