示例#1
0
文件: blocks.py 项目: w1y2l32009/CNTK
def Input(shape, dtype=default_override_or(np.float32), needs_gradient=True, is_sparse=False,
          dynamic_axes=Axis.default_input_variable_dynamic_axes(), name=''):
    '''
    Constructs an Input variable.
    '''
    dtype = get_default_override(Input, dtype=dtype)
    return input_variable(shape=shape, dtype=dtype, needs_gradient=needs_gradient, is_sparse=is_sparse,
                          dynamic_axes=dynamic_axes, name=name)
示例#2
0
def Input(shape, dtype=default_override_or(np.float32), needs_gradient=True, is_sparse=False,
          dynamic_axes=Axis.default_input_variable_dynamic_axes(), name=''):
    '''
    Input(shape, dtype=np.float32, needs_gradient=True, is_sparse=False, dynamic_axes=Axis.default_input_variable_dynamic_axes(), name='')

    Constructs an Input variable.
    Input variables are used when explicitly constructing a graph.
    In the context of the Layers library, however, the preferred method is to use the @\ :func:`~cntk.utils.Signature` pattern.
    This is a wrapper around :func:`~cntk.ops.input_variable`.

    Example:
     >>> # an input receptacle for explicit graph building
     >>> x = Input((2,3), is_sparse=True)
     >>> x.is_sparse
         True
     >>> x.shape
         (2, 3)
     >>> y = sigmoid(x)
     >>> y.shape
         (2, 3)

     >>> # but the preferred pattern is to use the @Function/@Signature pattern instead:
     >>> from cntk.ops.functions import Function
     >>> from cntk.layers.typing import *
     >>> @Function
     ... @Signature(x = Tensor[2,3])
     ... def y(x):
     ...     return sigmoid(x)
     >>> y.shape
         (2, 3)

     >>> # type specifications can also be directly passed to Input:
     >>> x = Input(**SparseTensor[2,3])
     >>> x.is_sparse
         True
     >>> x.shape
         (2, 3)
     >>> y = sigmoid(x)
     >>> y.shape
         (2, 3)

    Args:
        shape (`int` or `tuple` of `ints`): vector or tensor dimension of the output of this layer
        dtype (np.dtype, defaults to np.float32): data type
        needs_gradient (bool, defaults to `True`):
        is_sparse (bool, defaults to `False`):
        dynamic_axes (object, `Axis.default_input_variable_dynamic_axes`):
        name (str, defaults to ''): the name of the Function instance in the network
        
    Returns:
        an input Variable
    '''

    dtype = get_default_override(Input, dtype=dtype)
    return input(shape=shape, dtype=dtype, needs_gradient=needs_gradient, is_sparse=is_sparse,
                          dynamic_axes=dynamic_axes, name=name)
示例#3
0
def Input(shape, dtype=default_override_or(np.float32), needs_gradient=True, is_sparse=False,
          dynamic_axes=Axis.default_input_variable_dynamic_axes(), name=''):
    '''
    Input(shape, dtype=np.float32, needs_gradient=True, is_sparse=False, dynamic_axes=Axis.default_input_variable_dynamic_axes(), name='')

    Constructs an Input variable.

    Args:
        shape (`int` or `tuple` of `ints`): vector or tensor dimension of the output of this layer
        dtype (np.dtype, defaults to np.float32): data type
        needs_gradient (bool, defaults to `True`):
        is_sparse (bool, defaults to `False`):
        dynamic_axes (object, Axis.default_input_variable_dynamic_axes):
        name (str, defaults to ''): the name of the Function instance in the network
        
    '''

    dtype = get_default_override(Input, dtype=dtype)
    return input_variable(shape=shape, dtype=dtype, needs_gradient=needs_gradient, is_sparse=is_sparse,
                          dynamic_axes=dynamic_axes, name=name)