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


Python array_ops.sparse_placeholder函数代码示例

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


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

示例1: testPlaceholder

  def testPlaceholder(self):
    with self.test_session(use_gpu=False):
      foo = array_ops.sparse_placeholder(dtypes.float32, shape=(10, 47))
      self.assertAllEqual([10, 47], foo.get_shape())

      foo = array_ops.sparse_placeholder(dtypes.float32, shape=(None, 47))
      self.assertAllEqual(None, foo.get_shape())
开发者ID:jon-sch,项目名称:tensorflow,代码行数:7,代码来源:sparse_ops_test.py

示例2: _create_dummy_inputs

 def _create_dummy_inputs(self):
   return {
       "sc_int": array_ops.sparse_placeholder(dtypes.int32),
       "sc_hash": array_ops.sparse_placeholder(dtypes.string),
       "sc_keys": array_ops.sparse_placeholder(dtypes.string),
       "sc_vocab": array_ops.sparse_placeholder(dtypes.string),
       "real": array_ops.placeholder(dtypes.float32)
   }
开发者ID:ChengYuXiang,项目名称:tensorflow,代码行数:8,代码来源:warm_starting_util_test.py

示例3: setUp

  def setUp(self):
    self._tmp_dir = tempfile.mktemp()

    self.v = variables.Variable(10.0, name="v")
    self.w = variables.Variable(21.0, name="w")
    self.delta = constant_op.constant(1.0, name="delta")
    self.inc_v = state_ops.assign_add(self.v, self.delta, name="inc_v")

    self.w_int = control_flow_ops.with_dependencies(
        [self.inc_v],
        math_ops.cast(self.w, dtypes.int32, name="w_int_inner"),
        name="w_int_outer")

    self.ph = array_ops.placeholder(dtypes.float32, name="ph")
    self.xph = array_ops.transpose(self.ph, name="xph")
    self.m = constant_op.constant(
        [[0.0, 1.0, 2.0], [-4.0, -1.0, 0.0]], dtype=dtypes.float32, name="m")
    self.y = math_ops.matmul(self.m, self.xph, name="y")

    self.sparse_ph = array_ops.sparse_placeholder(
        dtypes.float32, shape=([5, 5]), name="sparse_placeholder")
    self.sparse_add = sparse_ops.sparse_add(self.sparse_ph, self.sparse_ph)

    self.sess = session.Session()

    # Initialize variable.
    self.sess.run(variables.global_variables_initializer())
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:27,代码来源:local_cli_wrapper_test.py

示例4: testFeedSparsePlaceholder

 def testFeedSparsePlaceholder(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 = array_ops.sparse_placeholder(dtype=np.float32, name='placeholder1')
     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:3kwa,项目名称:tensorflow,代码行数:28,代码来源:session_test.py

示例5: setUp

  def setUp(self):
    self._tmp_dir = tempfile.mktemp()

    self.v = variables.Variable(10.0, name="v")
    self.w = variables.Variable(21.0, name="w")
    self.delta = constant_op.constant(1.0, name="delta")
    self.inc_v = state_ops.assign_add(self.v, self.delta, name="inc_v")

    self.w_int = control_flow_ops.with_dependencies(
        [self.inc_v],
        math_ops.cast(self.w, dtypes.int32, name="w_int_inner"),
        name="w_int_outer")

    self.ph = array_ops.placeholder(dtypes.float32, name="ph")
    self.xph = array_ops.transpose(self.ph, name="xph")
    self.m = constant_op.constant(
        [[0.0, 1.0, 2.0], [-4.0, -1.0, 0.0]], dtype=dtypes.float32, name="m")
    self.y = math_ops.matmul(self.m, self.xph, name="y")

    self.sparse_ph = array_ops.sparse_placeholder(
        dtypes.float32, shape=([5, 5]), name="sparse_placeholder")
    self.sparse_add = sparse_ops.sparse_add(self.sparse_ph, self.sparse_ph)

    rewriter_config = rewriter_config_pb2.RewriterConfig(
        disable_model_pruning=True,
        arithmetic_optimization=rewriter_config_pb2.RewriterConfig.OFF,
        dependency_optimization=rewriter_config_pb2.RewriterConfig.OFF)
    graph_options = config_pb2.GraphOptions(rewrite_options=rewriter_config)
    config_proto = config_pb2.ConfigProto(graph_options=graph_options)
    self.sess = session.Session(config=config_proto)

    # Initialize variable.
    self.sess.run(variables.global_variables_initializer())
开发者ID:AnishShah,项目名称:tensorflow,代码行数:33,代码来源:local_cli_wrapper_test.py

示例6: make_place_holder_tensors_for_base_features

def make_place_holder_tensors_for_base_features(feature_columns):
  """Returns placeholder tensors for inference.

  Args:
    feature_columns: An iterable containing all the feature columns. All items
      should be instances of classes derived from _FeatureColumn.
  Returns:
    A dict mapping feature keys to SparseTensors (sparse columns) or
    placeholder Tensors (dense columns).
  """
  # Get dict mapping features to FixedLenFeature or VarLenFeature values.
  dict_for_parse_example = create_feature_spec_for_parsing(feature_columns)
  placeholders = {}
  for column_name, column_type in dict_for_parse_example.items():
    if isinstance(column_type, parsing_ops.VarLenFeature):
      # Sparse placeholder for sparse tensors.
      placeholders[column_name] = array_ops.sparse_placeholder(
          column_type.dtype,
          name="Placeholder_" + column_name)
    else:
      # Simple placeholder for dense tensors.
      placeholders[column_name] = array_ops.placeholder(
          column_type.dtype,
          shape=(None, column_type.shape[0]),
          name="Placeholder_" + column_name)
  return placeholders
开发者ID:Ambier,项目名称:tensorflow,代码行数:26,代码来源:feature_column.py

示例7: testGetTensorFromInfoSparse

 def testGetTensorFromInfoSparse(self):
   expected = array_ops.sparse_placeholder(dtypes.float32, name="x")
   tensor_info = utils.build_tensor_info(expected)
   actual = utils.get_tensor_from_tensor_info(tensor_info)
   self.assertIsInstance(actual, sparse_tensor.SparseTensor)
   self.assertEqual(expected.values.name, actual.values.name)
   self.assertEqual(expected.indices.name, actual.indices.name)
   self.assertEqual(expected.dense_shape.name, actual.dense_shape.name)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:8,代码来源:utils_test.py

示例8: testInvalidDimensionSizeInputUnavailableInGraphConstruction

  def testInvalidDimensionSizeInputUnavailableInGraphConstruction(self):
    sp_input = array_ops.sparse_placeholder(dtype=dtypes.int32)
    with self.test_session(use_gpu=False) as sess:
      new_shape = np.array([3, 7, 5], dtype=np.int64)
      out = sparse_ops.sparse_reset_shape(sp_input, new_shape)

      with self.assertRaisesOpError("x <= y did not hold element-wise"):
        sess.run(out, feed_dict={sp_input: self._SparseTensorValue_2x5x6()})
开发者ID:govindap,项目名称:tensorflow,代码行数:8,代码来源:sparse_ops_test.py

示例9: __init__

  def __init__(self,
               input_shape=None,
               batch_size=None,
               dtype=dtypes.float32,
               input_tensor=None,
               sparse=False,
               name=None):
    super(InputLayer, self).__init__(dtype=dtype, name=name)
    self.built = True
    self.sparse = sparse
    self.batch_size = batch_size

    if isinstance(input_shape, tensor_shape.TensorShape):
      input_shape = tuple(input_shape.as_list())

    if input_tensor is None:
      if input_shape is not None:
        batch_input_shape = (batch_size,) + tuple(input_shape)
      else:
        batch_input_shape = None

      if context.in_eager_mode():
        # In eager mode, create a temporary placeholder to call the layer on.
        input_tensor = base._DeferredTensor(  # pylint: disable=protected-access
            shape=batch_input_shape,
            dtype=dtype,
            name=self.name)
      else:
        # In graph mode, create a graph placeholder to call the layer on.
        if sparse:
          input_tensor = array_ops.sparse_placeholder(
              shape=batch_input_shape,
              dtype=dtype,
              name=self.name)
        else:
          input_tensor = array_ops.placeholder(
              shape=batch_input_shape,
              dtype=dtype,
              name=self.name)

      # For compatibility with Keras API.
      self.is_placeholder = True
      self._batch_input_shape = batch_input_shape
    else:
      # For compatibility with Keras API.
      self.is_placeholder = False
      self._batch_input_shape = tuple(input_tensor.get_shape().as_list())

    # Create an input node to add to self.outbound_node
    # and set output_tensors' _keras_history.
    input_tensor._keras_history = (self, 0, 0)  # pylint: disable=protected-access
    base.Node(
        self,
        inbound_layers=[],
        node_indices=[],
        tensor_indices=[],
        input_tensors=[input_tensor],
        output_tensors=[input_tensor])
开发者ID:AnddyWang,项目名称:tensorflow,代码行数:58,代码来源:network.py

示例10: test_build_all_signature_defs_with_single_alternatives

  def test_build_all_signature_defs_with_single_alternatives(self):
    receiver_tensor = array_ops.placeholder(dtypes.string)
    receiver_tensors_alternative_1 = array_ops.placeholder(dtypes.int64)
    receiver_tensors_alternative_2 = array_ops.sparse_placeholder(
        dtypes.float32)
    # Note we are passing single Tensors as values of
    # receiver_tensors_alternatives, where normally that is a dict.
    # In this case a dict will be created using the default receiver tensor
    # name "input".
    receiver_tensors_alternatives = {"other1": receiver_tensors_alternative_1,
                                     "other2": receiver_tensors_alternative_2}
    output_1 = constant_op.constant([1.])
    output_2 = constant_op.constant(["2"])
    output_3 = constant_op.constant(["3"])
    export_outputs = {
        signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
            export_output.RegressionOutput(value=output_1),
        "head-2": export_output.ClassificationOutput(classes=output_2),
        "head-3": export_output.PredictOutput(outputs={
            "some_output_3": output_3
        }),
    }

    signature_defs = export.build_all_signature_defs(
        receiver_tensor, export_outputs, receiver_tensors_alternatives)

    expected_signature_defs = {
        "serving_default":
            signature_def_utils.regression_signature_def(
                receiver_tensor,
                output_1),
        "head-2":
            signature_def_utils.classification_signature_def(
                receiver_tensor,
                output_2, None),
        "head-3":
            signature_def_utils.predict_signature_def(
                {"input": receiver_tensor},
                {"some_output_3": output_3}),
        "other1:head-3":
            signature_def_utils.predict_signature_def(
                {"input": receiver_tensors_alternative_1},
                {"some_output_3": output_3}),
        "other2:head-3":
            signature_def_utils.predict_signature_def(
                {"input": receiver_tensors_alternative_2},
                {"some_output_3": output_3})

        # Note that the alternatives 'other:serving_default' and 'other:head-2'
        # are invalid, because regession and classification signatures must take
        # a single string input.  Here we verify that these invalid signatures
        # are not included in the export.
    }

    self.assertDictEqual(expected_signature_defs, signature_defs)
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:55,代码来源:export_test.py

示例11: testInputUnavaibleInGraphConstructionOk

    def testInputUnavaibleInGraphConstructionOk(self):
        with self.test_session(use_gpu=False) as sess:
            sp_input = array_ops.sparse_placeholder(dtype=dtypes.int32)
            new_shape = np.array([3, 6, 7], dtype=np.int64)
            sp_output = sparse_ops.sparse_reset_shape(sp_input, new_shape)

            output = sess.run(sp_output, feed_dict={sp_input: self._SparseTensorValue_2x5x6()})

            self.assertAllEqual(output.indices, [[0, 0, 0], [0, 1, 0], [0, 1, 3], [1, 1, 4], [1, 3, 2], [1, 3, 3]])
            self.assertAllEqual(output.values, [0, 10, 13, 14, 32, 33])
            self.assertAllEqual(output.shape, [3, 6, 7])
开发者ID:tongwang01,项目名称:tensorflow,代码行数:11,代码来源:sparse_ops_test.py

示例12: testBuildTensorInfoSparse

 def testBuildTensorInfoSparse(self):
   x = array_ops.sparse_placeholder(dtypes.float32, [42, 69], name="x")
   x_tensor_info = utils.build_tensor_info(x)
   self.assertEqual(x.values.name,
                    x_tensor_info.coo_sparse.values_tensor_name)
   self.assertEqual(x.indices.name,
                    x_tensor_info.coo_sparse.indices_tensor_name)
   self.assertEqual(x.dense_shape.name,
                    x_tensor_info.coo_sparse.dense_shape_tensor_name)
   self.assertEqual(types_pb2.DT_FLOAT, x_tensor_info.dtype)
   self.assertEqual(2, len(x_tensor_info.tensor_shape.dim))
   self.assertEqual(42, x_tensor_info.tensor_shape.dim[0].size)
   self.assertEqual(69, x_tensor_info.tensor_shape.dim[1].size)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:13,代码来源:utils_test.py

示例13: testGetNonFullySpecifiedShapes

 def testGetNonFullySpecifiedShapes(self):
   outputs = {
       "output-1": array_ops.placeholder(dtypes.float32, [None, 10, None]),
       "output-2": array_ops.sparse_placeholder(dtypes.float32),
   }
   signature_def = _make_signature({}, outputs)
   shapes = signature_def_utils_impl.get_signature_def_output_shapes(
       signature_def)
   self.assertEqual(len(shapes), 2)
   # Must compare shapes with as_list() since 2 equivalent non-fully defined
   # shapes are not equal to each other.
   self.assertEqual(shapes["output-1"].as_list(), [None, 10, None])
   # Must compare `dims` since its an unknown shape.
   self.assertEqual(shapes["output-2"].dims, None)
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:14,代码来源:signature_def_utils_test.py

示例14: testFeedSparePlaceholderConstantShape

 def testFeedSparePlaceholderConstantShape(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 = array_ops.sparse_placeholder(dtype=np.float32, shape=shape, name="placeholder1")
         self.assertAllEqual(sp.shape.eval(session=s), shape)
         self.assertAllEqual(tensor_util.constant_value(sp.shape), shape)
         sp_indices = array_ops.identity(sp.indices)
         sp_values = array_ops.identity(sp.values)
         sp_shape = array_ops.identity(sp.shape)
         # Feed with tuple
         indices_out, values_out, shape_out = s.run([sp_indices, sp_values, sp_shape], {sp: (indices, values)})
         self.assertAllEqual(indices_out, indices)
         self.assertAllEqual(values_out, values)
         self.assertAllEqual(shape_out, shape)
开发者ID:scott89,项目名称:tensorflow,代码行数:16,代码来源:session_test.py

示例15: testFromSparseTensorSlices

  def testFromSparseTensorSlices(self):
    """Test a dataset based on slices of a `tf.SparseTensor`."""
    st = array_ops.sparse_placeholder(dtypes.float64)
    iterator = (dataset_ops.Dataset.from_sparse_tensor_slices(st)
                .make_initializable_iterator())
    init_op = iterator.initializer
    get_next = sparse_tensor.SparseTensor(*iterator.get_next())

    with self.test_session() as sess:
      slices = [[1., 2., 3.], [1.], [1.], [1., 2.], [], [1., 2.], [], [], []]

      # Test with sparse tensor in the appropriate order.
      indices = np.array(
          [[i, j] for i in range(len(slices)) for j in range(len(slices[i]))])
      values = np.array([val for s in slices for val in s])
      dense_shape = np.array([len(slices), max(len(s) for s in slices) + 1])
      sparse_feed = sparse_tensor.SparseTensorValue(indices, values,
                                                    dense_shape)
      sess.run(init_op, feed_dict={st: sparse_feed})
      for i, s in enumerate(slices):
        results = sess.run(get_next)
        self.assertAllEqual(s, results.values)
        expected_indices = np.array(
            [[j] for j in range(len(slices[i]))]).reshape([-1, 1])
        self.assertAllEqual(expected_indices, results.indices)
        self.assertAllEqual(dense_shape[1:], results.dense_shape)
      with self.assertRaises(errors.OutOfRangeError):
        sess.run(get_next)

      # Test with sparse tensor in the reverse order, which is not
      # currently supported.
      reverse_order_indices = indices[::-1, :]
      reverse_order_values = values[::-1]
      sparse_feed = sparse_tensor.SparseTensorValue(
          reverse_order_indices, reverse_order_values, dense_shape)
      with self.assertRaises(errors.UnimplementedError):
        sess.run(init_op, feed_dict={st: sparse_feed})

      # Test with an empty sparse tensor.
      empty_indices = np.empty((0, 4), dtype=np.int64)
      empty_values = np.empty((0,), dtype=np.float64)
      empty_dense_shape = [0, 4, 37, 9]
      sparse_feed = sparse_tensor.SparseTensorValue(empty_indices, empty_values,
                                                    empty_dense_shape)
      sess.run(init_op, feed_dict={st: sparse_feed})
      with self.assertRaises(errors.OutOfRangeError):
        sess.run(get_next)
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:47,代码来源:dataset_constructor_op_test.py


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