Beispiel #1
0
import sys

sys.path.append('../')
sys.path.append('../src/')

from data_gen import *
from coreset import *
from variational_trainer import VariationalTrainer

# experiment setup
dictParams = {
    'numEpochs': 1,
    'batchSize': 100,
    'numSamples': 10000,
    'dataGen': PermutedMnistGen(),
    'numTasks': 5,
    'numHeads': 5,
    'coresetMethod': coreset_rand,
    'coresetSize': 0,
    'numLayers': (2, 1),
    'hiddenSize': 256,
    'taskOrder': [],
    'headOrder': [],
}

# run experiment
trainer = VariationalTrainer(dictParams)
trainer.train()
print(trainer.accuracy)
from time import time
from data_gen import *
from coreset import *
from utils import *
from constants import DEFAULT_PARAMETERS
from result_averager import ResultAverager
from variational_trainer import VariationalTrainer

directory = "../exp/final_experiments/adversarial_ordering"

dictUpdate = {
    'dataGen': SplitMnistGen(),
    'coresetMethod': coreset_rand,
    'numLayers': (2, 1),
    'coresetSize': 0,
    'numEpochs': 120
}

for taskOrder in getAdversarialPermutationList():
    startTime = time()
    resultAverager = ResultAverager()
    dictUpdate['taskOrder'] = taskOrder
    dictParams = getAllExpParameters(dictUpdate)
    for iter in range(0, 5):
        trainer = VariationalTrainer(dictParams)
        accuracy = trainer.train()
        resultAverager.add(accuracy)
    filename = getName(dictParams, 'taskOrder')
    writePerformanceRecordAccuracyAvg(directory, filename, resultAverager)
    print('Time for single iteration: {}'.format((time() - startTime) / 60))
Beispiel #3
0
x_train = torch.ones(10, 5)
y_train = torch.ones(10, 2)
for i in range(y_train.shape[0]):
    x_train[i, :] *= i
    y_train[i, :] *= i

# ----------------- batchSize: None ----------------- #

x_train1 = deepcopy(x_train)
y_train1 = deepcopy(y_train)
dictParams1 = deepcopy(dictParams)

dictParams1['batchSize'] = None

variationalTrainer1 = VariationalTrainer(dictParams1)
batches1 = variationalTrainer1.getBatch(x_train1, y_train1)

x_train_batch, y_train_batch = batches1[0]
assert len(batches1) == 1
assert torch.all(torch.eq(x_train1, x_train_batch))
assert torch.all(torch.eq(y_train1, y_train_batch))

# ----------------- batchSize: 3 ----------------- #

x_train2 = deepcopy(x_train)
y_train2 = deepcopy(y_train)
dictParams2 = deepcopy(dictParams)

dictParams2['batchSize'] = 3