예제 #1
0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import paddle.fluid as fluid
import os
file_dir = os.path.dirname(os.path.abspath(__file__))
fluid.load_op_library(os.path.join(file_dir, 'correlation_lib.so'))

from paddle.fluid.layer_helper import LayerHelper


def correlation(input1,
                input2,
                pad_size,
                kernel_size,
                max_displacement,
                stride1,
                stride2,
                corr_type_multiply=1):
    helper = LayerHelper("correlation", **locals())
    output = helper.create_variable_for_type_inference(dtype=input1.dtype)
    helper.append_op(type="correlation",
예제 #2
0
    mpc_data_utils_lib = _paddle_enc_lib_path + '/mpc_data_utils.so'
    psi_lib = _paddle_enc_lib_path + '/libpsi.so'

    set_rpath(
        _paddle_enc_lib, paddle_lib_path + ":" + _paddle_enc_lib_path + ":" +
        third_party_lib_path)
    set_rpath(
        mpc_data_utils_lib,
        paddle_lib_path + ":" + _paddle_enc_lib_path + ":" + openssl_lib_path)
    if os.path.exists(psi_lib):
        set_rpath(psi_lib, openssl_lib_path)


sys.path.append(_paddle_enc_lib_path)
set_rpath_to_all_libs()
fluid.load_op_library(_paddle_enc_lib)

from .data import *
from . import layers
from .optimizer import *
from .mpc_init import *

from . import data_utils
from .io import *
from .version import version
from .layers import mpc_math_op_patch
from . import input
from . import initializer

mpc_math_op_patch.monkey_patch_mpc_variable()
예제 #3
0
import os
import paddle.fluid as fluid

use_cpp = False

file_dir = os.path.dirname(os.path.abspath(__file__))
try:
    fluid.load_op_library(os.path.join(file_dir, 'src/cornerpool_lib.so'))
    use_cpp = True
except:
    print(
        'Warning: cornerpool_lib.so not found, use python version instead which may drop the inference speed. Compile in ppdet/ext_op at first if you need cpp version.'
    )

from paddle.fluid.layer_helper import LayerHelper

__all__ = [
    'bottom_pool',
    'top_pool',
    'right_pool',
    'left_pool',
]


def cornerpool_op(layer_type, input, name):
    helper = LayerHelper(layer_type, input=input, name=name)
    dtype = helper.input_dtype()
    output = helper.create_variable_for_type_inference(dtype)
    max_map = helper.create_variable_for_type_inference(dtype)
    helper.append_op(type=layer_type,
                     inputs={"X": input},
예제 #4
0
# -*- coding: utf-8
import os
import paddle.fluid as fluid
# 调用load_op_library加载动态库
file_dir = os.path.dirname(os.path.abspath(__file__))
fluid.load_op_library(os.path.join(file_dir, 'lib/rerank.so'))

from paddle.fluid.layer_helper import LayerHelper


def vmat(x, name=None):
    # vmat的type和在OP中定义的type相同
    helper = LayerHelper("vmat", **locals())
    # 创建输出Variable
    out = helper.create_variable_for_type_inference(dtype=x.dtype)
    helper.append_op(type="vmat", inputs={"X": x}, outputs={"Y": out})
    return out


def qe(V, R, S, name=None):
    # qe的type和在OP中定义的type相同
    helper = LayerHelper("qe", **locals())
    # 创建输出Variable
    out = helper.create_variable_for_type_inference(dtype=V.dtype)
    helper.append_op(type="qe",
                     inputs={
                         "V": V,
                         "R": R,
                         "S": S
                     },
                     outputs={"Y": out})
예제 #5
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys
import numpy as np
import unittest
import contextlib

import paddle
import paddle.fluid as fluid

file_dir = os.path.dirname(os.path.abspath(__file__))
fluid.load_op_library(os.path.join(file_dir, 'librelu2_op.so'))

from paddle.fluid.layer_helper import LayerHelper


def relu2(x, name=None):
    helper = LayerHelper("relu2", **locals())
    out = helper.create_variable(type=x.type,
                                 name=name,
                                 dtype=x.dtype,
                                 persistable=False)
    helper.append_op(type="relu2", inputs={"X": x}, outputs={"Y": out})
    return out


@contextlib.contextmanager
예제 #6
0
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

import os
import paddle.fluid as fluid

file_dir = os.path.dirname(os.path.abspath(__file__))
fluid.load_op_library(os.path.join(file_dir, 'src/custom_lib.so'))

from paddle.fluid.layer_helper import LayerHelper

__all__ = ['gather_dim']


def gather_dim(input, index):
    """
    **Gather Dim Layer**
    Output is obtained by gathering entries of X indexed by `index`
    and concatenate them together.
    .. math::
        Out = X[Index]
    .. code-block:: text
        Given:
예제 #7
0
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

import os
import paddle.fluid as fluid

file_dir = os.path.dirname(os.path.abspath(__file__))
fluid.load_op_library(os.path.join(file_dir, 'src/pointnet_lib.so'))

from paddle.fluid.layer_helper import LayerHelper

__all__ = [
    'three_nn', 'three_interp', 'query_ball', 'gather_point',
    'farthest_point_sampling', 'group_points'
]


def three_nn(input, known, eps=1e-10, name=None):
    """
    **Three Nearest Neighbor Layer**

    This operator samples the top-3 nearest neighbor of each point
    coordinates specified by Input(X) between known point coordinates
예제 #8
0
import os

import paddle
import paddle.fluid as fluid
from paddle.fluid.layer_helper import LayerHelper

# 调用load_op_library加载动态库
# os.environ["FLAGS_op_dir"] = "/work/scripts/custom_op"
fluid.load_op_library('relu2_op.so')


def relu2(x, name=None):
    # relu2的type和在OP中定义的type相同
    helper = LayerHelper("relu2", **locals())
    # 创建输出Variable
    out = helper.create_variable_for_type_inference(dtype=x.dtype)
    helper.append_op(type="relu2", inputs={"X": [x]}, outputs={"Y": out})
    return out
예제 #9
0
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

import paddle.fluid as fluid
from paddle.fluid.layer_helper import LayerHelper
from paddle.fluid.framework import Variable
fluid.load_op_library('models/ext_op/src/rrpn_lib.so')


def rrpn_target_assign(bbox_pred,
                       cls_logits,
                       anchor_box,
                       gt_boxes,
                       im_info,
                       rpn_batch_size_per_im=256,
                       rpn_straddle_thresh=0.0,
                       rpn_fg_fraction=0.5,
                       rpn_positive_overlap=0.7,
                       rpn_negative_overlap=0.3,
                       use_random=True):
    """
    **Target Assign Layer for rotated region proposal network (RRPN).**
예제 #10
0
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

import paddle.fluid as fluid
from paddle.fluid.layer_helper import LayerHelper
from paddle.fluid.framework import Variable
fluid.load_op_library('rrpn_lib.so')


def rrpn_target_assign(bbox_pred,
                       cls_logits,
                       anchor_box,
                       gt_boxes,
                       im_info,
                       rpn_batch_size_per_im=256,
                       rpn_straddle_thresh=0.0,
                       rpn_fg_fraction=0.5,
                       rpn_positive_overlap=0.7,
                       rpn_negative_overlap=0.3,
                       use_random=True):
    """
    **Target Assign Layer for rotated region proposal network (RRPN).**
예제 #11
0
def load_so(so_name):
    """
    Load .so file and parse custom op into OpInfoMap.
    """
    file_dir = os.path.dirname(os.path.abspath(__file__))
    fluid.load_op_library(os.path.join(file_dir, so_name))