コード例 #1
0
def verify_on_full_data():
    model = ThreeLayerConvNet(num_classes=2, weight_scale=0.001, hidden_dim=500, reg=0.01, dropout=0.4)
    data = get_CIFAR2_data()

    solver = Solver(model, data,
                    num_epochs=10, batch_size=50,
                    update_rule='adam',
                    optim_config={
                        'learning_rate': 1e-3,
                    },
                    verbose=True, print_every=20)
    solver.train()
コード例 #2
0
def verify_model_on_small_data():
    data = get_CIFAR2_data()
    for k, v in data.items():
        print('% s: ' % k, v.shape)

    np.random.seed(231)

    num_train = 100
    small_data = {
        'X_train': data['X_train'][:num_train],
        'y_train': data['y_train'][:num_train],
        'X_val': data['X_val'],
        'y_val': data['y_val'],
    }

    model = cnn.ThreeLayerConvNet(weight_scale=1e-2)

    solver = Solver(model,
                    small_data,
                    num_epochs=15,
                    batch_size=50,
                    update_rule='adam',
                    optim_config={
                        'learning_rate': 1e-3,
                    },
                    verbose=True,
                    print_every=1)
    solver.train()

    plt.subplot(2, 1, 1)
    plt.plot(solver.loss_history, 'o')
    plt.xlabel('iteration')
    plt.ylabel('loss')

    plt.subplot(2, 1, 2)
    plt.plot(solver.train_acc_history, '-o')
    plt.plot(solver.val_acc_history, '-o')
    plt.legend(['train', 'val'], loc='upper left')
    plt.xlabel('epoch')
    plt.ylabel('accuracy')
    plt.show()
コード例 #3
0
def verify_on_full_data_without_dropout():
    model = ThreeLayerConvNet(num_classes=2,
                              weight_scale=0.001,
                              hidden_dim=500,
                              reg=0,
                              dropout=0)
    data = get_CIFAR2_data()

    solver = Solver(model,
                    data,
                    num_epochs=10,
                    batch_size=50,
                    update_rule='adam',
                    optim_config={
                        'learning_rate': 1e-3,
                    },
                    verbose=True,
                    print_every=20)
    solver.train()

    plt.subplot(2, 1, 1)
    plt.plot(solver.loss_history, 'o')
    plt.xlabel('iteration')
    plt.ylabel('loss')

    plt.subplot(2, 1, 2)
    plt.plot(solver.train_acc_history, '-o')
    plt.plot(solver.val_acc_history, '-o')
    plt.legend(['train', 'val'], loc='upper left')
    plt.xlabel('epoch')
    plt.ylabel('accuracy')
    plt.show()

    grid = visualize_grid(model.params['W1'].transpose(0, 2, 3, 1))
    plt.imshow(grid.astype('uint8'))
    plt.axis('off')
    plt.gcf().set_size_inches(5, 5)
    plt.show()
コード例 #4
0
ファイル: mytrain.py プロジェクト: Nuomisu/cs5242
import numpy as np
import matplotlib.pyplot as plt
from code_base.classifiers.cnn import *
from code_base.data_utils import get_CIFAR2_data
from code_base.layers import *
from code_base.solver import Solver

data = get_CIFAR2_data()
for k, v in data.items():
    print('%s: ' % k, v.shape)

model = ThreeLayerConvNet(num_classes=2,
                          weight_scale=0.001,
                          hidden_dim=500,
                          reg=0.001)

solver = Solver(model,
                data,
                num_epochs=1,
                batch_size=50,
                update_rule='adam',
                optim_config={
                    'learning_rate': 1e-3,
                },
                verbose=True,
                print_every=20)
print('start train')
solver.train()
print('finish train')

plt.subplot(2, 1, 1)