def _import_prroi_pooling(): global _prroi_pooling if _prroi_pooling is None: try: from os.path import join as pjoin, dirname from torch.utils.cpp_extension import load as load_extension root_dir = pjoin(dirname(__file__), 'src') _prroi_pooling = load_extension('_prroi_pooling', [ pjoin(root_dir, 'prroi_pooling_gpu.c'), pjoin(root_dir, 'prroi_pooling_gpu_impl.cu') ], verbose=True) except ImportError: raise ImportError('Can not compile Precise RoI Pooling library.') return _prroi_pooling
import torch from torch.autograd import Function from torch.nn.modules.utils import _pair import cffi # from .._ext import depthconv import torch.autograd as ag try: from os.path import join as pjoin, dirname from torch.utils.cpp_extension import load as load_extension root_dir = pjoin(dirname(__file__), '../src_pytorch13') depthconv = load_extension('_depthconv', [ pjoin(root_dir, 'depthconv_cuda_redo.c'), pjoin(root_dir, 'depthconv_cuda_kernel.cu') ], verbose=True) except ImportError: raise ImportError('Can not compile depth-aware cnn library.') __all__ = ['depth_conv'] def depth_conv(input, depth, weight, bias, stride=1, padding=0, dilation=1): if input is not None and input.dim() != 4: raise ValueError( "Expected 4D tensor as input, got {}D tensor instead.".format( input.dim())) f = DepthconvFunction(_pair(stride), _pair(padding), _pair(dilation))
import torch try: from os.path import join as pjoin, dirname from torch.utils.cpp_extension import load as load_extension root_dir = pjoin(dirname(__file__), 'src') _psroi_pooling = load_extension( '_psroi_pooling', [ pjoin(root_dir, 'psroi_pooling_cuda.c'), pjoin(root_dir, 'cuda/psroi_pooling_kernel.cu') ], verbose=True, ) except ImportError: raise ImportError('Can not compile Position Sensitive RoI Pooling library.') class PsRoIPool2DFunction(torch.autograd.Function): def __init__(self, pooled_height: int, pooled_width: int, spatial_scale: float, group_size: int, output_dim: int): self.pooled_width = int(pooled_width) self.pooled_height = int(pooled_height) self.spatial_scale = float(spatial_scale) self.group_size = int(group_size) self.output_dim = int(output_dim) self.output = None self.mappingchannel = None self.rois = None
import torch try: from os.path import join as pjoin, dirname from torch.utils.cpp_extension import load as load_extension root_dir = pjoin(dirname(__file__), 'src') _prroi_pooling = load_extension( '_prroi_pooling', [ pjoin(root_dir, 'prroi_pooling_gpu.c'), pjoin(root_dir, 'prroi_pooling_gpu_impl.cu') ], ) except ImportError: raise ImportError('Can not compile Precise RoI Pooling library.') __all__ = ['prroi_pool2d'] class PrRoIPool2DFunction(torch.autograd.Function): @staticmethod def forward(ctx, features, rois, pooled_height, pooled_width, spatial_scale): assert isinstance(features, torch.cuda.FloatTensor) or isinstance(rois, torch.cuda.FloatTensor), \ 'Precise RoI Pooling only takes float input, got {} for features and {} for rois.'.format(features.type(), rois.type()) pooled_height = int(pooled_height) pooled_width = int(pooled_width) spatial_scale = float(spatial_scale) features = features.contiguous() rois = rois.contiguous()
# Date : 07/13/2018 # # This file is part of PreciseRoIPooling. # Distributed under terms of the MIT license. # Copyright (c) 2017 Megvii Technology Limited. import torch import torch.autograd as ag try: from os.path import join as pjoin, dirname from torch.utils.cpp_extension import load as load_extension root_dir = pjoin(dirname(__file__), 'src') _prroi_pooling = load_extension( '_prroi_pooling', [pjoin(root_dir, 'prroi_pooling_gpu.c'), pjoin(root_dir, 'prroi_pooling_gpu_impl.cu')], verbose=True ) except ImportError: raise ImportError('Can not compile Precise RoI Pooling library.') __all__ = ['prroi_pool2d'] class PrRoIPool2DFunction(ag.Function): @staticmethod def forward(ctx, features, rois, pooled_height, pooled_width, spatial_scale): assert 'FloatTensor' in features.type() and 'FloatTensor' in rois.type(), \ 'Precise RoI Pooling only takes float input, got {} for features and {} for rois.'.format(features.type(), rois.type()) pooled_height = int(pooled_height)