Exemplo n.º 1
0
from utils.transforms import *

# hyper-parameters
learning_rate = 0.1
num_epoches = 25
batch_size = 128
lr_decay = [0.2, 15]
l2_reg = 0.001
eval_freq = 100

# network
net = network.Network(l2_reg=l2_reg)

# blocks
net.add_block(layers.Linear(n_in=28 * 28 * 1, n_out=1024))
net.add_block(layers.BatchNorm1d(n_in=1024))
net.add_block(activations.ReLU(inplace=True))
net.add_block(layers.Dropout(keep_prob=0.5))
net.add_block(layers.Linear(n_in=1024, n_out=10))
net.add_block(losses.CrossEntropyLoss())

# optimizer
optimizer = optimizers.Momentum(learning_rate=learning_rate,
                                momentum=0.9,
                                Nesterov=True,
                                lr_decay=lr_decay)

# data loading and augmentation
train_transform = Transforms([ToTensor()])
val_test_transform = Transforms([ToTensor()])
train, val, test = load_data.load_mnist(train_transform, val_test_transform)
Exemplo n.º 2
0
                  padding=2,
                  stride=1))
net.add_block(layers.BatchNorm2d(in_channels=8))
net.add_block(activations.ReLU(inplace=True))
net.add_block(layers.MaxPool2d(stride=2))
net.add_block(
    layers.Conv2d(in_channels=8,
                  out_channels=16,
                  kernel_size=(5, 5),
                  padding=2,
                  stride=1))
net.add_block(layers.BatchNorm2d(in_channels=16))
net.add_block(activations.ReLU(inplace=True))
net.add_block(layers.MaxPool2d(stride=2))
net.add_block(layers.Linear(n_in=8 * 8 * 16, n_out=512))
net.add_block(layers.BatchNorm1d(n_in=512))
net.add_block(activations.ReLU(inplace=True))
net.add_block(layers.Dropout(keep_prob=0.5))
net.add_block(layers.Linear(n_in=512, n_out=10))
net.add_block(losses.CrossEntropyLoss())

# optimizer
optimizer = optimizers.Momentum(learning_rate=learning_rate,
                                momentum=0.9,
                                Nesterov=True,
                                lr_decay=lr_decay)

# data loading and augmentation
mean = [x / 255 for x in [125.3, 123.0, 113.9]]
std = [x / 255 for x in [63.0, 62.1, 66.7]]
train_transform = Transforms([
Exemplo n.º 3
0
import numpy as np
import matplotlib.pyplot as plt

# hyper-parameters
d_lr = 0.0002
g_lr = 0.0002
image_size = 28 * 28
hideen_size = 256
latent_size = 64
batch_size = 100
num_epoches = 400

# discriminator
D = network.Network(l2_reg=1e-3)
D.add_block(layers.Linear(image_size, hideen_size))
D.add_block(layers.BatchNorm1d(hideen_size))
D.add_block(activations.LeakeyReLU(0.2))
D.add_block(layers.Linear(hideen_size, hideen_size))
D.add_block(layers.BatchNorm1d(hideen_size))
D.add_block(activations.LeakeyReLU(0.2))
D.add_block(layers.Linear(hideen_size, 1))
D.add_block(losses.BCELoss())

# generator
G = network.Network(l2_reg=1e-3)
G.add_block(layers.Linear(latent_size, hideen_size))
G.add_block(layers.BatchNorm1d(hideen_size))
G.add_block(activations.ReLU())
G.add_block(layers.Linear(hideen_size, hideen_size))
G.add_block(layers.BatchNorm1d(hideen_size))
G.add_block(activations.ReLU())