Beispiel #1
0
def get_cifar10_dataset():
    # The data, shuffled and split between train and test sets:
    data = get_CIFAR10_data(cifar10_dir='~/Developer/CS599/assignment1/data/cifar-10-batches-py',
                            num_training=50000, num_validation=0, num_test=10000)
    x_train = data['X_train'].transpose(0, 2, 3, 1)
    y_train = data['y_train']
    x_val = data['X_val'].transpose(0, 2, 3, 1)
    y_val = data['y_val']
    x_test = data['X_test'].transpose(0, 2, 3, 1)
    y_test = data['y_test']

    print('x_train shape:', x_train.shape)
    print(x_train.shape[0], 'train samples')
    print(x_test.shape[0], 'test samples')

    # Convert class vectors to binary class matrices.
    y_train = keras.utils.to_categorical(y_train, num_classes)
    y_val = keras.utils.to_categorical(y_val, num_classes)
    y_test = keras.utils.to_categorical(y_test, num_classes)

    x_train = x_train.astype('float32')
    x_val = x_val.astype('float32')
    x_test = x_test.astype('float32')
    x_train /= 255
    x_val /= 255
    x_test /= 255

    return (x_train, y_train), (x_val, y_val), (x_test, y_test)
Beispiel #2
0
from utils.data_utils import get_CIFAR10_data

batch_size = 128
nb_classes = 10
nb_epoch = 10

# input image dimensions
img_rows, img_cols = 32, 32
# The CIFAR10 images are RGB.
img_channels = 3

reg = 0

# The data, shuffled and split between train and test sets:
data = get_CIFAR10_data()
X_train = data['X_train']
y_train = data['y_train']
X_val = data['X_val']
y_val = data['y_val']
X_test = data['X_test']
y_test = data['y_test']

# Convert class vectors to binary class matrices.
Y_train = np_utils.to_categorical(y_train, nb_classes)
Y_val = np_utils.to_categorical(y_val, nb_classes)


def create_model_1():
    model = Sequential()
import random
import numpy as np
from utils.data_utils import get_CIFAR10_data
from utils.gradient_check import grad_check_sparse

from softmax_loss import softmax_loss_vectorized, softmax_loss_naive
from softmax import Softmax
import matplotlib.pyplot as plt

cifar10_dir = 'datasets/cifar-10-batches-py'

X_train, y_train, X_val, y_val, X_test, y_test, X_sample, y_sample = get_CIFAR10_data(
)

# W = np.random.randn(3073, 10) * 0.0001
# loss, grad = softmax_loss_vectorized(W, X_sample, y_sample, 0.0)
# f = lambda w: softmax_loss_vectorized(w, X_sample, y_sample, 0.0)[0]

# grad_numerical = grad_check_sparse(f, W, grad, 10)

# loss, grad = softmax_loss_vectorized(W, X_sample, y_sample, 0.01)
# f = lambda w: softmax_loss_vectorized(w, X_sample, y_sample, 0.01)[0]

# grad_numerical = grad_check_sparse(f, W, grad, 10)

# softmax = Softmax()
# loss_hist = softmax.train(X_sample, y_sample, learning_rate=1e-7, reg=5e-4, num_iters=3500, verbose=True)
# plt.plot(loss_hist)
# plt.xlabel('iteration number')
# plt.ylabel('loss value')
# plt.show()
Beispiel #4
0
import numpy as np

from fcnet import FullyConnectedNet
from utils.solver import Solver
from utils.data_utils import get_CIFAR10_data
"""
TODO: Use a Solver instance to train a TwoLayerNet that achieves at least 50% 
accuracy on the validation set.
"""
###########################################################################
#                           BEGIN OF YOUR CODE                            #
###########################################################################
datapath = datadir = (
    '/media/mat10/EA3F-222E/395/CW2/CW2_data/cifar-10-batches-py')
data = get_CIFAR10_data()  #datapath)

hidden_dims = [512, 256]
net = FullyConnectedNet(hidden_dims,
                        num_classes=10,
                        dropout=0.0,
                        reg=0.2,
                        seed=0)

solver = Solver(net,
                data,
                update_rule='sgd_momentum',
                optim_config={
                    'learning_rate': 1e-3,
                    'momentum': 0.9
                },
                lr_decay=0.975,
Beispiel #5
0
import numpy as np

from fcnet import FullyConnectedNet
from utils.solver import Solver
from utils.data_utils import get_CIFAR10_data
import csv
"""
TODO: Use a Solver instance to train a TwoLayerNet that achieves at least 50%
accuracy on the validation set.
"""
###########################################################################
#                           BEGIN OF YOUR CODE                            #
###########################################################################

DIC = get_CIFAR10_data()

data = {
    'X_train': DIC['X_train'],
    'y_train': DIC['y_train'],
    'X_val': DIC['X_val'],
    'y_val': DIC['y_val'],
}

# configuration of CIFAR-10 training
model = FullyConnectedNet([150, 60],
                          num_classes=10,
                          dropout=0,
                          reg=0.01,
                          weight_scale=1e-2,
                          dtype=np.float32,
                          seed=None)