import numpy as np from src.fcnet import FullyConnectedNet from src.utils.solver import Solver from src.utils.data_utils import get_CIFAR10_data """ TODO: Overfit the network with 50 samples of CIFAR-10 """ ########################################################################### # BEGIN OF YOUR CODE # ########################################################################### datapath = datadir = ('/home/mat10/Documents/MSc Machine Learning/395-Machine Learning/' 'CW2/assignment2_advanced/datasets/cifar-10-batches-py') data = get_CIFAR10_data(datapath, num_training=50, num_validation=100, num_test=100, subtract_mean=True) hidden_dims = [1024, 512] net = FullyConnectedNet(hidden_dims, num_classes=10, dropout=0., reg=0.0, seed=0) solver = Solver(net, data, update_rule='sgd', optim_config={'learning_rate': 1e-3, 'momentum': 0.5}, lr_decay=0.95, num_epochs=20, batch_size=10, print_every=100) solver.train()
from src.evaluator import draw_loss_acc """ TODO: Overfit the network with 50 samples of CIFAR-10 """ ########################################################################### # BEGIN OF YOUR CODE # ########################################################################### TRAIN_NUM = 50 VALID_NUM = 1 TEST_NUM = 10 CLASS_NUM = 10 data = get_CIFAR10_data(TRAIN_NUM, VALID_NUM, TEST_NUM) print (data["y_test"].shape) print (data["y_test"]) INPUT_DIMS = np.prod(data["X_train"].shape[1:]) HIDDEN_DIMS = np.asarray([400, 400]) fcnn = FullyConnectedNet(HIDDEN_DIMS, INPUT_DIMS, CLASS_NUM) solver = Solver(fcnn, data, update_rule='sgd', optim_config={"learning_rate":1e-3}, print_every=1, num_epochs=20) solver.train() y = fcnn.predict(data["X_test"]) print (y) fcnn.save()
import numpy as np from src.fcnet import FullyConnectedNet from src.utils.solver import Solver from src.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 # ########################################################################### #define model and data model = FullyConnectedNet(hidden_dims=[20, 30]) data = get_CIFAR10_data() # define solver which helps us to train our model using the data solver = Solver(model, data, lr_decay=0.95, num_epochs=30, batch_size=120) # train the model solver.train() ############################################################################## # END OF YOUR CODE # ##############################################################################
import numpy as np from src.fcnet import FullyConnectedNet from src.utils.solver1 import Solver from src.utils.data_utils import get_CIFAR10_data """ TODO: Overfit the network with 50 samples of CIFAR-10 """ ########################################################################### # BEGIN OF YOUR CODE # ########################################################################### data = dict() data = get_CIFAR10_data(50, 50) model = FullyConnectedNet([2000, 2000], reg=1e-3) solver = Solver(model, data, update_rule='sgd', optim_config={ 'learning_rate': 1e-3, }, lr_decay=0.95, num_epochs=10, batch_size=100, print_every=100) solver.train() import matplotlib.pyplot as plt plt.subplot(2, 1, 1) plt.title('Trainingloss') plt.plot(solver.loss_history, 'o') plt.xlabel('Iteration')
import numpy as np from src.fcnet import FullyConnectedNet from src.utils.solver import Solver from src.utils.data_utils import get_CIFAR10_data """ TODO: Overfit the network with 50 samples of CIFAR-10 """ ########################################################################### # BEGIN OF YOUR CODE # ########################################################################### data = get_CIFAR10_data(49, 1, 0) INPUT_DIMS = np.prod(data["X_train"].shape[1:]) HIDDEN_DIMS = np.asarray([400,400]) NUM_CLASS = 10 net = FullyConnectedNet(HIDDEN_DIMS,INPUT_DIMS,NUM_CLASS) solver = Solver(net, data,update_rule='sgd',optim_config={\ 'learning_rate': 1e-3},\ num_epochs=20,\ batch_size = 10,\ print_every=1) solver.train() ############################################################################## # END OF YOUR CODE # ##############################################################################
import numpy as np from src.fcnet import FullyConnectedNet from src.utils.solver import Solver from src.utils.data_utils import get_CIFAR10_data """ TODO: Overfit the network with 50 samples of CIFAR-10 """ ########################################################################### # BEGIN OF YOUR CODE # ########################################################################### # define model and data model = FullyConnectedNet(hidden_dims=[20, 30]) data = get_CIFAR10_data(num_training=50) # define solver which helps us to train our model using the data solver = Solver(model, data, num_epochs=20, num_train_samples=50) # train our model using the solver solver.train() ############################################################################## # END OF YOUR CODE # ##############################################################################
import numpy as np from src.fcnet import FullyConnectedNet from src.utils.solver import Solver from src.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 = ( '/home/mat10/Documents/MSc Machine Learning/395-Machine Learning/' 'CW2/assignment2_advanced/datasets/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 },
import numpy as np import matplotlib.pyplot as plt from src.fcnet import FullyConnectedNet from src.utils.solver import Solver from src.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 # ########################################################################### out = get_CIFAR10_data(num_training=25000) data = { 'X_train': out['X_train'], # training data 'y_train': out['y_train'], # training labels 'X_val': out['X_val'], # validation data 'y_val': out['y_val'] # validation labels } model = FullyConnectedNet(hidden_dims=[100], num_classes=10, dropout=0, reg=0.5) solver = Solver(model, data, update_rule='sgd', optim_config={ 'learning_rate': 2e-3, },