Esempio n. 1
0
    def test_verify_cross_layer_for_multiple_pairs(self):
        # Get trained MNIST model

        model = MyModel()
        # Call API
        consecutive_layer_list = [(model.conv1, model.conv2),
                                  (model.conv3, model.conv4)]
        w1 = model.conv1.weight.detach().numpy()
        w2 = model.conv2.weight.detach().numpy()
        w3 = model.conv3.weight.detach().numpy()

        CrossLayerScaling.scale_cls_sets(consecutive_layer_list)

        # check if weights are updating
        assert not np.allclose(model.conv1.weight.detach().numpy(), w1)
        assert not np.allclose(model.conv2.weight.detach().numpy(), w2)
        assert not np.allclose(model.conv3.weight.detach().numpy(), w3)
Esempio n. 2
0
    def test_verify_cross_layer_scaling_depthwise_separable_layer_multiple_triplets(
            self):

        torch.manual_seed(10)

        model = MockMobileNetV1()
        model = model.eval()

        consecutive_layer_list = [
            (model.model[0][0], model.model[1][0], model.model[1][3]),
            (model.model[1][3], model.model[2][0], model.model[2][3])
        ]

        w1 = model.model[0][0].weight.detach().numpy()
        w2 = model.model[1][3].weight.detach().numpy()
        w3 = model.model[2][3].weight.detach().numpy()

        CrossLayerScaling.scale_cls_sets(consecutive_layer_list)

        assert not np.allclose(model.model[0][0].weight.detach().numpy(), w1)
        assert not np.allclose(model.model[1][3].weight.detach().numpy(), w2)
        assert not np.allclose(model.model[2][3].weight.detach().numpy(), w3)