當前位置: 首頁>>代碼示例>>Python>>正文


Python conv3d2d.conv3d方法代碼示例

本文整理匯總了Python中theano.tensor.nnet.conv3d2d.conv3d方法的典型用法代碼示例。如果您正苦於以下問題:Python conv3d2d.conv3d方法的具體用法?Python conv3d2d.conv3d怎麽用?Python conv3d2d.conv3d使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在theano.tensor.nnet.conv3d2d的用法示例。


在下文中一共展示了conv3d2d.conv3d方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: set_output

# 需要導入模塊: from theano.tensor.nnet import conv3d2d [as 別名]
# 或者: from theano.tensor.nnet.conv3d2d import conv3d [as 別名]
def set_output(self):
        padding = self._padding
        input_shape = self._input_shape
        if np.sum(self._padding) > 0:
            padded_input = tensor.alloc(0.0,  # Value to fill the tensor
                                        input_shape[0],
                                        input_shape[1] + 2 * padding[1],
                                        input_shape[2],
                                        input_shape[3] + 2 * padding[3],
                                        input_shape[4] + 2 * padding[4])

            padded_input = tensor.set_subtensor(
                padded_input[:, padding[1]:padding[1] + input_shape[1], :, padding[3]:padding[3] +
                             input_shape[3], padding[4]:padding[4] + input_shape[4]],
                self._prev_layer.output)
        else:
            padded_input = self._prev_layer.output

        self._output = conv3d2d.conv3d(padded_input, self.W.val) + \
            self.b.val.dimshuffle('x', 'x', 0, 'x', 'x') 
開發者ID:chrischoy,項目名稱:3D-R2N2,代碼行數:22,代碼來源:layers.py

示例2: __init__

# 需要導入模塊: from theano.tensor.nnet import conv3d2d [as 別名]
# 或者: from theano.tensor.nnet.conv3d2d import conv3d [as 別名]
def __init__(self, prev_layers, axis=1):
        """
        list of prev layers to concatenate
        axis to concatenate

        For tensor5, channel dimension is axis=2 (due to theano conv3d
        convention). For image, axis=1
        """
        assert (len(prev_layers) > 1)
        super().__init__(prev_layers[0])
        self._axis = axis
        self._prev_layers = prev_layers

        self._output_shape = self._input_shape.copy()
        for prev_layer in prev_layers[1:]:
            self._output_shape[axis] += prev_layer._output_shape[axis]
        print('Concat the prev layer to [%s]' % ','.join(str(x) for x in self._output_shape)) 
開發者ID:chrischoy,項目名稱:3D-R2N2,代碼行數:19,代碼來源:layers.py

示例3: conv3d

# 需要導入模塊: from theano.tensor.nnet import conv3d2d [as 別名]
# 或者: from theano.tensor.nnet.conv3d2d import conv3d [as 別名]
def conv3d(x, kernel, strides=(1, 1, 1),
           border_mode='valid', dim_ordering='default',
           volume_shape=None, filter_shape=None,
           filter_dilation=(1, 1, 1)):
    '''3D convolution.

    # Arguments
        kernel: kernel tensor.
        strides: strides tuple.
        border_mode: string, "same" or "valid".
        dim_ordering: "tf" or "th".
            Whether to use Theano or TensorFlow dimension ordering
        in inputs/kernels/ouputs.
    '''
    if dim_ordering == 'default':
        dim_ordering = image_dim_ordering()
    if dim_ordering not in {'th', 'tf'}:
        raise Exception('Unknown dim_ordering ' + str(dim_ordering))

    # TODO: remove this if statement when Theano without AbstractConv3d is deprecated
    if not hasattr(T.nnet, 'conv3d'):
        if filter_dilation != (1, 1, 1):
            raise Exception('conv3d with filter dilation requires Theano '
                            '0.9.0dev3 or newer.')

        return _old_theano_conv3d(x, kernel, strides, border_mode,
                                  dim_ordering, volume_shape, filter_shape)

    x = _preprocess_conv3d_input(x, dim_ordering)
    kernel = _preprocess_conv3d_kernel(kernel, dim_ordering)
    th_border_mode = _preprocess_border_mode(border_mode)
    np_kernel = kernel.eval()
    volume_shape = _preprocess_conv3d_volume_shape(dim_ordering, volume_shape)
    filter_shape = _preprocess_conv3d_filter_shape(dim_ordering, filter_shape)

    conv_out = T.nnet.conv3d(x, kernel,
                             border_mode=th_border_mode,
                             subsample=strides,
                             input_shape=volume_shape,
                             filter_shape=filter_shape,
                             filter_dilation=filter_dilation)

    conv_out = _postprocess_conv3d_output(conv_out, x, border_mode, np_kernel,
                                          strides, dim_ordering)
    return conv_out


# TODO: remove this function when theano without AbstractConv3d is deprecated 
開發者ID:GeekLiB,項目名稱:keras,代碼行數:50,代碼來源:theano_backend.py

示例4: conv3d

# 需要導入模塊: from theano.tensor.nnet import conv3d2d [as 別名]
# 或者: from theano.tensor.nnet.conv3d2d import conv3d [as 別名]
def conv3d(x, kernel, strides=(1, 1, 1),
           border_mode='valid', dim_ordering='default',
           volume_shape=None, filter_shape=None,
           filter_dilation=(1, 1, 1)):
    """3D convolution.

    # Arguments
        kernel: kernel tensor.
        strides: strides tuple.
        border_mode: string, "same" or "valid".
        dim_ordering: "tf" or "th".
            Whether to use Theano or TensorFlow dimension ordering
        in inputs/kernels/ouputs.
    """
    if dim_ordering == 'default':
        dim_ordering = image_dim_ordering()
    if dim_ordering not in {'th', 'tf'}:
        raise ValueError('Unknown dim_ordering:', dim_ordering)

    # TODO: remove this if statement when Theano without AbstractConv3d is deprecated
    if not hasattr(T.nnet, 'conv3d'):
        if filter_dilation != (1, 1, 1):
            raise ValueError('conv3d with filter dilation requires Theano '
                             '0.9.0dev3 or newer.')

        return _old_theano_conv3d(x, kernel, strides, border_mode,
                                  dim_ordering, volume_shape, filter_shape)

    x = _preprocess_conv3d_input(x, dim_ordering)
    kernel = _preprocess_conv3d_kernel(kernel, dim_ordering)
    th_border_mode = _preprocess_border_mode(border_mode)

    if hasattr(kernel, '_keras_shape'):
        kernel_shape = kernel._keras_shape
    else:
        # Will only work if `kernel` is a shared variable.
        kernel_shape = kernel.eval().shape

    volume_shape = _preprocess_conv3d_volume_shape(dim_ordering, volume_shape)
    filter_shape = _preprocess_conv3d_filter_shape(dim_ordering, filter_shape)

    conv_out = T.nnet.conv3d(x, kernel,
                             border_mode=th_border_mode,
                             subsample=strides,
                             input_shape=volume_shape,
                             filter_shape=filter_shape,
                             filter_dilation=filter_dilation)

    conv_out = _postprocess_conv3d_output(conv_out, x, border_mode,
                                          kernel_shape, strides, dim_ordering)
    return conv_out


# TODO: remove this function when theano without AbstractConv3d is deprecated 
開發者ID:jasmeetsb,項目名稱:deep-learning-keras-projects,代碼行數:56,代碼來源:theano_backend.py

示例5: _old_theano_conv3d

# 需要導入模塊: from theano.tensor.nnet import conv3d2d [as 別名]
# 或者: from theano.tensor.nnet.conv3d2d import conv3d [as 別名]
def _old_theano_conv3d(x, kernel, strides=(1, 1, 1),
                       border_mode='valid', dim_ordering='default',
                       volume_shape=None, filter_shape=None):
    """
    Run on cuDNN if available.
    border_mode: string, "same" or "valid".
    """
    if dim_ordering == 'default':
        dim_ordering = image_dim_ordering()
    if dim_ordering not in {'th', 'tf'}:
        raise ValueError('Unknown dim_ordering:', dim_ordering)
    if border_mode not in {'same', 'valid'}:
        raise ValueError('Invalid border mode:', border_mode)

    if dim_ordering == 'tf':
        # TF uses the last dimension as channel dimension,
        # instead of the 2nd one.
        # TH input shape: (samples, input_depth, conv_dim1, conv_dim2, conv_dim3)
        # TF input shape: (samples, conv_dim1, conv_dim2, conv_dim3, input_depth)
        # TH kernel shape: (out_depth, input_depth, kernel_dim1, kernel_dim2, kernel_dim3)
        # TF kernel shape: (kernel_dim1, kernel_dim2, kernel_dim3, input_depth, out_depth)
        x = x.dimshuffle((0, 4, 1, 2, 3))
        kernel = kernel.dimshuffle((4, 3, 0, 1, 2))
        if volume_shape:
            volume_shape = (volume_shape[0], volume_shape[4],
                            volume_shape[1], volume_shape[2], volume_shape[3])
        if filter_shape:
            filter_shape = (filter_shape[4], filter_shape[3],
                            filter_shape[0], filter_shape[1], filter_shape[2])

    if border_mode == 'same':
        assert(strides == (1, 1, 1))
        pad_dim1 = (kernel.shape[2] - 1)
        pad_dim2 = (kernel.shape[3] - 1)
        pad_dim3 = (kernel.shape[4] - 1)
        output_shape = (x.shape[0], x.shape[1],
                        x.shape[2] + pad_dim1,
                        x.shape[3] + pad_dim2,
                        x.shape[4] + pad_dim3)
        output = T.zeros(output_shape)
        indices = (slice(None), slice(None),
                   slice(pad_dim1 // 2, x.shape[2] + pad_dim1 // 2),
                   slice(pad_dim2 // 2, x.shape[3] + pad_dim2 // 2),
                   slice(pad_dim3 // 2, x.shape[4] + pad_dim3 // 2))
        x = T.set_subtensor(output[indices], x)
        border_mode = 'valid'

    border_mode_3d = (border_mode, border_mode, border_mode)
    conv_out = conv3d2d.conv3d(signals=x.dimshuffle(0, 2, 1, 3, 4),
                               filters=kernel.dimshuffle(0, 2, 1, 3, 4),
                               border_mode=border_mode_3d)
    conv_out = conv_out.dimshuffle(0, 2, 1, 3, 4)

    # support strides by manually slicing the output
    if strides != (1, 1, 1):
        conv_out = conv_out[:, :, ::strides[0], ::strides[1], ::strides[2]]

    if dim_ordering == 'tf':
        conv_out = conv_out.dimshuffle((0, 2, 3, 4, 1))

    return conv_out 
開發者ID:jasmeetsb,項目名稱:deep-learning-keras-projects,代碼行數:63,代碼來源:theano_backend.py

示例6: conv3d

# 需要導入模塊: from theano.tensor.nnet import conv3d2d [as 別名]
# 或者: from theano.tensor.nnet.conv3d2d import conv3d [as 別名]
def conv3d(x, kernel, strides=(1, 1, 1),
           border_mode='valid', dim_ordering='default',
           volume_shape=None, filter_shape=None,
           filter_dilation=(1, 1, 1)):
    '''3D convolution.

    # Arguments
        kernel: kernel tensor.
        strides: strides tuple.
        border_mode: string, "same" or "valid".
        dim_ordering: "tf" or "th".
            Whether to use Theano or TensorFlow dimension ordering
        in inputs/kernels/ouputs.
    '''
    if dim_ordering == 'default':
        dim_ordering = image_dim_ordering()
    if dim_ordering not in {'th', 'tf'}:
        raise ValueError('Unknown dim_ordering:', dim_ordering)

    # TODO: remove this if statement when Theano without AbstractConv3d is deprecated
    if not hasattr(T.nnet, 'conv3d'):
        if filter_dilation != (1, 1, 1):
            raise ValueError('conv3d with filter dilation requires Theano '
                             '0.9.0dev3 or newer.')

        return _old_theano_conv3d(x, kernel, strides, border_mode,
                                  dim_ordering, volume_shape, filter_shape)

    x = _preprocess_conv3d_input(x, dim_ordering)
    kernel = _preprocess_conv3d_kernel(kernel, dim_ordering)
    th_border_mode = _preprocess_border_mode(border_mode)
    np_kernel = kernel.eval()
    volume_shape = _preprocess_conv3d_volume_shape(dim_ordering, volume_shape)
    filter_shape = _preprocess_conv3d_filter_shape(dim_ordering, filter_shape)

    conv_out = T.nnet.conv3d(x, kernel,
                             border_mode=th_border_mode,
                             subsample=strides,
                             input_shape=volume_shape,
                             filter_shape=filter_shape,
                             filter_dilation=filter_dilation)

    conv_out = _postprocess_conv3d_output(conv_out, x, border_mode, np_kernel,
                                          strides, dim_ordering)
    return conv_out


# TODO: remove this function when theano without AbstractConv3d is deprecated 
開發者ID:ambrite,項目名稱:keras-customized,代碼行數:50,代碼來源:theano_backend.py

示例7: _old_theano_conv3d

# 需要導入模塊: from theano.tensor.nnet import conv3d2d [as 別名]
# 或者: from theano.tensor.nnet.conv3d2d import conv3d [as 別名]
def _old_theano_conv3d(x, kernel, strides=(1, 1, 1),
                       border_mode='valid', dim_ordering='default',
                       volume_shape=None, filter_shape=None):
    '''
    Run on cuDNN if available.
    border_mode: string, "same" or "valid".
    '''
    if dim_ordering == 'default':
        dim_ordering = image_dim_ordering()
    if dim_ordering not in {'th', 'tf'}:
        raise ValueError('Unknown dim_ordering:', dim_ordering)
    if border_mode not in {'same', 'valid'}:
        raise ValueError('Invalid border mode:', border_mode)

    if dim_ordering == 'tf':
        # TF uses the last dimension as channel dimension,
        # instead of the 2nd one.
        # TH input shape: (samples, input_depth, conv_dim1, conv_dim2, conv_dim3)
        # TF input shape: (samples, conv_dim1, conv_dim2, conv_dim3, input_depth)
        # TH kernel shape: (out_depth, input_depth, kernel_dim1, kernel_dim2, kernel_dim3)
        # TF kernel shape: (kernel_dim1, kernel_dim2, kernel_dim3, input_depth, out_depth)
        x = x.dimshuffle((0, 4, 1, 2, 3))
        kernel = kernel.dimshuffle((4, 3, 0, 1, 2))
        if volume_shape:
            volume_shape = (volume_shape[0], volume_shape[4],
                            volume_shape[1], volume_shape[2], volume_shape[3])
        if filter_shape:
            filter_shape = (filter_shape[4], filter_shape[3],
                            filter_shape[0], filter_shape[1], filter_shape[2])

    if border_mode == 'same':
        assert(strides == (1, 1, 1))
        pad_dim1 = (kernel.shape[2] - 1)
        pad_dim2 = (kernel.shape[3] - 1)
        pad_dim3 = (kernel.shape[4] - 1)
        output_shape = (x.shape[0], x.shape[1],
                        x.shape[2] + pad_dim1,
                        x.shape[3] + pad_dim2,
                        x.shape[4] + pad_dim3)
        output = T.zeros(output_shape)
        indices = (slice(None), slice(None),
                   slice(pad_dim1 // 2, x.shape[2] + pad_dim1 // 2),
                   slice(pad_dim2 // 2, x.shape[3] + pad_dim2 // 2),
                   slice(pad_dim3 // 2, x.shape[4] + pad_dim3 // 2))
        x = T.set_subtensor(output[indices], x)
        border_mode = 'valid'

    border_mode_3d = (border_mode, border_mode, border_mode)
    conv_out = conv3d2d.conv3d(signals=x.dimshuffle(0, 2, 1, 3, 4),
                               filters=kernel.dimshuffle(0, 2, 1, 3, 4),
                               border_mode=border_mode_3d)
    conv_out = conv_out.dimshuffle(0, 2, 1, 3, 4)

    # support strides by manually slicing the output
    if strides != (1, 1, 1):
        conv_out = conv_out[:, :, ::strides[0], ::strides[1], ::strides[2]]

    if dim_ordering == 'tf':
        conv_out = conv_out.dimshuffle((0, 2, 3, 4, 1))

    return conv_out 
開發者ID:ambrite,項目名稱:keras-customized,代碼行數:63,代碼來源:theano_backend.py

示例8: conv3d

# 需要導入模塊: from theano.tensor.nnet import conv3d2d [as 別名]
# 或者: from theano.tensor.nnet.conv3d2d import conv3d [as 別名]
def conv3d(x, kernel, strides=(1, 1, 1),
           border_mode='valid', dim_ordering='th',
           volume_shape=None, filter_shape=None):
    '''
    Run on cuDNN if available.
    border_mode: string, "same" or "valid".
    '''
    if dim_ordering not in {'th', 'tf'}:
        raise Exception('Unknown dim_ordering ' + str(dim_ordering))

    if border_mode not in {'same', 'valid'}:
        raise Exception('Invalid border mode: ' + str(border_mode))

    if dim_ordering == 'tf':
        # TF uses the last dimension as channel dimension,
        # instead of the 2nd one.
        # TH input shape: (samples, input_depth, conv_dim1, conv_dim2, conv_dim3)
        # TF input shape: (samples, conv_dim1, conv_dim2, conv_dim3, input_depth)
        # TH kernel shape: (out_depth, input_depth, kernel_dim1, kernel_dim2, kernel_dim3)
        # TF kernel shape: (kernel_dim1, kernel_dim2, kernel_dim3, input_depth, out_depth)
        x = x.dimshuffle((0, 4, 1, 2, 3))
        kernel = kernel.dimshuffle((4, 3, 0, 1, 2))
        if volume_shape:
            volume_shape = (volume_shape[0], volume_shape[4],
                            volume_shape[1], volume_shape[2], volume_shape[3])
        if filter_shape:
            filter_shape = (filter_shape[4], filter_shape[3],
                            filter_shape[0], filter_shape[1], filter_shape[2])

    if border_mode == 'same':
        assert(strides == (1, 1, 1))
        pad_dim1 = (kernel.shape[2] - 1)
        pad_dim2 = (kernel.shape[3] - 1)
        pad_dim3 = (kernel.shape[4] - 1)
        output_shape = (x.shape[0], x.shape[1],
                        x.shape[2] + pad_dim1,
                        x.shape[3] + pad_dim2,
                        x.shape[4] + pad_dim3)
        output = T.zeros(output_shape)
        indices = (slice(None), slice(None),
                   slice(pad_dim1 // 2, x.shape[2] + pad_dim1 // 2),
                   slice(pad_dim2 // 2, x.shape[3] + pad_dim2 // 2),
                   slice(pad_dim3 // 2, x.shape[4] + pad_dim3 // 2))
        x = T.set_subtensor(output[indices], x)
        border_mode = 'valid'

    border_mode_3d = (border_mode, border_mode, border_mode)
    conv_out = conv3d2d.conv3d(signals=x.dimshuffle(0, 2, 1, 3, 4),
                               filters=kernel.dimshuffle(0, 2, 1, 3, 4),
                               border_mode=border_mode_3d)
    conv_out = conv_out.dimshuffle(0, 2, 1, 3, 4)

    # support strides by manually slicing the output
    if strides != (1, 1, 1):
        conv_out = conv_out[:, :, ::strides[0], ::strides[1], ::strides[2]]

    if dim_ordering == 'tf':
        conv_out = conv_out.dimshuffle((0, 2, 3, 4, 1))

    return conv_out 
開發者ID:mathDR,項目名稱:reading-text-in-the-wild,代碼行數:62,代碼來源:theano_backend.py


注:本文中的theano.tensor.nnet.conv3d2d.conv3d方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。