• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tensor_shape.scalar函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tensorflow.python.framework.tensor_shape.scalar函数的典型用法代码示例。如果您正苦于以下问题:Python scalar函数的具体用法?Python scalar怎么用?Python scalar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: testReadUpToFromRandomShuffleQueue

 def testReadUpToFromRandomShuffleQueue(self):
   shared_queue = data_flow_ops.RandomShuffleQueue(
       capacity=55,
       min_after_dequeue=28,
       dtypes=[dtypes_lib.string, dtypes_lib.string],
       shapes=[tensor_shape.scalar(), tensor_shape.scalar()])
   self._verify_read_up_to_out(shared_queue)
开发者ID:1000sprites,项目名称:tensorflow,代码行数:7,代码来源:parallel_reader_test.py


示例2: _ShardedFilenameShape

def _ShardedFilenameShape(op):
    """Shape function for ShardedFilename op."""
    # Validate input shapes.
    unused_basename_shape = op.inputs[0].get_shape().merge_with(tensor_shape.scalar())
    unused_shard_shape = op.inputs[1].get_shape().merge_with(tensor_shape.scalar())
    unused_num_shards_shape = op.inputs[2].get_shape().merge_with(tensor_shape.scalar())
    return [tensor_shape.scalar()]
开发者ID:RChandrasekar,项目名称:tensorflow,代码行数:7,代码来源:io_ops.py


示例3: _TensorArrayReadShape

def _TensorArrayReadShape(op):
    # handle, index, flow_in
    op.inputs[0].get_shape().merge_with(tensor_shape.vector(2))
    op.inputs[1].get_shape().merge_with(tensor_shape.scalar())
    op.inputs[2].get_shape().merge_with(tensor_shape.scalar())
    # value
    return [tensor_shape.unknown_shape()]
开发者ID:MISingularity,项目名称:tensorflow,代码行数:7,代码来源:tensor_array_ops.py


示例4: testDeserialize

  def testDeserialize(self):
    with self.test_session() as sess:
      accumulator = stats_accumulator_ops.StatsAccumulator(
          stamp_token=0,
          gradient_shape=tensor_shape.scalar(),
          hessian_shape=tensor_shape.scalar())
      with ops.control_dependencies([accumulator._create_op]):
        # These will be deleted due to deserialize call.
        op1 = accumulator.add(
            stamp_token=0,
            partition_ids=[1, 2],
            feature_ids=[2, 3],
            gradients=[0.1, 0.3],
            hessians=[0.2, 0.4])

      with ops.control_dependencies([op1]):
        deserialize = (accumulator.deserialize(
            stamp_token=2,
            num_updates=3,
            partition_ids=[3, 4],
            feature_ids=[5, 6],
            gradients=[0.4, 0.5],
            hessians=[0.6, 0.7]))
      with ops.control_dependencies([deserialize]):
        num_updates, partition, feature, grads, hessians = accumulator.flush(
            stamp_token=2, next_stamp_token=3)
        num_updates, partition, feature, grads, hessians = sess.run(
            [num_updates, partition, feature, grads, hessians])

      result = _AccumulatorResultToDict(partition, feature, grads,
                                        hessians)
      self.assertEqual(num_updates, 3)
      self.assertEqual(len(result), 2)
      self.assertAllClose(result[(3, 5)], [0.4, 0.6])
      self.assertAllClose(result[(4, 6)], [0.5, 0.7])
开发者ID:1000sprites,项目名称:tensorflow,代码行数:35,代码来源:stats_accumulator_ops_test.py


示例5: _TensorArrayWriteShape

def _TensorArrayWriteShape(op):
    # handle, index, value, flow_in
    op.inputs[0].get_shape().merge_with(tensor_shape.vector(2))
    op.inputs[1].get_shape().merge_with(tensor_shape.scalar())
    op.inputs[3].get_shape().merge_with(tensor_shape.scalar())
    # flow_out
    return [tensor_shape.scalar()]
开发者ID:MISingularity,项目名称:tensorflow,代码行数:7,代码来源:tensor_array_ops.py


示例6: _ReaderRestoreStateShape

def _ReaderRestoreStateShape(op):
  """Shape function for the ReaderBase.Restore op."""
  unused_handle_shape = op.inputs[0].get_shape().merge_with(
      tensor_shape.scalar())
  unused_state_shape = op.inputs[1].get_shape().merge_with(
      tensor_shape.scalar())
  return []
开发者ID:ray2020,项目名称:tensorflow,代码行数:7,代码来源:io_ops.py


示例7: testMultidimensionalAcculumator

  def testMultidimensionalAcculumator(self):
    with self.test_session() as sess:
      accumulator = stats_accumulator_ops.StatsAccumulator(
          stamp_token=0,
          gradient_shape=tensor_shape.scalar(),
          hessian_shape=tensor_shape.scalar())
      with ops.control_dependencies([accumulator._create_op]):
        op1 = accumulator.add(
            stamp_token=0,
            partition_ids=[1, 2, 1],
            feature_ids=[[2, 2], [3, 0], [2, 2]],
            gradients=[0.1, 0.3, 0.8],
            hessians=[0.2, 0.4, -9])
        op2 = accumulator.add(0, [2, 1], [[3, 1], [2, 2]], [0.1, 1], [0.2, -1])

      with ops.control_dependencies([op1, op2]):
        num_updates, partition, bucket_ids, grads, hessians = accumulator.flush(
            stamp_token=0, next_stamp_token=1)
        num_updates, partition, bucket_ids, grads, hessians = sess.run(
            [num_updates, partition, bucket_ids, grads, hessians])

      result = _AccumulatorResultToDict(partition, bucket_ids, grads, hessians)
      self.assertEqual(num_updates, 2)
      self.assertEqual(len(result), 3)
      # Key is partion, bucket, dimension.
      self.assertAllClose(result[(1, 2, 2)], [1.9, -9.8])
      self.assertAllClose(result[(2, 3, 0)], [0.3, 0.4])
      self.assertAllClose(result[(2, 3, 1)], [0.1, 0.2])
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:28,代码来源:stats_accumulator_ops_test.py


示例8: constant_value_as_shape

def constant_value_as_shape(tensor):  # pylint: disable=invalid-name
  """A version of `constant_value()` that returns a `TensorShape`.

  This version should be used when a constant tensor value is
  interpreted as a (possibly partial) shape, e.g. in the shape
  function for `tf.reshape()`. By explicitly requesting a
  `TensorShape` as the return value, it is possible to represent
  unknown dimensions; by contrast, `constant_value()` is
  all-or-nothing.

  Args:
    tensor: The rank-1 Tensor to be evaluated.

  Returns:
    A `TensorShape` based on the constant value of the given `tensor`.
  """
  shape = tensor.get_shape().with_rank(1)
  if tensor.get_shape() == [0]:
    return tensor_shape.scalar()
  elif tensor.op.type == "Shape":
    return tensor.op.inputs[0].get_shape()
  elif tensor.op.type == "Pack":
    ret = tensor_shape.scalar()  # Empty list.
    for pack_input in tensor.op.inputs:
      # `pack_input` must be a scalar. Attempt to evaluate it, and append it
      # to `ret`.
      pack_input_val = constant_value(pack_input)
      if pack_input_val is None or pack_input_val < 0:
        new_dim = tensor_shape.Dimension(None)
      else:
        new_dim = tensor_shape.Dimension(pack_input_val)
      ret = ret.concatenate([new_dim])
    return ret
  elif tensor.op.type == "Concat":
    # We assume that `tensor.op.inputs[0]` evaluates to 0, as this is
    # the only legal value when concatenating vectors, and it will
    # have been checked by a previous shape function.
    ret = tensor_shape.scalar()  # Empty list.
    for concat_input in tensor.op.inputs[1:]:
      # `concat_input` must be a vector. Attempt to evaluate it as a shape,
      # and concatenate it with `ret`.
      ret = ret.concatenate(constant_value_as_shape(concat_input))
    return ret
  elif tensor.op.type == "ConcatV2":
    # We assume that `tensor.op.inputs[-1]` evaluates to 0, as this is
    # the only legal value when concatenating vectors, and it will
    # have been checked by a previous shape function.
    ret = tensor_shape.scalar()  # Empty list.
    for concat_input in tensor.op.inputs[:-1]:
      # `concat_input` must be a vector. Attempt to evaluate it as a shape,
      # and concatenate it with `ret`.
      ret = ret.concatenate(constant_value_as_shape(concat_input))
    return ret
  else:
    ret = tensor_shape.unknown_shape(shape[0].value)
    value = constant_value(tensor)
    if value is not None:
      ret = ret.merge_with(tensor_shape.TensorShape(
          [d if d != -1 else None for d in value]))
    return ret
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:60,代码来源:tensor_util.py


示例9: dropout_selu_impl

    def dropout_selu_impl(x, rate, alpha, noise_shape, seed, name):
        keep_prob = 1.0 - rate
        x = ops.convert_to_tensor(x, name="x")
        if isinstance(keep_prob, numbers.Real) and not 0. < keep_prob <= 1.:
            raise ValueError("keep_prob must be a scalar tensor or a float in the "
                                             "range (0, 1], got %g" % keep_prob)
        keep_prob = ops.convert_to_tensor(keep_prob, dtype=x.dtype, name="keep_prob")
        keep_prob.get_shape().assert_is_compatible_with(tensor_shape.scalar())

        alpha = ops.convert_to_tensor(alpha, dtype=x.dtype, name="alpha")
        keep_prob.get_shape().assert_is_compatible_with(tensor_shape.scalar())

        if tensor_util.constant_value(keep_prob) == 1:
            return x

        noise_shape = noise_shape if noise_shape is not None else array_ops.shape(x)
        random_tensor = keep_prob
        random_tensor += random_ops.random_uniform(noise_shape, seed=seed, dtype=x.dtype)
        binary_tensor = math_ops.floor(random_tensor)
        ret = x * binary_tensor + alpha * (1-binary_tensor)

        a = tf.sqrt(fixedPointVar / (keep_prob *((1-keep_prob) * tf.pow(alpha-fixedPointMean,2) + fixedPointVar)))

        b = fixedPointMean - a * (keep_prob * fixedPointMean + (1 - keep_prob) * alpha)
        ret = a * ret + b
        ret.set_shape(x.get_shape())
        return ret
开发者ID:waxz,项目名称:ppo_torcs,代码行数:27,代码来源:selu.py


示例10: testDropStaleUpdate

  def testDropStaleUpdate(self):
    with self.test_session() as sess:
      accumulator = stats_accumulator_ops.StatsAccumulator(
          stamp_token=0,
          gradient_shape=tensor_shape.scalar(),
          hessian_shape=tensor_shape.scalar())
      with ops.control_dependencies([accumulator._create_op]):
        op1 = accumulator.add(
            stamp_token=0,
            partition_ids=[1, 2],
            feature_ids=[[2, 0], [3, 0]],
            gradients=[0.1, 0.3],
            hessians=[0.2, 0.4])
        op2 = accumulator.add(
            stamp_token=-1,
            partition_ids=[1],
            feature_ids=[[2, 0]],
            gradients=[0.1],
            hessians=[0.2])

      with ops.control_dependencies([op1, op2]):
        num_updates, partition, feature, grads, hessians = accumulator.flush(
            stamp_token=0, next_stamp_token=1)
        num_updates, partition, feature, grads, hessians = sess.run(
            [num_updates, partition, feature, grads, hessians])

      result = _AccumulatorResultToDict(partition, feature, grads, hessians)
      self.assertEqual(num_updates, 1)
      self.assertEqual(len(result), 2)
      self.assertAllClose(result[(1, 2, 0)], [0.1, 0.2])
      self.assertAllClose(result[(2, 3, 0)], [0.3, 0.4])
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:31,代码来源:stats_accumulator_ops_test.py


示例11: testSkipEagerBuildElementShape

 def testSkipEagerBuildElementShape(self):
   fn = list_ops._build_element_shape
   # Unknown shape -> -1.
   self.assertEqual(fn(None), -1)
   self.assertEqual(fn(tensor_shape.unknown_shape()), -1)
   # Scalar shape -> [] with type int32.
   self.assertEqual(fn([]).dtype, dtypes.int32)
   self.assertEqual(fn(tensor_shape.scalar()).dtype, dtypes.int32)
   self.assertAllEqual(self.evaluate(fn([])), np.array([], np.int32))
   self.assertAllEqual(
       self.evaluate(fn(tensor_shape.scalar())), np.array([], np.int32))
   # Tensor -> Tensor
   shape = constant_op.constant(1)
   self.assertIs(fn(shape), shape)
   # Shape with unknown dims -> shape list with -1's.
   shape = [None, 5]
   self.assertAllEqual(fn(shape), [-1, 5])
   self.assertAllEqual(fn(tensor_shape.TensorShape(shape)), [-1, 5])
   # Shape with unknown dims and tensor dims -> shape list with -1's and tensor
   # dims.
   t = array_ops.placeholder(dtypes.int32)
   shape = [None, 5, t]
   result = fn(shape)
   self.assertAllEqual(result[:2], [-1, 5])
   self.assertIs(result[2], t)
开发者ID:aeverall,项目名称:tensorflow,代码行数:25,代码来源:list_ops_test.py


示例12: _ReaderReadShape

def _ReaderReadShape(op):
  """Shape function for the ReaderBase.Read op."""
  unused_handle_shape = op.inputs[0].get_shape().merge_with(
      tensor_shape.scalar())
  unused_queue_shape = op.inputs[1].get_shape().merge_with(
      tensor_shape.scalar())
  return [tensor_shape.scalar(), tensor_shape.scalar()]
开发者ID:ray2020,项目名称:tensorflow,代码行数:7,代码来源:io_ops.py


示例13: _TensorArraySplitShape

def _TensorArraySplitShape(op):
    # handle, value, lengths, flow_in
    op.inputs[0].get_shape().merge_with(tensor_shape.vector(2))
    op.inputs[2].get_shape().merge_with(tensor_shape.vector(None))
    op.inputs[3].get_shape().merge_with(tensor_shape.scalar())
    # flow_out
    return [tensor_shape.scalar()]
开发者ID:MISingularity,项目名称:tensorflow,代码行数:7,代码来源:tensor_array_ops.py


示例14: _RestoreShape

def _RestoreShape(op):
  """Shape function for Restore op."""
  # Validate input shapes.
  unused_file_pattern = op.inputs[0].get_shape().merge_with(
      tensor_shape.scalar())
  unused_tensor_name = op.inputs[1].get_shape().merge_with(
      tensor_shape.scalar())
  return [tensor_shape.unknown_shape()]
开发者ID:ray2020,项目名称:tensorflow,代码行数:8,代码来源:io_ops.py


示例15: _RestoreSliceShape

def _RestoreSliceShape(op):
    """Shape function for RestoreSlice op."""
    # Validate input shapes.
    unused_file_pattern = op.inputs[0].get_shape().merge_with(tensor_shape.scalar())
    unused_tensor_name = op.inputs[1].get_shape().merge_with(tensor_shape.scalar())
    unused_shape_and_slice_shape = op.inputs[2].get_shape().merge_with(tensor_shape.scalar())
    # TODO(mrry): Attempt to parse the shape_and_slice value and use it
    # to form the shape of the output.
    return [tensor_shape.unknown_shape()]
开发者ID:RChandrasekar,项目名称:tensorflow,代码行数:9,代码来源:io_ops.py


示例16: _make_window_size_func

 def _make_window_size_func(self, window_size_func):
   """Make wrapping Defun for window_size_func."""
   def window_size_func_wrapper(key):
     return ops.convert_to_tensor(window_size_func(key), dtype=dtypes.int64)
   wrapped_func = dataset_ops.StructuredFunctionWrapper(
       window_size_func_wrapper, "tf.contrib.data.group_by_window()",
       input_classes=ops.Tensor, input_shapes=tensor_shape.scalar(),
       input_types=dtypes.int64)
   if not (
       wrapped_func.output_types == dtypes.int64 and
       wrapped_func.output_shapes.is_compatible_with(tensor_shape.scalar())):
     raise ValueError(
         "`window_size_func` must return a single tf.int64 scalar tensor.")
   self._window_size_func = wrapped_func.function
开发者ID:BhaskarNallani,项目名称:tensorflow,代码行数:14,代码来源:grouping.py


示例17: _InitializeLookupTableShape

def _InitializeLookupTableShape(op):
  """Shape function for data_flow_ops._initialize_table."""
  unused_table_shape = op.inputs[0].get_shape().merge_with(
      tensor_shape.scalar())
  keys_shape = op.inputs[1].get_shape().with_rank(1)
  unused_values_shape = op.inputs[2].get_shape().merge_with(keys_shape)
  return []
开发者ID:DapengLan,项目名称:tensorflow,代码行数:7,代码来源:data_flow_ops.py


示例18: testHelpers

 def testHelpers(self):
   tensor_shape.TensorShape([]).assert_is_compatible_with(
       tensor_shape.scalar())
   tensor_shape.TensorShape([37]).assert_is_compatible_with(
       tensor_shape.vector(37))
   tensor_shape.TensorShape(
       [94, 43]).assert_is_compatible_with(tensor_shape.matrix(94, 43))
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:7,代码来源:tensor_shape_test.py


示例19: testGradSerialTwoLoops

  def testGradSerialTwoLoops(self):
    with self.test_session():
      num_steps = 100
      acc = tf.TensorArray(dtype=tf.float32, size=num_steps,
                           clear_after_read=False,
                           element_shape=tensor_shape.scalar())
      i = tf.constant(0, name="i")
      x = tf.constant(2.0, name="x")

      c = lambda i, acc: i < 5
      def b(i, acc):
        x1 = tf.cond(tf.equal(i, 0),
                     lambda: x,
                     lambda: tf.mul(acc.read(i - 1), 2.0))
        return i + 1, acc.write(i, x1)
      i1, acc1 = tf.while_loop(c, b, [i, acc])

      z = tf.constant(0.0)
      def fn(i, acc):
        return i + 1, acc.write(i, z)
      _, acc2 = tf.while_loop(lambda i, acc: i < num_steps, fn, [i1, acc1])

      r = acc2.stack()
      grad = tf.gradients(r, [x])[0]
      self.assertAllClose(31.0, grad.eval())
开发者ID:BloodD,项目名称:tensorflow,代码行数:25,代码来源:tensor_array_ops_test.py


示例20: make_splits

  def make_splits(self, stamp_token, next_stamp_token, class_id):
    """Create the best split using the accumulated stats and flush the state."""
    if (self._gradient_shape == tensor_shape.scalar() and
        self._hessian_shape == tensor_shape.scalar()):
      handler = make_sparse_split_scalar
    else:
      handler = make_sparse_split_tensor

    are_splits_ready, partition_ids, gains, split_infos = (
        handler(self._quantile_accumulator.resource_handle,
                self._stats_accumulator.resource_handle, stamp_token,
                next_stamp_token, self._multiclass_strategy, class_id,
                self._feature_column_group_id, self._l1_regularization,
                self._l2_regularization, self._tree_complexity_regularization,
                self._min_node_weight, self._loss_uses_sum_reduction))
    return are_splits_ready, partition_ids, gains, split_infos
开发者ID:Albert-Z-Guo,项目名称:tensorflow,代码行数:16,代码来源:ordinal_split_handler.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tensor_shape.unknown_shape函数代码示例发布时间:2022-05-27
下一篇:
Python tensor_shape.matrix函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap