Ejemplo n.º 1
0
def load_data(small_data=False, verbose=False):
    """
    Output: A dictionary with the following keys and value shapes
    if small_data is True:
        X_train (100, 32, 32, 4)
        y_train (100, 32, 32, 3)
        X_val (10, 32, 32, 4)
        y_val (10, 32, 32, 3)
    else (small_data is False):
        X_train (49000, 32, 32, 4)
        y_train (49000, 32, 32, 3)
        X_val (1000, 32, 32, 4)
        y_val (1000, 32, 32, 3)
        X_test (1000, 32, 32, 4)
        y_test (1000, 32, 32, 3)
    """
    print 'Loading data'
    data = get_CIFAR10_data(mode=1)
    if small_data:
        num_train = 100
        data = {
            'X_train': data['X_train'][:num_train],
            'y_train': data['y_train'][:num_train],
            'X_val': data['X_val'][:(num_train / 10)],
            'y_val': data['y_val'][:(num_train / 10)],
        }

    if verbose:
        for k, v in data.iteritems():
            print '%s: ' % k, v.shape

    return data
Ejemplo n.º 2
0
def test_two_layer_net_solver():
  model = TwoLayerNet()
  solver = None

  data = get_CIFAR10_data()
  solver = Solver(model, data, update_rule='sgd', optim_config={'learning_rate': 1e-3}, lr_decay=0.95)
  solver.train()
Ejemplo n.º 3
0
def test_two_layer_net_solver():
    from code.solver import Solver
    from code.data_utils import get_CIFAR10_data
    from code.classifiers.fc_net import TwoLayerNet
    model = TwoLayerNet()
    solver = None

    data = get_CIFAR10_data()
    solver = Solver(model,
                    data,
                    update_rule='sgd',
                    optim_config={'learning_rate': 1e-3},
                    lr_decay=0.95)
    solver.train()
Ejemplo n.º 4
0
def test_sgd():
    from code.data_utils import get_CIFAR10_data
    from code.classifiers.linear_classifier import Softmax
    softmax = Softmax()
    data = get_CIFAR10_data()
    X_train, y_train = data['X_train'], data['y_train']
    X_val, y_val = data['X_val'], data['y_val']

    np.random.seed(1)
    loss_hist = softmax.train(X_train.reshape((X_train.shape[0], -1)),
                              y_train,
                              learning_rate=1e-7,
                              reg=5e4,
                              num_iters=1500,
                              verbose=False)
    assert loss_hist[
        -1] < 2.2, 'Problem with softmax train sgd, loss: %s' % loss_hist[-1]
    y_val_pred = softmax.predict(X_val.reshape((X_val.shape[0], -1)))
    val_acc = np.mean(y_val == y_val_pred)
    assert val_acc > 0.28, 'Problem with softmax train sgd, val accuracy %f' % val_acc
Ejemplo n.º 5
0
# All gradients above this will be clipped
GRAD_CLIP = 100

# How often should we check the output?
PRINT_FREQ = 1000

# Number of epochs to train the net
NUM_EPOCHS = 50

# Batch Size
BATCH_SIZE = 20 #128

NUM_LABELS = 256

# Load data
data = get_CIFAR10_data(mode=1)
"""
data is a dictionary with the following keys and value shapes:
X_val:  (1000, 4, 32, 32)
X_train:  (49000, 4, 32, 32)
X_test:  (1000, 4, 32, 32)
y_val:  (1000, 3, 32, 32)
y_train:  (49000, 3, 32, 32)
y_test:  (1000, 3, 32, 32)
"""

# Work with a small subset of data
num_train = 100
small_data = {
  'X_train': data['X_train'][:num_train],
  'y_train': data['y_train'][:num_train],