当前位置: 首页>>代码示例>>Python>>正文


Python utils.collect_named_outputs方法代码示例

本文整理汇总了Python中tensorflow.contrib.layers.python.layers.utils.collect_named_outputs方法的典型用法代码示例。如果您正苦于以下问题:Python utils.collect_named_outputs方法的具体用法?Python utils.collect_named_outputs怎么用?Python utils.collect_named_outputs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.contrib.layers.python.layers.utils的用法示例。


在下文中一共展示了utils.collect_named_outputs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: det_lesion_resnet

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def det_lesion_resnet(inputs, is_training_option=False, scope='det_lesion'):
    """Defines the network
    Args:
    inputs: Tensorflow placeholder that contains the input image
    scope: Scope name for the network
    Returns:
    net: Output Tensor of the network
    end_points: Dictionary with all Tensors of the network
    """

    with tf.variable_scope(scope, 'det_lesion', [inputs]) as sc:
        end_points_collection = sc.name + '_end_points'
        with slim.arg_scope(resnet_v1.resnet_arg_scope()):

            net, end_points = resnet_v1.resnet_v1_50(inputs, is_training=is_training_option)
            net = slim.flatten(net, scope='flatten5')
            net = slim.fully_connected(net, 1, activation_fn=tf.nn.sigmoid,
                                       weights_initializer=initializers.xavier_initializer(), scope='output')
            utils.collect_named_outputs(end_points_collection, 'det_lesion/output', net)

    end_points = slim.utils.convert_collection_to_dict(end_points_collection)
    return net, end_points 
开发者ID:imatge-upc,项目名称:liverseg-2017-nipsws,代码行数:24,代码来源:det_lesion.py

示例2: ops_to_outputs

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def ops_to_outputs(func):
    def wrapper(*args, **kwargs):
        x = func(*args, **kwargs)
        x = collect_named_outputs(__outputs__, tf.get_variable_scope().name, x)
        return x
    return wrapper 
开发者ID:taehoonlee,项目名称:tensornets,代码行数:8,代码来源:utils.py

示例3: dropout

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def dropout(inputs,
            keep_prob=0.5,
            noise_shape=None,
            is_training=True,
            outputs_collections=None,
            scope=None):
  """Returns a dropout op applied to the input.

  With probability `keep_prob`, outputs the input element scaled up by
  `1 / keep_prob`, otherwise outputs `0`.  The scaling is so that the expected
  sum is unchanged.

  Args:
    inputs: The tensor to pass to the nn.dropout op.
    keep_prob: A scalar `Tensor` with the same type as x. The probability
      that each element is kept.
    noise_shape: A 1-D `Tensor` of type `int32`, representing the
      shape for randomly generated keep/drop flags.
    is_training: A bool `Tensor` indicating whether or not the model
      is in training mode. If so, dropout is applied and values scaled.
      Otherwise, inputs is returned.
    outputs_collections: Collection to add the outputs.
    scope: Optional scope for name_scope.

  Returns:
    A tensor representing the output of the operation.
  """
  with variable_scope.variable_scope(
      scope, 'Dropout', [inputs], custom_getter=_model_variable_getter) as sc:
    inputs = ops.convert_to_tensor(inputs)
    layer = core_layers.Dropout(rate=1 - keep_prob,
                                noise_shape=noise_shape,
                                name=sc.name,
                                _scope=sc)
    outputs = layer.apply(inputs, training=is_training)
    return utils.collect_named_outputs(
        outputs_collections, sc.original_name_scope, outputs) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:39,代码来源:layers.py

示例4: one_hot_encoding

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def one_hot_encoding(labels,
                     num_classes,
                     on_value=1.0,
                     off_value=0.0,
                     outputs_collections=None,
                     scope=None):
  """Transform numeric labels into onehot_labels using `tf.one_hot`.

  Args:
    labels: [batch_size] target labels.
    num_classes: Total number of classes.
    on_value: A scalar defining the on-value.
    off_value: A scalar defining the off-value.
    outputs_collections: Collection to add the outputs.
    scope: Optional scope for name_scope.

  Returns:
    One-hot encoding of the labels.
  """
  with ops.name_scope(scope, 'OneHotEncoding', [labels, num_classes]) as sc:
    labels = ops.convert_to_tensor(labels)
    if labels.dtype == dtypes.int32:
      labels = standard_ops.to_int64(labels)
    outputs = standard_ops.one_hot(labels,
                                   num_classes,
                                   on_value=on_value,
                                   off_value=off_value)
    return utils.collect_named_outputs(outputs_collections, sc, outputs) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:30,代码来源:layers.py

示例5: dropout

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def dropout(inputs,
            keep_prob=0.5,
            noise_shape=None,
            is_training=True,
            outputs_collections=None,
            scope=None):
  """Returns a dropout op applied to the input.

  With probability `keep_prob`, outputs the input element scaled up by
  `1 / keep_prob`, otherwise outputs `0`.  The scaling is so that the expected
  sum is unchanged.

  Args:
    inputs: the tensor to pass to the nn.dropout op.
    keep_prob: A scalar `Tensor` with the same type as x. The probability
      that each element is kept.
    noise_shape: A 1-D `Tensor` of type `int32`, representing the
      shape for randomly generated keep/drop flags.
    is_training: A bool `Tensor` indicating whether or not the model
      is in training mode. If so, dropout is applied and values scaled.
      Otherwise, inputs is returned.
    outputs_collections: collection to add the outputs.
    scope: Optional scope for name_scope.

  Returns:
    a tensor representing the output of the operation.
  """
  with variable_scope.variable_scope(
      scope, 'Dropout', [inputs], custom_getter=_model_variable_getter) as sc:
    inputs = ops.convert_to_tensor(inputs)
    layer = core_layers.Dropout(rate=1 - keep_prob,
                                noise_shape=noise_shape,
                                name=sc.name,
                                _scope=sc)
    outputs = layer.apply(inputs, training=is_training)
    return utils.collect_named_outputs(
        outputs_collections, sc.original_name_scope, outputs) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:39,代码来源:layers.py

示例6: flatten

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def flatten(inputs,
            outputs_collections=None,
            scope=None):
  """Flattens the input while maintaining the batch_size.

    Assumes that the first dimension represents the batch.

  Args:
    inputs: a tensor of size [batch_size, ...].
    outputs_collections: collection to add the outputs.
    scope: Optional scope for name_scope.

  Returns:
    a flattened tensor with shape [batch_size, k].
  Raises:
    ValueError: if inputs.dense_shape is wrong.
  """
  with ops.name_scope(scope, 'Flatten', [inputs]) as sc:
    inputs = ops.convert_to_tensor(inputs)
    inputs_shape = inputs.get_shape()
    inputs_rank = inputs_shape.ndims
    if (inputs_rank is None) or (inputs_rank < 2):
      raise ValueError('Inputs must have a least 2 dimensions.')
    dims = inputs_shape[1:]
    if not dims.is_fully_defined():
      raise ValueError('Inputs 2nd dimension must be defined.')
    k = dims.num_elements()
    outputs = array_ops.reshape(inputs, [-1, k])
    return utils.collect_named_outputs(outputs_collections, sc, outputs) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:31,代码来源:layers.py

示例7: one_hot_encoding

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def one_hot_encoding(labels,
                     num_classes,
                     on_value=1.0,
                     off_value=0.0,
                     outputs_collections=None,
                     scope=None):
  """Transform numeric labels into onehot_labels using `tf.one_hot`.

  Args:
    labels: [batch_size] target labels.
    num_classes: total number of classes.
    on_value: A scalar defining the on-value.
    off_value: A scalar defining the off-value.
    outputs_collections: collection to add the outputs.
    scope: Optional scope for name_scope.

  Returns:
    one hot encoding of the labels.
  """
  with ops.name_scope(scope, 'OneHotEncoding', [labels, num_classes]) as sc:
    labels = ops.convert_to_tensor(labels)
    if labels.dtype == dtypes.int32:
      labels = standard_ops.to_int64(labels)
    outputs = standard_ops.one_hot(labels,
                                   num_classes,
                                   on_value=on_value,
                                   off_value=off_value)
    return utils.collect_named_outputs(outputs_collections, sc, outputs) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:30,代码来源:layers.py

示例8: mlp

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def mlp(feature, hparams, name="mlp"):
  """Multi layer perceptron with dropout and relu activation."""
  with tf.variable_scope(name, "mlp", values=[feature]):
    num_mlp_layers = hparams.num_mlp_layers
    mlp_size = hparams.mlp_size
    for _ in range(num_mlp_layers):
      feature = common_layers.dense(feature, mlp_size, activation=None)
      utils.collect_named_outputs("norms", "mlp_feature",
                                  tf.norm(feature, axis=-1))
      feature = common_layers.layer_norm(feature)
      feature = tf.nn.relu(feature)
      feature = tf.nn.dropout(feature, keep_prob=1.-hparams.dropout)
    return feature 
开发者ID:tensorflow,项目名称:tensor2tensor,代码行数:15,代码来源:vqa_self_attention.py

示例9: preact_conv2d

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def preact_conv2d(
        inputs,
        num_outputs,
        kernel_size,
        stride=1,
        padding='SAME',
        activation_fn=nn.relu,
        normalizer_fn=None,
        normalizer_params=None,
        weights_initializer=initializers.xavier_initializer(),
        weights_regularizer=None,
        reuse=None,
        variables_collections=None,
        outputs_collections=None,
        trainable=True,
        scope=None):
    """Adds a 2D convolution preceded by batch normalization and activation.
    """
    with variable_scope.variable_scope(scope, 'Conv', values=[inputs], reuse=reuse) as sc:
        inputs = ops.convert_to_tensor(inputs)
        dtype = inputs.dtype.base_dtype
        if normalizer_fn:
            normalizer_params = normalizer_params or {}
            inputs = normalizer_fn(inputs, activation_fn=activation_fn, **normalizer_params)
        kernel_h, kernel_w = utils.two_element_tuple(kernel_size)
        stride_h, stride_w = utils.two_element_tuple(stride)
        num_filters_in = utils.last_dimension(inputs.get_shape(), min_rank=4)
        weights_shape = [kernel_h, kernel_w, num_filters_in, num_outputs]
        weights_collections = utils.get_variable_collections(variables_collections, 'weights')
        weights = variables.model_variable('weights',
                                           shape=weights_shape,
                                           dtype=dtype,
                                           initializer=weights_initializer,
                                           regularizer=weights_regularizer,
                                           collections=weights_collections,
                                           trainable=trainable)
        outputs = nn.conv2d(inputs, weights, [1, stride_h, stride_w, 1], padding=padding)
        return utils.collect_named_outputs(outputs_collections, sc.name, outputs) 
开发者ID:rwightman,项目名称:tensorflow-litterbox,代码行数:40,代码来源:preact_conv.py

示例10: maxout

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def maxout(inputs,
           num_units,
           axis=None,
           outputs_collections=None,
           scope=None):
  """Adds a maxout op which is a max pooling performed in filter/channel
  dimension. This can also be used after fully-connected layers to reduce
  number of features.
  Args:
    inputs: A Tensor on which maxout will be performed
    num_units: Specifies how many features will remain after max pooling at the
      channel dimension. This must be multiple of number of channels.
    axis: The dimension where max pooling will be performed. Default is the
      last dimension.
    outputs_collections: The collections to which the outputs are added.
    scope: Optional scope for name_scope.
  Returns:
    A `Tensor` representing the results of the pooling operation.
  Raises:
    ValueError: if num_units is not multiple of number of features.
    """
  with ops.name_scope(scope, 'MaxOut', [inputs]) as sc:
    inputs = ops.convert_to_tensor(inputs)
    shape = inputs.get_shape().as_list()
    if axis is None:
      # Assume that channel is the last dimension
      axis = -1
    num_channels = shape[axis]
    if num_channels % num_units:
      raise ValueError('number of features({}) is not '
                       'a multiple of num_units({})'
              .format(num_channels, num_units))
    shape[axis] = -1
    shape += [num_channels // num_units]
    outputs = math_ops.reduce_max(gen_array_ops.reshape(inputs, shape), -1,
                                  keep_dims=False)
    return utils.collect_named_outputs(outputs_collections, sc, outputs) 
开发者ID:marshmelloX,项目名称:dynamic-coattention-network,代码行数:39,代码来源:ops.py

示例11: test_collect

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def test_collect(self):
    t1 = tf.constant(1.0, name='t1')
    t2 = tf.constant(2.0, name='t2')
    utils.collect_named_outputs('end_points', 'a1', t1)
    utils.collect_named_outputs('end_points', 'a2', t2)
    self.assertEqual(tf.get_collection('end_points'), [t1, t2]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:8,代码来源:utils_test.py

示例12: test_aliases

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def test_aliases(self):
    t1 = tf.constant(1.0, name='t1')
    t2 = tf.constant(2.0, name='t2')
    utils.collect_named_outputs('end_points', 'a1', t1)
    utils.collect_named_outputs('end_points', 'a2', t2)
    self.assertEqual(t1.alias, 'a1')
    self.assertEqual(t2.alias, 'a2') 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:9,代码来源:utils_test.py

示例13: test_gather_aliases

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def test_gather_aliases(self):
    t1 = tf.constant(1.0, name='t1')
    t2 = tf.constant(2.0, name='t2')
    t3 = tf.constant(2.0, name='t3')
    utils.collect_named_outputs('end_points', 'a1', t1)
    utils.collect_named_outputs('end_points', 'a2', t2)
    tf.add_to_collection('end_points', t3)
    aliases = utils.gather_tensors_alias(tf.get_collection('end_points'))
    self.assertListEqual(aliases, ['a1', 'a2', 't3']) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:11,代码来源:utils_test.py

示例14: dropout

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def dropout(inputs,
            keep_prob=0.5,
            noise_shape=None,
            is_training=True,
            outputs_collections=None,
            scope=None):
  """Returns a dropout op applied to the input.

  With probability `keep_prob`, outputs the input element scaled up by
  `1 / keep_prob`, otherwise outputs `0`.  The scaling is so that the expected
  sum is unchanged.

  Args:
    inputs: the tensor to pass to the nn.dropout op.
    keep_prob: A scalar `Tensor` with the same type as x. The probability
      that each element is kept.
    noise_shape: A 1-D `Tensor` of type `int32`, representing the
      shape for randomly generated keep/drop flags.
    is_training: A bool `Tensor` indicating whether or not the model
      is in training mode. If so, dropout is applied and values scaled.
      Otherwise, inputs is returned.
    outputs_collections: collection to add the outputs.
    scope: Optional scope for name_scope.

  Returns:
    a tensor representing the output of the operation.
  """
  with ops.name_scope(scope, 'Dropout', [inputs]) as sc:
    inputs = ops.convert_to_tensor(inputs)
    dropout_fn = lambda: nn.dropout(inputs, keep_prob, noise_shape)
    id_fn = lambda: array_ops.identity(inputs)
    outputs = utils.smart_cond(is_training, dropout_fn, id_fn)
    return utils.collect_named_outputs(outputs_collections, sc, outputs) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:35,代码来源:layers.py

示例15: _inner_flatten

# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import collect_named_outputs [as 别名]
def _inner_flatten(inputs, new_rank, output_collections=None, scope=None):
  """Flattens inner dimensions of `inputs`, returns a Tensor with `new_rank`.

  For example:
  '''
      x = tf.random_uniform(shape=[1, 2, 3, 4, 5, 6])
      y = _inner_flatten(x, 4)
      assert y.get_shape().as_list() == [1, 2, 3, (4 * 5 * 6)]
  '''
  This layer will fail at run time if `new_rank` is greater than the current
  rank of `inputs`.

  Args:
    inputs: a `Tensor` or `SparseTensor`.
    new_rank: the desired rank of the returned `Tensor` or `SparseTensor`.
    output_collections: collection to which the outputs will be added.
    scope: optional scope for `name_scope`.
  Returns:
    A `Tensor` or `SparseTensor` conataining the same values as `inputs`, but
    with innermost dimensions flattened to obtain rank `new_rank`.

  Raises:
    TypeError: `inputs` is not a `Tensor` or `SparseTensor`.
  """
  with ops.name_scope(scope, 'InnerFlatten', [inputs, new_rank]) as sc:
    if isinstance(inputs, sparse_tensor.SparseTensor):
      flattened = _sparse_inner_flatten(inputs, new_rank)
    else:
      inputs = ops.convert_to_tensor(inputs)
      flattened = _dense_inner_flatten(inputs, new_rank)
  return utils.collect_named_outputs(output_collections, sc, flattened) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:33,代码来源:layers.py


注:本文中的tensorflow.contrib.layers.python.layers.utils.collect_named_outputs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。