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


Python array_ops.placeholder函数代码示例

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


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

示例1: testUnknownShape

 def testUnknownShape(self):
   x = array_ops.placeholder(dtypes.float32)
   num_dimensions = array_ops.placeholder(dtypes.int32)
   ret = random_grad.add_leading_unit_dimensions(x, num_dimensions)
   with self.cached_session() as sess:
     ret_val = sess.run(ret, {x: np.ones([2, 2]), num_dimensions: 2})
   self.assertAllEqual(ret_val.shape, [1, 1, 2, 2])
开发者ID:AnishShah,项目名称:tensorflow,代码行数:7,代码来源:random_grad_test.py

示例2: _testReduceSum

  def _testReduceSum(self,
                     expected_result,
                     dtype,
                     test_inputs,
                     rtol=1e-3,
                     atol=1e-4):
    """Tests reduce sum on a list of input arrays.

    For each array in test_inputs, check that performing reduce sum on the array
    produces a value that is close to the expected result.

    Args:
      expected_result: the expected result.
      dtype: the data type of the reduce sum operation.
      test_inputs: a list of input arrays for the reduce sum operation.
      rtol: the relative error.
      atol: the absolute error.
    """

    for test_input in test_inputs:
      with self.test_session() as sess:
        with self.test_scope():
          a = array_ops.placeholder(dtype)
          index = array_ops.placeholder(dtypes.int32)
          out = math_ops.reduce_sum(a, index)
        result = sess.run(out, {
            a: np.array(test_input, dtype=dtype),
            index: [0]
        })
        # Compare the results using float32 type.
        self.assertAllClose(
            np.float32(result),
            np.float32(expected_result),
            rtol=rtol,
            atol=atol)
开发者ID:BhaskarNallani,项目名称:tensorflow,代码行数:35,代码来源:reduce_ops_test.py

示例3: testAutoPack

 def testAutoPack(self):
   with self.test_session():
     h = array_ops.placeholder(dtypes_lib.int32, shape=[])
     w = array_ops.placeholder(dtypes_lib.int32, shape=[])
     z = array_ops.ones([h, w])
     out = z.eval(feed_dict={h: 4, w: 16})
   self.assertAllEqual(out, np.array([[1] * 16] * 4))
开发者ID:piyushjaiswal98,项目名称:tensorflow,代码行数:7,代码来源:constant_op_test.py

示例4: testShapeFunctionEdgeCases

  def testShapeFunctionEdgeCases(self):
    # split_dim greater than rank of input.
    with self.assertRaises(ValueError):
      array_ops.split(value=[[0, 1], [2, 3]], num_or_size_splits=4, axis=2)

    # split dim less than -(rank of input)
    with self.assertRaises(ValueError):
      array_ops.split(value=[[0, 1], [2, 3]], num_or_size_splits=4, axis=-3)

    # num_split does not evenly divide the size in split_dim.
    with self.assertRaisesRegexp(ValueError, "should evenly divide"):
      array_ops.split(value=[0, 1, 2, 3], num_or_size_splits=3, axis=0)

    # Unknown split_dim.
    splits = array_ops.split(
        value=[[0, 1, 2, 3]],
        num_or_size_splits=4,
        axis=array_ops.placeholder(dtypes.int32))
    for s in splits:
      self.assertEqual([None, None], s.get_shape().as_list())

    # Unknown split_dim and input shape.
    splits = array_ops.split(
        value=array_ops.placeholder(dtypes.float32),
        num_or_size_splits=4,
        axis=array_ops.placeholder(dtypes.int32))
    for s in splits:
      self.assertEqual(None, s.get_shape().ndims)
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:28,代码来源:split_op_test.py

示例5: testCondNested

  def testCondNested(self):
    with context.graph_mode(), self.test_session():
      v = resource_variable_ops.ResourceVariable(1.0)
      variables.global_variables_initializer().run()
      p = array_ops.placeholder(dtype=dtypes.bool)
      q = array_ops.placeholder(dtype=dtypes.bool)
      with function.AutomaticControlDependencies() as c:

        def true_fn():
          v.assign(v + 1, name='true')
          return 1.0

        def false_fn():

          def inner_true_fn():
            v.assign(v * 2, name='false_true')
            return 2.0

          def inner_false_fn():
            v.assign(v * 3, name='false_false')
            return 3.0

          control_flow_ops.cond(q, inner_true_fn, inner_false_fn)
          return 1.0

        control_flow_ops.cond(p, true_fn, false_fn)
        with ops.name_scope('final'):
          val = v.read_value()
        val = c.mark_as_return(val)
      self.assertAllEqual(val.eval(feed_dict={p: False, q: False}), 3.0)
      self.assertAllEqual(val.eval(feed_dict={p: False, q: True}), 6.0)
      self.assertAllEqual(val.eval(feed_dict={p: True, q: True}), 7.0)
      self.assertAllEqual(val.eval(feed_dict={p: True, q: False}), 8.0)
开发者ID:StephenOman,项目名称:tensorflow,代码行数:33,代码来源:function_test.py

示例6: testSlideDatasetInvalid

  def testSlideDatasetInvalid(self, count, window_size, window_shift,
                              window_stride):
    count_t = array_ops.placeholder(dtypes.int64, shape=[])
    window_size_t = array_ops.placeholder(dtypes.int64, shape=[])
    window_shift_t = array_ops.placeholder(dtypes.int64, shape=[])
    window_stride_t = array_ops.placeholder(dtypes.int64, shape=[])

    iterator = (
        dataset_ops.Dataset.range(10).map(lambda x: x).repeat(count_t).apply(
            sliding.sliding_window_batch(
                window_size=window_size_t,
                window_shift=window_shift_t,
                window_stride=window_stride_t)).make_initializable_iterator())
    init_op = iterator.initializer

    with self.cached_session() as sess:
      with self.assertRaises(errors.InvalidArgumentError):
        sess.run(
            init_op,
            feed_dict={
                count_t: count,
                window_size_t: window_size,
                window_shift_t: window_shift,
                window_stride_t: window_stride
            })
开发者ID:AnishShah,项目名称:tensorflow,代码行数:25,代码来源:slide_dataset_op_test.py

示例7: testStreamingQuantileBuckets

  def testStreamingQuantileBuckets(self):
    """Sets up the quantile summary op test as follows.

    100 batches of data is added to the accumulator. The batches are in form:
    [0 1 .. 99]
    [100 101 .. 200]
    ...
    [9900 9901 .. 9999]
    All the batches have 1 for all the example weights.
    """
    with self.test_session() as sess:
      accumulator = quantile_ops.QuantileAccumulator(
          init_stamp_token=0, num_quantiles=3, epsilon=0.01, name="q1")
      resources.initialize_resources(resources.shared_resources()).run()
    weight_placeholder = array_ops.placeholder(dtypes.float32)
    dense_placeholder = array_ops.placeholder(dtypes.float32)
    update = accumulator.add_summary(
        stamp_token=0,
        column=dense_placeholder,
        example_weights=weight_placeholder)
    with self.test_session() as sess:
      for i in range(100):
        dense_float = np.linspace(
            i * 100, (i + 1) * 100 - 1, num=100).reshape(-1, 1)
        sess.run(update, {
            dense_placeholder: dense_float,
            weight_placeholder: np.ones(shape=(100, 1), dtype=np.float32)
        })

    with self.test_session() as sess:
      sess.run(accumulator.flush(stamp_token=0, next_stamp_token=1))
      are_ready_flush, buckets = (accumulator.get_buckets(stamp_token=1))
      buckets, are_ready_flush = (sess.run([buckets, are_ready_flush]))
      self.assertEqual(True, are_ready_flush)
      self.assertAllEqual([0, 3335., 6671., 9999.], buckets)
开发者ID:ChengYuXiang,项目名称:tensorflow,代码行数:35,代码来源:quantile_ops_test.py

示例8: testPaddedBatchDatasetShapeSpecifications

  def testPaddedBatchDatasetShapeSpecifications(self):
    int_placeholder = array_ops.placeholder(dtypes.int32)
    float_placeholder = array_ops.placeholder(dtypes.float32)
    string_placeholder = array_ops.placeholder(dtypes.string)
    input_dataset = dataset_ops.Dataset.from_tensors(
        (int_placeholder, float_placeholder, string_placeholder))

    # Test different ways of specifying the `padded_shapes` argument.
    dynamic_padding_from_tensor_shapes = input_dataset.padded_batch(
        32,
        padded_shapes=(tensor_shape.TensorShape([None]),
                       tensor_shape.TensorShape([None, None]),
                       tensor_shape.TensorShape([37])))
    dynamic_padding_from_lists = input_dataset.padded_batch(
        32, padded_shapes=([None], [None, None], [37]))
    dynamic_padding_from_lists_with_minus_one = input_dataset.padded_batch(
        32, padded_shapes=([-1], [-1, -1], [37]))
    dynamic_padding_from_tensors = input_dataset.padded_batch(
        32,
        padded_shapes=(constant_op.constant([-1], dtype=dtypes.int64),
                       constant_op.constant([-1, -1], dtype=dtypes.int64),
                       constant_op.constant([37], dtype=dtypes.int64)))

    for dataset in [dynamic_padding_from_tensor_shapes,
                    dynamic_padding_from_lists,
                    dynamic_padding_from_lists_with_minus_one,
                    dynamic_padding_from_tensors]:
      self.assertEqual([None, None], dataset.output_shapes[0].as_list())
      self.assertEqual([None, None, None], dataset.output_shapes[1].as_list())
      self.assertEqual([None, 37], dataset.output_shapes[2].as_list())
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:30,代码来源:batch_dataset_op_test.py

示例9: _testIdentityOperator

 def _testIdentityOperator(self, use_static_shape_):
   for dtype in np.float32, np.float64:
     a_np = np.array([[1., 2.], [3., 4.], [5., 6.]], dtype=dtype)
     x_np = np.array([[2.], [-3.]], dtype=dtype)
     y_np = np.array([[2], [-3.], [5.]], dtype=dtype)
     with self.test_session() as sess:
       if use_static_shape_:
         a = constant_op.constant(a_np, dtype=dtype)
         x = constant_op.constant(x_np, dtype=dtype)
         y = constant_op.constant(y_np, dtype=dtype)
       else:
         a = array_ops.placeholder(dtype)
         x = array_ops.placeholder(dtype)
         y = array_ops.placeholder(dtype)
       id_op = util.identity_operator(a)
       ax = id_op.apply(x)
       aty = id_op.apply_adjoint(y)
       op_shape = ops.convert_to_tensor(id_op.shape)
       if use_static_shape_:
         op_shape_val, ax_val, aty_val = sess.run([op_shape, ax, aty])
       else:
         op_shape_val, ax_val, aty_val = sess.run(
             [op_shape, ax, aty], feed_dict={a: a_np,
                                             x: x_np,
                                             y: y_np})
     self.assertAllEqual(op_shape_val, [3, 2])
     self.assertAllClose(ax_val, x_np)
     self.assertAllClose(aty_val, y_np)
开发者ID:ChengYuXiang,项目名称:tensorflow,代码行数:28,代码来源:util_test.py

示例10: testFeedSparseTensor

 def testFeedSparseTensor(self):
   with session.Session() as s:
     indices = np.array([[3, 2, 0], [4, 5, 1]]).astype(np.int64)
     values = np.array([1.0, 2.0]).astype(np.float32)
     shape = np.array([7, 9, 2]).astype(np.int64)
     sp = ops.SparseTensor(
         array_ops.placeholder(dtype=np.int64, shape=(2, 3)),
         array_ops.placeholder(dtype=np.float32, shape=(2,)),
         array_ops.placeholder(dtype=np.int64, shape=(3,)),)
     sp_indices = array_ops.identity(sp.indices)
     sp_values = array_ops.identity(sp.values)
     sp_shape = array_ops.identity(sp.shape)
     sp2 = ops.SparseTensor(sp_indices, sp_values, sp_shape)
     # Feed with tuple
     indices_out, values_out, shape_out = s.run(
         [sp_indices, sp_values, sp_shape], {sp: (indices, values, shape)})
     self.assertAllEqual(indices_out, indices)
     self.assertAllEqual(values_out, values)
     self.assertAllEqual(shape_out, shape)
     # Feed with SparseTensorValue
     indices_out, values_out, shape_out = s.run(
         [sp_indices, sp_values, sp_shape],
         {sp: ops.SparseTensorValue(indices, values, shape)})
     self.assertAllEqual(indices_out, indices)
     self.assertAllEqual(values_out, values)
     self.assertAllEqual(shape_out, shape)
     # Feed with SparseTensorValue, fetch SparseTensorValue
     sp2_out = s.run(sp2, {sp: ops.SparseTensorValue(indices, values, shape)})
     self.assertAllEqual(sp2_out.indices, indices)
     self.assertAllEqual(sp2_out.values, values)
     self.assertAllEqual(sp2_out.shape, shape)
开发者ID:agouwin,项目名称:udacity_deep_learning_homework,代码行数:31,代码来源:session_test.py

示例11: testFeedIndexedSlicesWithoutDenseShape

 def testFeedIndexedSlicesWithoutDenseShape(self):
   with session.Session() as s:
     values = np.array([1.0, 2.0]).astype(np.float32)
     indices = np.array([[3, 2, 0], [4, 5, 1]]).astype(np.int64)
     dense_shape = None
     ind = ops.IndexedSlices(
         array_ops.placeholder(dtype=np.float32,
                               shape=(2,)),
         array_ops.placeholder(dtype=np.int64,
                               shape=(2, 3)),
         None)
     ind_values = array_ops.identity(ind.values)
     ind_indices = array_ops.identity(ind.indices)
     ind2 = ops.IndexedSlices(ind_values, ind_indices)
     # Feed with tuple
     values_out, indices_out = s.run(
         [ind_values, ind_indices], {ind: (values, indices)})
     self.assertAllEqual(values_out, values)
     self.assertAllEqual(indices_out, indices)
     # Feed with IndexedSlicesValue
     values_out, indices_out = s.run(
         [ind_values, ind_indices],
         {ind: ops.IndexedSlicesValue(values, indices, dense_shape)})
     self.assertAllEqual(values_out, values)
     self.assertAllEqual(indices_out, indices)
     # Feed with IndexedSlicesValue, fetch IndexedSlicesValue
     ind2_out = s.run(ind2, {ind: ops.IndexedSlicesValue(values, indices,
                                                         dense_shape)})
     self.assertAllEqual(ind2_out.values, values)
     self.assertAllEqual(ind2_out.indices, indices)
     self.assertAllEqual(ind2_out.dense_shape, dense_shape)
开发者ID:agouwin,项目名称:udacity_deep_learning_homework,代码行数:31,代码来源:session_test.py

示例12: testProbNonScalarBaseDistributionScalarTransformDynamic

  def testProbNonScalarBaseDistributionScalarTransformDynamic(self):
    # Non-scalar batch_shape.
    df = np.asarray([1., 2., 3.], dtype=np.float32)
    # Scalar batch_shape.
    loc = np.asarray([1, 2, 3], dtype=np.float32)
    scale_diag = np.asarray([2, 3, 4], dtype=np.float32)
    scale_tril = np.diag(scale_diag)

    x = 2. * self._rng.rand(4, 3, 3).astype(np.float32) - 1.

    expected_mst = _FakeVectorStudentT(
        df=df,
        loc=np.tile(loc[array_ops.newaxis, :], reps=[len(df), 1]),
        scale_tril=np.tile(scale_tril[array_ops.newaxis, :, :],
                           reps=[len(df), 1, 1]))

    with self.cached_session():
      df_pl = array_ops.placeholder(dtypes.float32, name="df")
      loc_pl = array_ops.placeholder(dtypes.float32, name="loc")
      scale_diag_pl = array_ops.placeholder(dtypes.float32, name="scale_diag")
      feed_dict = {df_pl: df, loc_pl: loc, scale_diag_pl: scale_diag}
      actual_mst = _VectorStudentT(df=df, loc=loc, scale_diag=scale_diag,
                                   validate_args=True)
      self.assertAllClose(expected_mst.log_prob(x),
                          actual_mst.log_prob(x).eval(feed_dict=feed_dict),
                          rtol=0., atol=1e-5)
      self.assertAllClose(expected_mst.prob(x),
                          actual_mst.prob(x).eval(feed_dict=feed_dict),
                          rtol=0., atol=1e-5)
开发者ID:Ajaycs99,项目名称:tensorflow,代码行数:29,代码来源:vector_student_t_test.py

示例13: testProbScalarBaseDistributionNonScalarTransformDynamic

  def testProbScalarBaseDistributionNonScalarTransformDynamic(self):
    # Scalar batch_shape.
    df = np.asarray(2., dtype=np.float32)
    # Non-scalar batch_shape.
    loc = np.asarray([[0., 0, 0],
                      [1, 2, 3],
                      [1, 0, 1]],
                     dtype=np.float32)
    scale_diag = np.asarray([[1., 2, 3],
                             [2, 3, 4],
                             [4, 5, 6]],
                            dtype=np.float32)
    scale_tril = np.concatenate([[np.diag(scale_diag[i])]
                                 for i in range(len(scale_diag))])
    x = 2. * self._rng.rand(4, 3, 3).astype(np.float32) - 1.

    expected_mst = _FakeVectorStudentT(
        df=np.tile(df, reps=len(scale_diag)),
        loc=loc,
        scale_tril=scale_tril)

    with self.cached_session():
      df_pl = array_ops.placeholder(dtypes.float32, name="df")
      loc_pl = array_ops.placeholder(dtypes.float32, name="loc")
      scale_diag_pl = array_ops.placeholder(dtypes.float32, name="scale_diag")
      feed_dict = {df_pl: df, loc_pl: loc, scale_diag_pl: scale_diag}
      actual_mst = _VectorStudentT(df=df, loc=loc, scale_diag=scale_diag,
                                   validate_args=True)
      self.assertAllClose(expected_mst.log_prob(x),
                          actual_mst.log_prob(x).eval(feed_dict=feed_dict),
                          rtol=0., atol=1e-5)
      self.assertAllClose(expected_mst.prob(x),
                          actual_mst.prob(x).eval(feed_dict=feed_dict),
                          rtol=0., atol=1e-5)
开发者ID:Ajaycs99,项目名称:tensorflow,代码行数:34,代码来源:vector_student_t_test.py

示例14: testSparseCount

  def testSparseCount(self):
    def _sparse(i):
      return sparse_tensor.SparseTensorValue(
          indices=np.array([[0, 0]]),
          values=(i * np.array([1])),
          dense_shape=np.array([1, 1]))

    def make_scan_fn(step):
      return lambda state, _: (_sparse(state.values[0] + step), state)

    start = array_ops.placeholder(dtypes.int32, shape=[])
    step = array_ops.placeholder(dtypes.int32, shape=[])
    take = array_ops.placeholder(dtypes.int64, shape=[])
    iterator = self._counting_dataset(
        _sparse(start),
        make_scan_fn(step)).take(take).make_initializable_iterator()
    next_element = iterator.get_next()

    with self.cached_session() as sess:

      for start_val, step_val, take_val in [(0, 1, 10), (0, 1, 0), (10, 1, 10),
                                            (10, 2, 10), (10, -1, 10),
                                            (10, -2, 10)]:
        sess.run(iterator.initializer,
                 feed_dict={start: start_val, step: step_val, take: take_val})
        for expected, _ in zip(
            itertools.count(start_val, step_val), range(take_val)):
          self.assertEqual(expected, sess.run(next_element).values[0])
        with self.assertRaises(errors.OutOfRangeError):
          sess.run(next_element)
开发者ID:AnishShah,项目名称:tensorflow,代码行数:30,代码来源:scan_dataset_op_test.py

示例15: testGradientsNegativeAxis

  def testGradientsNegativeAxis(self):
    x1 = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
    x2 = [[7.0, 8.0, 9.0], [10.0, 11.0, 12.0]]
    inp_tensors = [constant_op.constant(x1, shape=(2, 3), dtype=dtypes.float32),
                   constant_op.constant(x2, shape=(2, 3), dtype=dtypes.float32)]

    # Test concat gradient with axis == -2
    self._testGradientsForAxis(inp_tensors, -2, output_shape=[4, 3])

    # Test concat gradient with unknown-shape tensors.
    x1_placeholder = array_ops.placeholder(dtypes.float32)
    x2_placeholder = array_ops.placeholder(dtypes.float32)
    inp_tensors_placeholders = [x1_placeholder, x2_placeholder]
    feed_dict = {x1_placeholder: x1, x2_placeholder: x2}
    self._testGradientsForAxis(
        inp_tensors_placeholders, -1, output_shape=[2, 6], feed_dict=feed_dict)

    # Test IndexedSlices concat gradient.
    self._testIndexedSlicesGradientsForAxis(
        inp_tensors, -2, output_shape=[2, 3], gather_indexes=[2, 0])

    # We don't support calculating IndexedSlices concat gradient for
    # negative indexes when rank is not known.
    with self.assertRaises(ValueError):
      self._testIndexedSlicesGradientsForAxis(
          inp_tensors_placeholders, -2, output_shape=[2, 3],
          gather_indexes=[2, 0], feed_dict=feed_dict)
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:27,代码来源:concat_op_test.py


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