예제 #1
0
    def __init__(self, img_ch=3):
        super(RefineNet_DeMoN, self).__init__()

        self.conv0 = m_submodule.conv2d_leakyRelu(ch_in=img_ch + 1,
                                                  ch_out=32,
                                                  kernel_size=3,
                                                  stride=1,
                                                  pad=1,
                                                  use_bias=True)

        self.conv1 = m_submodule.conv2d_leakyRelu(ch_in=32,
                                                  ch_out=64,
                                                  kernel_size=3,
                                                  stride=2,
                                                  pad=1,
                                                  use_bias=True)
        self.conv1_1 = m_submodule.conv2d_leakyRelu(ch_in=64,
                                                    ch_out=64,
                                                    kernel_size=3,
                                                    stride=1,
                                                    pad=1,
                                                    use_bias=True)

        self.conv2 = m_submodule.conv2d_leakyRelu(ch_in=64,
                                                  ch_out=128,
                                                  kernel_size=3,
                                                  stride=2,
                                                  pad=1,
                                                  use_bias=True)
        self.conv2_1 = m_submodule.conv2d_leakyRelu(ch_in=128,
                                                    ch_out=128,
                                                    kernel_size=3,
                                                    stride=1,
                                                    pad=1,
                                                    use_bias=True)

        self.trans_conv0 = m_submodule.conv2dTranspose_leakyRelu(ch_in=128,
                                                                 ch_out=64,
                                                                 kernel_size=4,
                                                                 stride=2,
                                                                 pad=1,
                                                                 use_bias=True)
        self.trans_conv1 = m_submodule.conv2dTranspose_leakyRelu(ch_in=128,
                                                                 ch_out=32,
                                                                 kernel_size=4,
                                                                 stride=2,
                                                                 pad=1,
                                                                 use_bias=True)

        self.conv3 = m_submodule.conv2d_leakyRelu(ch_in=64,
                                                  ch_out=16,
                                                  kernel_size=3,
                                                  stride=1,
                                                  pad=1,
                                                  use_bias=True)
        self.conv3_1 = nn.Conv2d(16,
                                 1,
                                 kernel_size=3,
                                 stride=1,
                                 padding=1,
                                 bias=True)

        self.apply(self.weight_init)
예제 #2
0
    def __init__(self, in_channels):
        '''
        in_channels - for example, if we use some statistics from DPV, plus the raw rgb input image, then
                      in_channels = 3 + # of statistics we used from DPV
                      Statistics of DPV can includes {expected mean, variance, min_v, max_v etc. }
        '''
        super(RefineNet_Unet2D, self).__init__()

        self.conv0 = m_submodule.conv2d_leakyRelu(ch_in=in_channels,
                                                  ch_out=32,
                                                  kernel_size=3,
                                                  stride=1,
                                                  pad=1,
                                                  use_bias=True)
        self.conv0_1 = m_submodule.conv2d_leakyRelu(ch_in=32,
                                                    ch_out=32,
                                                    kernel_size=3,
                                                    stride=1,
                                                    pad=1,
                                                    use_bias=True)

        self.conv1 = m_submodule.conv2d_leakyRelu(ch_in=32,
                                                  ch_out=64,
                                                  kernel_size=3,
                                                  stride=2,
                                                  pad=1,
                                                  use_bias=True)
        self.conv1_1 = m_submodule.conv2d_leakyRelu(ch_in=64,
                                                    ch_out=64,
                                                    kernel_size=3,
                                                    stride=1,
                                                    pad=1,
                                                    use_bias=True)

        self.conv2 = m_submodule.conv2d_leakyRelu(ch_in=64,
                                                  ch_out=128,
                                                  kernel_size=3,
                                                  stride=2,
                                                  pad=1,
                                                  use_bias=True)
        self.conv2_1 = m_submodule.conv2d_leakyRelu(ch_in=128,
                                                    ch_out=128,
                                                    kernel_size=3,
                                                    stride=1,
                                                    pad=1,
                                                    use_bias=True)

        self.trans_conv0 = m_submodule.conv2dTranspose_leakyRelu(ch_in=128,
                                                                 ch_out=64,
                                                                 kernel_size=4,
                                                                 stride=2,
                                                                 pad=1,
                                                                 use_bias=True)
        self.trans_conv1 = m_submodule.conv2dTranspose_leakyRelu(ch_in=128,
                                                                 ch_out=32,
                                                                 kernel_size=4,
                                                                 stride=2,
                                                                 pad=1,
                                                                 use_bias=True)

        self.conv3 = m_submodule.conv2d_leakyRelu(ch_in=64,
                                                  ch_out=16,
                                                  kernel_size=3,
                                                  stride=1,
                                                  pad=1,
                                                  use_bias=True)
        self.conv3_1 = nn.Conv2d(16,
                                 1,
                                 kernel_size=3,
                                 stride=1,
                                 padding=1,
                                 bias=True)

        self.apply(self.weight_init)
예제 #3
0
    def __init__(self, C0, C1, C2, D=64, upsample_D=False):
        '''
        Inputs: 

        C0 - feature channels in .25 image resolution feature,
        C1 - feature cnahnels in .5 image resolution feature,
        C2 - feature cnahnels in 1 image resolution feature,

        D - the length of d_candi, we will treat the D dimension as the feature dimension
        upsample_D - if upsample in the D dimension 
        '''
        super(RefineNet_DPV_upsample, self).__init__()
        in_channels = D + C0

        if upsample_D:
            D0 = 2 * D
            D1 = 2 * D0
        else:
            D0 = D
            D1 = D

        self.conv0 = m_submodule.conv2d_leakyRelu(ch_in=in_channels,
                                                  ch_out=in_channels,
                                                  kernel_size=3,
                                                  stride=1,
                                                  pad=1,
                                                  use_bias=True)

        self.conv0_1 = m_submodule.conv2d_leakyRelu(ch_in=in_channels,
                                                    ch_out=in_channels,
                                                    kernel_size=3,
                                                    stride=1,
                                                    pad=1,
                                                    use_bias=True)

        self.trans_conv0 = m_submodule.conv2dTranspose_leakyRelu(
            ch_in=in_channels,
            ch_out=D0,
            kernel_size=4,
            stride=2,
            pad=1,
            use_bias=True)

        self.conv1 = m_submodule.conv2d_leakyRelu(ch_in=D0 + C1,
                                                  ch_out=D0 + C1,
                                                  kernel_size=3,
                                                  stride=1,
                                                  pad=1,
                                                  use_bias=True)

        self.conv1_1 = m_submodule.conv2d_leakyRelu(ch_in=D0 + C1,
                                                    ch_out=D0 + C1,
                                                    kernel_size=3,
                                                    stride=1,
                                                    pad=1,
                                                    use_bias=True)

        self.trans_conv1 = m_submodule.conv2dTranspose_leakyRelu(ch_in=D0 + C1,
                                                                 ch_out=D1,
                                                                 kernel_size=4,
                                                                 stride=2,
                                                                 pad=1,
                                                                 use_bias=True)

        self.conv2 = m_submodule.conv2d_leakyRelu(ch_in=D1 + C2,
                                                  ch_out=D1 + C2,
                                                  kernel_size=3,
                                                  stride=1,
                                                  pad=1,
                                                  use_bias=True)

        self.conv2_1 = m_submodule.conv2d_leakyRelu(ch_in=D1 + C2,
                                                    ch_out=D1,
                                                    kernel_size=3,
                                                    stride=1,
                                                    pad=1,
                                                    use_bias=True)

        self.conv2_2 = nn.Conv2d(D1,
                                 D1,
                                 kernel_size=3,
                                 stride=1,
                                 padding=1,
                                 bias=True)

        self.apply(self.weight_init)
예제 #4
0
    def __init__(self,
                 feature_extraction,
                 cam_intrinsics,
                 d_candi,
                 sigma_soft_max,
                 BV_log=False,
                 normalize=True,
                 use_img_intensity=False,
                 force_img_dw_rate=1,
                 parallel_d=True,
                 output_features=False,
                 refine_costV=False,
                 feat_dist='L2'):
        '''
        INPUTS: 

        feature_extraction - the feature extrator module

        cam_intrinsic - {'hfov': hfov, 'vfov': vfov, 'unit_ray_array': unit_ray_array, 'intrinsic_M'} : 
            hfov, vfov - fovs in horzontal and vertical directions (degrees)
            unit_ray_array - A tensor with size (height, width, 3). Each 'pixel' corresponds to the
            unit ray pointing from the camera center to the pixel

        d_candi - np array of candidate depths 

        output_features - if output the features from the feature extractor. If ture, forward() will also return multi-scale 
                          image features (.25 and .5 image sizes) from the feature extractor
                          In this case, the output features will be saved in a list: [ img_feat_final, img_feat_layer1]
                          where img_feat_layer1 is the .5 image size feature

        refine_costV - if do the optional convolutions to refine costV before soft_max(costV)

        feat_dist - 'L2' (default) or 'L1' distance for feature matching

        '''

        super(D_NET_BASIC, self).__init__()
        self.feature_extraction = feature_extraction
        self.cam_intrinsics = cam_intrinsics
        self.d_candi = d_candi
        self.sigma_soft_max = sigma_soft_max
        self.BV_log = BV_log
        self.normalize = normalize
        self.use_img_intensity = use_img_intensity
        self.parallel_d = parallel_d
        self.output_features = output_features
        self.refine_costV = refine_costV
        self.feat_dist = feat_dist
        self.refine_costV = refine_costV

        if force_img_dw_rate > 1:
            self.force_img_dw_rate = force_img_dw_rate  # Force to downsampling the input images
        else:
            self.force_img_dw_rate = None

        if self.refine_costV:
            D = len(d_candi)
            self.conv0 = m_submodule.conv2d_leakyRelu(ch_in=D,
                                                      ch_out=D,
                                                      kernel_size=3,
                                                      stride=1,
                                                      pad=1,
                                                      use_bias=True)
            self.conv0_1 = m_submodule.conv2d_leakyRelu(ch_in=D,
                                                        ch_out=D,
                                                        kernel_size=3,
                                                        stride=1,
                                                        pad=1,
                                                        use_bias=True)
            self.conv0_2 = nn.Conv2d(D,
                                     D,
                                     kernel_size=3,
                                     stride=1,
                                     padding=1,
                                     bias=True)
            self.apply(self.weight_init)