Example #1
0
    def test_infer_shape_gradI(self):
        if theano.config.mode == "FAST_COMPILE":
            raise SkipTest("Corr3dMM don't work in FAST_COMPILE")

        def rand(*shape):
            r = numpy.asarray(numpy.random.rand(*shape), dtype="float64")
            return r * 2 - 1

        corr3dMM = corr3d.Corr3dMM
        gradI = corr3d.Corr3dMM_gradInputs

        adtens = T.dtensor5()
        bdtens = T.dtensor5()
        aivec_vals = [[1, 5, 6, 3, 3], [8, 2, 7, 3, 3], [1, 6, 9, 4, 4], [9, 6, 8, 5, 5], [9, 1, 6, 8, 8]]
        bivec_vals = [[7, 5, 3, 1, 1], [4, 2, 5, 3, 3], [12, 6, 3, 2, 2], [5, 6, 1, 3, 3], [7, 1, 3, 4, 4]]
        modes = ["valid", "full", "half", (1, 1, 1), (2, 1, 1), (1, 2, 1), (1, 1, 2), 1]
        subsamples = [(1, 1, 1), (2, 1, 1), (1, 2, 1), (1, 1, 2)]

        for aivec_val, bivec_val in zip(aivec_vals, bivec_vals):
            adtens_val = rand(*aivec_val)
            bdtens_val = rand(*bivec_val)
            for mode in modes:
                for subsample in subsamples:
                    # Corr3dMM
                    cdtens = corr3dMM(border_mode=mode, subsample=subsample)(adtens, bdtens)
                    f = theano.function([adtens, bdtens], cdtens)
                    cdtens_val = f(adtens_val, bdtens_val)
                    # Corr3dMM_gradInputs
                    shape = (theano.shared(aivec_val[2]), theano.shared(aivec_val[3]), theano.shared(aivec_val[4]))
                    adtens_g = gradI(border_mode=mode, subsample=subsample)(bdtens, cdtens, shape=shape)
                    self._compile_and_check([bdtens, cdtens], [adtens_g], [bdtens_val, cdtens_val], gradI, warn=False)
Example #2
0
    def test_infer_shape_forward(self):
        if theano.config.mode == "FAST_COMPILE":
            raise SkipTest("Corr3dMM don't work in FAST_COMPILE")

        def rand(*shape):
            r = numpy.asarray(numpy.random.rand(*shape), dtype='float64')
            return r * 2 - 1
        corr3dMM = corr3d.Corr3dMM

        adtens = T.dtensor5()
        bdtens = T.dtensor5()
        aivec_vals = [[4, 5, 6, 3, 3], [6, 2, 8, 3, 3], [3, 6, 7, 5, 5],
                      [3, 6, 7, 5, 5], [5, 2, 4, 3, 3]]
        bivec_vals = [[7, 5, 3, 2, 2], [4, 2, 5, 3, 3], [5, 6, 3, 2, 2],
                      [5, 6, 2, 3, 3], [6, 2, 4, 3, 3]]
        modes = ['valid', 'full', 'half', (1, 1, 1), (2, 1, 1), (1, 2, 1), (1, 1, 2), 1]
        subsamples = [(1, 1, 1), (2, 1, 1), (1, 2, 1), (1, 1, 2)]

        for aivec_val, bivec_val in zip(aivec_vals, bivec_vals):
            adtens_val = rand(*aivec_val)
            bdtens_val = rand(*bivec_val)
            for mode in modes:
                for subsample in subsamples:
                    # Corr3dMM
                    cdtens = corr3dMM(border_mode=mode, subsample=subsample)(adtens, bdtens)
                    self._compile_and_check([adtens, bdtens],
                                            [cdtens],
                                            [adtens_val, bdtens_val], corr3dMM,
                                            warn=False)
Example #3
0
    def test_infer_shape_forward(self):
        if theano.config.mode == "FAST_COMPILE":
            raise SkipTest("Corr3dMM don't work in FAST_COMPILE")

        def rand(*shape):
            r = numpy.asarray(numpy.random.rand(*shape), dtype="float64")
            return r * 2 - 1

        corr3dMM = corr3d.Corr3dMM

        adtens = T.dtensor5()
        bdtens = T.dtensor5()
        aivec_vals = [[4, 5, 6, 3, 3], [6, 2, 8, 3, 3], [3, 6, 7, 5, 5], [3, 6, 7, 5, 5], [5, 2, 4, 3, 3]]
        bivec_vals = [[7, 5, 3, 2, 2], [4, 2, 5, 3, 3], [5, 6, 3, 2, 2], [5, 6, 2, 3, 3], [6, 2, 4, 3, 3]]
        modes = ["valid", "full", "half", (1, 1, 1), (2, 1, 1), (1, 2, 1), (1, 1, 2), 1]
        subsamples = [(1, 1, 1), (2, 1, 1), (1, 2, 1), (1, 1, 2)]

        for aivec_val, bivec_val in zip(aivec_vals, bivec_vals):
            adtens_val = rand(*aivec_val)
            bdtens_val = rand(*bivec_val)
            for mode in modes:
                for subsample in subsamples:
                    # Corr3dMM
                    cdtens = corr3dMM(border_mode=mode, subsample=subsample)(adtens, bdtens)
                    self._compile_and_check([adtens, bdtens], [cdtens], [adtens_val, bdtens_val], corr3dMM, warn=False)
    def test_infer_shape_gradI(self):
        def rand(*shape):
            r = np.asarray(np.random.rand(*shape), dtype="float64")
            return r * 2 - 1

        corr3dMM = corr3d.Corr3dMM
        gradI = corr3d.Corr3dMMGradInputs

        adtens = tt.dtensor5()
        bdtens = tt.dtensor5()
        aivec_vals = [
            [1, 5, 6, 3, 3],
            [8, 2, 7, 3, 3],
            [1, 6, 9, 4, 4],
            [9, 6, 8, 5, 5],
            [9, 1, 6, 8, 8],
        ]
        bivec_vals = [
            [7, 5, 3, 1, 1],
            [4, 2, 5, 3, 3],
            [12, 6, 3, 2, 2],
            [5, 6, 1, 3, 3],
            [7, 1, 3, 4, 4],
        ]
        modes = [
            "valid", "full", "half", (1, 1, 1), (2, 1, 1), (1, 2, 1),
            (1, 1, 2), 1
        ]
        subsamples = [(1, 1, 1), (2, 1, 1), (1, 2, 1), (1, 1, 2)]

        for aivec_val, bivec_val in zip(aivec_vals, bivec_vals):
            adtens_val = rand(*aivec_val)
            bdtens_val = rand(*bivec_val)
            for mode in modes:
                for subsample in subsamples:
                    # Corr3dMM
                    cdtens = corr3dMM(border_mode=mode,
                                      subsample=subsample)(adtens, bdtens)
                    f = theano.function([adtens, bdtens], cdtens)
                    cdtens_val = f(adtens_val, bdtens_val)
                    # Corr3dMM_gradInputs
                    shape = (
                        theano.shared(aivec_val[2]),
                        theano.shared(aivec_val[3]),
                        theano.shared(aivec_val[4]),
                    )
                    adtens_g = gradI(border_mode=mode,
                                     subsample=subsample)(bdtens,
                                                          cdtens,
                                                          shape=shape)
                    self._compile_and_check(
                        [bdtens, cdtens],
                        [adtens_g],
                        [bdtens_val, cdtens_val],
                        gradI,
                        warn=False,
                    )
Example #5
0
    def test_infer_shape_forward(self):
        if theano.config.mode == "FAST_COMPILE":
            pytest.skip("Corr3dMM don't work in FAST_COMPILE")
        if not theano.config.cxx:
            pytest.skip("Need cxx for this test")

        def rand(*shape):
            r = np.asarray(np.random.rand(*shape), dtype="float64")
            return r * 2 - 1

        corr3dMM = corr3d.Corr3dMM

        adtens = T.dtensor5()
        bdtens = T.dtensor5()
        aivec_vals = [
            [4, 5, 6, 3, 3],
            [6, 2, 8, 3, 3],
            [3, 6, 7, 5, 5],
            [3, 6, 7, 5, 5],
            [5, 2, 4, 3, 3],
        ]
        bivec_vals = [
            [7, 5, 3, 2, 2],
            [4, 2, 5, 3, 3],
            [5, 6, 3, 2, 2],
            [5, 6, 2, 3, 3],
            [6, 2, 4, 3, 3],
        ]
        modes = [
            "valid", "full", "half", (1, 1, 1), (2, 1, 1), (1, 2, 1),
            (1, 1, 2), 1
        ]
        subsamples = [(1, 1, 1), (2, 1, 1), (1, 2, 1), (1, 1, 2)]

        for aivec_val, bivec_val in zip(aivec_vals, bivec_vals):
            adtens_val = rand(*aivec_val)
            bdtens_val = rand(*bivec_val)
            for mode in modes:
                for subsample in subsamples:
                    # Corr3dMM
                    cdtens = corr3dMM(border_mode=mode,
                                      subsample=subsample)(adtens, bdtens)
                    self._compile_and_check(
                        [adtens, bdtens],
                        [cdtens],
                        [adtens_val, bdtens_val],
                        corr3dMM,
                        warn=False,
                    )
    def test_infer_shape_gradI(self):
        if theano.config.mode == "FAST_COMPILE":
            raise SkipTest("Corr3dMM don't work in FAST_COMPILE")
        if not theano.config.cxx:
            raise SkipTest("Need cxx for this test")

        def rand(*shape):
            r = np.asarray(np.random.rand(*shape), dtype='float64')
            return r * 2 - 1

        corr3dMM = corr3d.Corr3dMM
        gradI = corr3d.Corr3dMM_gradInputs

        adtens = T.dtensor5()
        bdtens = T.dtensor5()
        aivec_vals = [[1, 5, 6, 3, 3], [8, 2, 7, 3, 3], [1, 6, 9, 4, 4],
                      [9, 6, 8, 5, 5], [9, 1, 6, 8, 8]]
        bivec_vals = [[7, 5, 3, 1, 1], [4, 2, 5, 3, 3], [12, 6, 3, 2, 2],
                      [5, 6, 1, 3, 3], [7, 1, 3, 4, 4]]
        modes = [
            'valid', 'full', 'half', (1, 1, 1), (2, 1, 1), (1, 2, 1),
            (1, 1, 2), 1
        ]
        subsamples = [(1, 1, 1), (2, 1, 1), (1, 2, 1), (1, 1, 2)]

        for aivec_val, bivec_val in zip(aivec_vals, bivec_vals):
            adtens_val = rand(*aivec_val)
            bdtens_val = rand(*bivec_val)
            for mode in modes:
                for subsample in subsamples:
                    # Corr3dMM
                    cdtens = corr3dMM(border_mode=mode,
                                      subsample=subsample)(adtens, bdtens)
                    f = theano.function([adtens, bdtens], cdtens)
                    cdtens_val = f(adtens_val, bdtens_val)
                    # Corr3dMM_gradInputs
                    shape = (theano.shared(aivec_val[2]),
                             theano.shared(aivec_val[3]),
                             theano.shared(aivec_val[4]))
                    adtens_g = gradI(border_mode=mode,
                                     subsample=subsample)(bdtens,
                                                          cdtens,
                                                          shape=shape)
                    self._compile_and_check([bdtens, cdtens], [adtens_g],
                                            [bdtens_val, cdtens_val],
                                            gradI,
                                            warn=False)
    def test_infer_shape_forward(self):
        def rand(*shape):
            r = np.asarray(np.random.rand(*shape), dtype="float64")
            return r * 2 - 1

        corr3dMM = corr3d.Corr3dMM

        adtens = tt.dtensor5()
        bdtens = tt.dtensor5()
        aivec_vals = [
            [4, 5, 6, 3, 3],
            [6, 2, 8, 3, 3],
            [3, 6, 7, 5, 5],
            [3, 6, 7, 5, 5],
            [5, 2, 4, 3, 3],
        ]
        bivec_vals = [
            [7, 5, 3, 2, 2],
            [4, 2, 5, 3, 3],
            [5, 6, 3, 2, 2],
            [5, 6, 2, 3, 3],
            [6, 2, 4, 3, 3],
        ]
        modes = [
            "valid", "full", "half", (1, 1, 1), (2, 1, 1), (1, 2, 1),
            (1, 1, 2), 1
        ]
        subsamples = [(1, 1, 1), (2, 1, 1), (1, 2, 1), (1, 1, 2)]

        for aivec_val, bivec_val in zip(aivec_vals, bivec_vals):
            adtens_val = rand(*aivec_val)
            bdtens_val = rand(*bivec_val)
            for mode in modes:
                for subsample in subsamples:
                    # Corr3dMM
                    cdtens = corr3dMM(border_mode=mode,
                                      subsample=subsample)(adtens, bdtens)
                    self._compile_and_check(
                        [adtens, bdtens],
                        [cdtens],
                        [adtens_val, bdtens_val],
                        corr3dMM,
                        warn=False,
                    )
Example #8
0
    def test_infer_shape_gradW(self):
        if theano.config.mode == "FAST_COMPILE":
            raise SkipTest("Corr3dMM don't work in FAST_COMPILE")
        if not theano.config.cxx:
            raise SkipTest("Need cxx for this test")

        def rand(*shape):
            r = np.asarray(np.random.rand(*shape), dtype='float64')
            return r * 2 - 1
        corr3dMM = corr3d.Corr3dMM
        gradW = corr3d.Corr3dMM_gradWeights

        adtens = T.dtensor5()
        bdtens = T.dtensor5()
        aivec_vals = [[1, 5, 6, 3, 3], [8, 2, 7, 3, 3], [1, 6, 9, 4, 4],
                      [9, 6, 8, 5, 5], [9, 1, 6, 8, 8]]
        bivec_vals = [[7, 5, 3, 1, 1], [4, 2, 5, 3, 3], [12, 6, 3, 2, 2],
                      [5, 6, 1, 3, 3], [11, 1, 3, 3, 3]]
        modes = ['valid', 'full', 'half', (1, 1, 1), (2, 1, 1), (1, 2, 1), (1, 1, 2), 1]
        subsamples = [(1, 1, 1), (2, 1, 1), (1, 2, 1), (1, 1, 2)]

        for aivec_val, bivec_val in zip(aivec_vals, bivec_vals):
            adtens_val = rand(*aivec_val)
            bdtens_val = rand(*bivec_val)
            for mode in modes:
                for subsample in subsamples:
                    # Corr3dMM
                    cdtens = corr3dMM(border_mode=mode, subsample=subsample)(adtens, bdtens)
                    f = theano.function([adtens, bdtens], cdtens)
                    cdtens_val = f(adtens_val, bdtens_val)
                    # Corr3dMM_gradWeights
                    shape = (theano.shared(bivec_val[2]), theano.shared(bivec_val[3]),
                             theano.shared(bivec_val[4]))
                    bdtens_g = gradW(border_mode=mode,
                                     subsample=subsample)(adtens, cdtens, shape=shape)
                    self._compile_and_check([adtens, cdtens],
                                            [bdtens_g],
                                            [adtens_val, cdtens_val], gradW,
                                            warn=False)