Exemple #1
0
def local_conv2d_cpu(fgraph, node):

    if not isinstance(node.op, AbstractConv2d) or node.inputs[0].dtype == "float16":
        return None

    img, kern = node.inputs
    if not isinstance(img.type, TensorType) or not isinstance(kern.type, TensorType):
        return None
    if node.op.border_mode not in ["full", "valid"]:
        return None
    if not node.op.filter_flip:
        # Not tested yet
        return None
    if node.op.num_groups > 1 or node.op.unshared:
        return None
    if node.op.filter_dilation != (1, 1):
        return None

    rval = conv2d(
        img,
        kern,
        node.op.imshp,
        node.op.kshp,
        border_mode=node.op.border_mode,
        subsample=node.op.subsample,
    )

    copy_stack_trace(node.outputs[0], rval)
    return [rval]
Exemple #2
0
 def sym_conv2d(input, filters):
     # define aesara graph and function
     input.name = "input"
     filters.name = "filters"
     rval = conv.conv2d(
         input,
         filters,
         image_shape,
         filter_shape,
         border_mode,
         subsample,
         unroll_batch=unroll_batch,
         unroll_kern=unroll_kern,
         unroll_patch=unroll_patch,
     )
     rval.name = "conv_output"
     return rval
Exemple #3
0
    def speed(self):
        n_calls = 20000
        print("n_calls", n_calls)
        for border_mode in ["valid", "full"]:
            print()
            print(border_mode)
            for openmp in [False, True]:
                print("OpenMP", openmp)
                image_shapes = [(1, 5, 6, 6), (10, 5, 6, 6)
                                # (10, 10, 16, 16),
                                # (10, 10, 32, 32)]
                                ]
                print("image_shape", image_shapes)
                for image_shape in image_shapes:
                    filter_shapes = [(1, 5, 4, 4), (2, 5, 4, 4), (5, 5, 4, 4)]
                    print("filter_shapes", filter_shapes)
                    for filter_shape in filter_shapes:

                        input = aesara.shared(np.random.random(image_shape))
                        filters = aesara.shared(np.random.random(filter_shape))

                        with pytest.warns(DeprecationWarning):
                            output = conv.conv2d(
                                input,
                                filters,
                                image_shape,
                                filter_shape,
                                border_mode,
                                unroll_patch=True,
                                openmp=openmp,
                            )
                        mode = Mode(linker=aesara.link.vm.VMLinker(
                            allow_gc=False, use_cloop=True))
                        aesara_conv = aesara.function([], output, mode=mode)
                        t1 = time.time()
                        aesara_conv.vm(n_calls=n_calls)
                        t2 = time.time()
                        print(t2 - t1, end=" ")
                    print()
Exemple #4
0
    def test_infer_shape(self):
        # Note: infer_shape is incomplete and thus input and filter shapes
        # must be provided explicitly

        rng = np.random.default_rng(280284)

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

        adtens = dtensor4()
        bdtens = dtensor4()
        aivec_val = [4, 5, 6, 3]
        bivec_val = [7, 5, 3, 2]
        adtens_val = rand(*aivec_val)
        bdtens_val = rand(*bivec_val)
        with pytest.warns(DeprecationWarning):
            self._compile_and_check(
                [adtens, bdtens],
                [
                    conv.conv2d(adtens,
                                bdtens,
                                aivec_val,
                                bivec_val,
                                border_mode="valid")
                ],
                [adtens_val, bdtens_val],
                conv.ConvOp,
                excluding=["conv_gemm"],
            )

        with pytest.warns(DeprecationWarning):
            self._compile_and_check(
                [adtens, bdtens],
                [
                    conv.conv2d(adtens,
                                bdtens,
                                aivec_val,
                                bivec_val,
                                border_mode="full")
                ],
                [adtens_val, bdtens_val],
                conv.ConvOp,
                excluding=["conv_gemm"],
            )

        aivec_val = [6, 2, 8, 3]
        bivec_val = [4, 2, 5, 3]
        adtens_val = rand(*aivec_val)
        bdtens_val = rand(*bivec_val)
        with pytest.warns(DeprecationWarning):
            self._compile_and_check(
                [adtens, bdtens],
                [
                    conv.conv2d(adtens,
                                bdtens,
                                aivec_val,
                                bivec_val,
                                border_mode="valid")
                ],
                [adtens_val, bdtens_val],
                conv.ConvOp,
                excluding=["conv_gemm"],
            )

        with pytest.warns(DeprecationWarning):
            self._compile_and_check(
                [adtens, bdtens],
                [
                    conv.conv2d(adtens,
                                bdtens,
                                aivec_val,
                                bivec_val,
                                border_mode="full")
                ],
                [adtens_val, bdtens_val],
                conv.ConvOp,
                excluding=["conv_gemm"],
            )

        aivec_val = [3, 6, 7, 5]
        bivec_val = [5, 6, 3, 2]
        adtens_val = rand(*aivec_val)
        bdtens_val = rand(*bivec_val)
        with pytest.warns(DeprecationWarning):
            self._compile_and_check(
                [adtens, bdtens],
                [
                    conv.conv2d(adtens,
                                bdtens,
                                aivec_val,
                                bivec_val,
                                border_mode="valid")
                ],
                [adtens_val, bdtens_val],
                conv.ConvOp,
                excluding=["conv_gemm"],
            )

        with pytest.warns(DeprecationWarning):
            self._compile_and_check(
                [adtens, bdtens],
                [
                    conv.conv2d(adtens,
                                bdtens,
                                aivec_val,
                                bivec_val,
                                border_mode="full")
                ],
                [adtens_val, bdtens_val],
                conv.ConvOp,
                excluding=["conv_gemm"],
            )

        aivec_val = [3, 6, 7, 5]
        bivec_val = [5, 6, 2, 3]
        adtens_val = rand(*aivec_val)
        bdtens_val = rand(*bivec_val)
        with pytest.warns(DeprecationWarning):
            self._compile_and_check(
                [adtens, bdtens],
                [
                    conv.conv2d(adtens,
                                bdtens,
                                aivec_val,
                                bivec_val,
                                border_mode="valid")
                ],
                [adtens_val, bdtens_val],
                conv.ConvOp,
                excluding=["conv_gemm"],
            )

        with pytest.warns(DeprecationWarning):
            self._compile_and_check(
                [adtens, bdtens],
                [
                    conv.conv2d(adtens,
                                bdtens,
                                aivec_val,
                                bivec_val,
                                border_mode="full")
                ],
                [adtens_val, bdtens_val],
                conv.ConvOp,
                excluding=["conv_gemm"],
            )

        aivec_val = [5, 2, 4, 3]
        bivec_val = [6, 2, 4, 3]
        adtens_val = rand(*aivec_val)
        bdtens_val = rand(*bivec_val)
        with pytest.warns(DeprecationWarning):
            self._compile_and_check(
                [adtens, bdtens],
                [
                    conv.conv2d(adtens,
                                bdtens,
                                aivec_val,
                                bivec_val,
                                border_mode="valid")
                ],
                [adtens_val, bdtens_val],
                conv.ConvOp,
                excluding=["conv_gemm"],
            )

        with pytest.warns(DeprecationWarning):
            self._compile_and_check(
                [adtens, bdtens],
                [
                    conv.conv2d(adtens,
                                bdtens,
                                aivec_val,
                                bivec_val,
                                border_mode="full")
                ],
                [adtens_val, bdtens_val],
                conv.ConvOp,
                excluding=["conv_gemm"],
            )