def test_calcMean(self):
        modelMetadata = TestModel_Metadata()
        model = TestModel(modelMetadata)
        smoothingMetadata = dc.DefaultSmoothingOscilationEWMA_Metadata(
            movingAvgParam=0.5)

        smoothing = dc.DefaultSmoothingOscilationEWMA(
            smoothingMetadata=smoothingMetadata)
        smoothing.__setDictionary__(
            smoothingMetadata=smoothingMetadata,
            dictionary=model.getNNModelModule().named_parameters())

        smoothing.calcMean(model=model, smoothingMetadata=smoothingMetadata)

        wg = dict(model.named_parameters())
        smoothedWg = smoothing.weightsSum
        self.compareDictToNumpy(wg, init_weights)
        self.compareDictToNumpy(smoothedWg, init_weights)

        #############

        smoothing.calcMean(model=model, smoothingMetadata=smoothingMetadata)
        wg = dict(model.named_parameters())
        smoothedWg = smoothing.weightsSum
        self.compareDictToNumpy(wg, init_weights)
        self.compareDictToNumpy(smoothedWg, init_weights)

        ############

        second_base_weights = {
            'linear1.weight': [[17., 17., 17.]],
            'linear1.bias': [19.],
            'linear2.weight': [[17.], [17.], [17.]],
            'linear2.bias': [19., 19., 19.]
        }

        second_smth_weights = {
            'linear1.weight': [[11., 11., 11.]],
            'linear1.bias': [13.],
            'linear2.weight': [[11.], [11.], [11.]],
            'linear2.bias': [13., 13., 13.]
        }

        model.setConstWeights(weight=17, bias=19)
        smoothing.calcMean(model=model, smoothingMetadata=smoothingMetadata)
        wg = dict(model.named_parameters())
        smoothedWg = smoothing.weightsSum
        self.compareDictToNumpy(iterator=wg, numpyDict=second_base_weights)
        self.compareDictToNumpy(iterator=smoothedWg,
                                numpyDict=second_smth_weights)
    dataMetadata = dc.DefaultData_Metadata(pin_memoryTest=False,
                                           pin_memoryTrain=False,
                                           epoch=2,
                                           fromGrayToRGB=True)
    loop = 5
    modelName = "wide_resnet50_2"
    prefix = "epsilons_"

    types = ('predefModel', 'MNIST', 'movingMean')
    try:
        stats = []
        rootFolder = prefix + sf.Output.getTimeStr() + ''.join(
            x + "_" for x in types) + "set"
        smoothingMetadata = dc.DefaultSmoothingOscilationEWMA_Metadata(
            movingAvgParam=0.15,
            epsilon=1e-1,
            hardEpsilon=1e-3,
            weightsEpsilon=1e-2,
            batchPercentMaxStart=0.98)

        for r in range(loop):
            obj = models.wide_resnet50_2()
            metadata.resetOutput()
            modelMetadata = dc.DefaultModel_Metadata()

            stat = dc.run(numbOfRepetition=2,
                          modelType=types[0],
                          dataType=types[1],
                          smoothingType=types[2],
                          metadataObj=metadata,
                          modelMetadata=modelMetadata,
                          dataMetadata=dataMetadata,
Beispiel #3
0
                                           pin_memoryTrain=False,
                                           epoch=2,
                                           fromGrayToRGB=True)
    loop = 5
    modelName = "alexnet"
    prefix = "mov_param_"
    runningAvgSize = 10

    types = ('predefModel', 'MNIST', 'movingMean')
    try:
        stats = []
        rootFolder = prefix + sf.Output.getTimeStr() + ''.join(
            x + "_" for x in types) + "set"
        smoothingMetadata = dc.DefaultSmoothingOscilationEWMA_Metadata(
            movingAvgParam=0.05,
            epsilon=1e-5,
            hardEpsilon=1e-7,
            weightsEpsilon=1e-6,
            batchPercentMaxStart=0.98)

        for r in range(loop):
            obj = models.alexnet()
            metadata.resetOutput()

            modelMetadata = dc.DefaultModel_Metadata()
            data = DataMap[dataType](dataMetadata)
            smoothing = SmoothingMap[smoothingType](smoothingMetadata)
            model = ModelMap[modelType](obj=modelPredefObj,
                                        modelMetadata=modelMetadata,
                                        name=modelPredefObjName,
                                        optimizer=optimizer,
                                        lossFunc=lossFunc)