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


Python tensorflow.SparseTensorValue方法代码示例

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


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

示例1: _run_graph

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def _run_graph(self, sess, qq, hh, tt, mdb, to_fetch):
        feed = {}
        if not self.query_is_language:
            feed[self.queries] = [[q] * (self.num_step-1) + [self.num_query]
                                  for q in qq]
        else:
            feed[self.queries] = [[q] * (self.num_step-1) 
                                  + [[self.num_vocab] * self.num_word]
                                  for q in qq]

        feed[self.heads] = hh 
        feed[self.tails] = tt 
        for r in xrange(self.num_operator / 2):
            feed[self.database[r]] = tf.SparseTensorValue(*mdb[r]) 
        fetches = to_fetch
        graph_output = sess.run(fetches, feed)
        return graph_output 
开发者ID:fanyangxyz,项目名称:Neural-LP,代码行数:19,代码来源:model.py

示例2: shape_internal

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def shape_internal(input, name=None, optimize=True, out_type=dtypes.int32):
  # pylint: disable=redefined-builtin
  """Returns the shape of a tensor.

  Args:
    input: A `Tensor` or `SparseTensor`.
    name: A name for the operation (optional).
    optimize: if true, encode the shape as a constant when possible.
    out_type: (Optional) The specified output type of the operation
      (`int32` or `int64`). Defaults to tf.int32.

  Returns:
    A `Tensor` of type `out_type`.

  """
  with ops.name_scope(name, "Shape", [input]) as name:
    if isinstance(
        input, (sparse_tensor.SparseTensor, sparse_tensor.SparseTensorValue)):
      return gen_math_ops.cast(input.dense_shape, out_type)
    else:
      input_tensor = ops.convert_to_tensor(input)
      input_shape = input_tensor.get_shape()
      if optimize and input_shape.is_fully_defined():
        return constant(input_shape.as_list(), out_type, name=name)
      return gen_array_ops.shape(input, name=name, out_type=out_type) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:array_ops.py

示例3: size_internal

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def size_internal(input, name=None, optimize=True, out_type=dtypes.int32):
  # pylint: disable=redefined-builtin,protected-access
  """Returns the size of a tensor.

  Args:
    input: A `Tensor` or `SparseTensor`.
    name: A name for the operation (optional).
    optimize: if true, encode the size as a constant when possible.
    out_type: (Optional) The specified output type of the operation
      (`int32` or `int64`). Defaults to tf.int32.

  Returns:
    A `Tensor` of type `out_type`.
  """
  with ops.name_scope(name, "Size", [input]) as name:
    if isinstance(
        input, (sparse_tensor.SparseTensor, sparse_tensor.SparseTensorValue)):
      return gen_math_ops._prod(
          gen_math_ops.cast(input.dense_shape, out_type), 0, name=name)
    else:
      input_tensor = ops.convert_to_tensor(input)
      input_shape = input_tensor.get_shape()
      if optimize and input_shape.is_fully_defined():
        return constant(input_shape.num_elements(), out_type, name=name)
      return gen_array_ops.size(input, name=name, out_type=out_type) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:array_ops.py

示例4: rank_internal

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def rank_internal(input, name=None, optimize=True):
  # pylint: disable=redefined-builtin
  """Returns the rank of a tensor.

  Args:
    input: A `Tensor` or `SparseTensor`.
    name: A name for the operation (optional).
    optimize: if true, encode the rank as a constant when possible.

  Returns:
    A `Tensor` of type `int32`.
  """
  with ops.name_scope(name, "Rank", [input]) as name:
    if isinstance(
        input, (sparse_tensor.SparseTensor, sparse_tensor.SparseTensorValue)):
      return gen_array_ops.size(input.dense_shape, name=name)
    else:
      input_tensor = ops.convert_to_tensor(input)
      input_shape = input_tensor.get_shape()
      if optimize and input_shape.ndims is not None:
        return constant(input_shape.ndims, dtypes.int32, name=name)
      return gen_array_ops.rank(input, name=name) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:24,代码来源:array_ops.py

示例5: _get_labels_feed_item

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def _get_labels_feed_item(label_list, max_time):
    """
    Generate the tensor from 'label_list' to feed as labels into the network

    Args:
      label_list: a list of encoded labels (ints)
      max_time: the maximum time length of `label_list`

    Returns: the SparseTensorValue to feed into the network

    """

    label_shape = np.array([len(label_list), max_time], dtype=np.int)
    label_indices = []
    label_values = []
    for labelIdx, label in enumerate(label_list):
      for idIdx, identifier in enumerate(label):
        label_indices.append([labelIdx, idIdx])
        label_values.append(identifier)
    label_indices = np.array(label_indices, dtype=np.int)
    label_values = np.array(label_values, dtype=np.int)
    return tf.SparseTensorValue(label_indices, label_values, label_shape) 
开发者ID:timediv,项目名称:speechT,代码行数:24,代码来源:speech_input.py

示例6: output_s

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def output_s(self):
        batch_num = int(self.test_data_amt / self.batch_size)
        output = np.ones([self.batch_size, 300])
        for i in range(batch_num):
            x_batch_field, b_batch, z_batch, y_batch, all_prices = self.util_test.get_batch_data_sorted_dwpp(i)
            feed_dict = {}
            for j in range(len(self.X)):
                feed_dict[self.X[j]] = tf.SparseTensorValue(x_batch_field[j], [1] * len(x_batch_field[j]),
                                                                  [self.batch_size, self.field_sizes[j]])
            feed_dict[self.b] = b_batch
            feed_dict[self.z] = z_batch
            feed_dict[self.y] = y_batch
            feed_dict[self.all_prices] = all_prices
            output = np.vstack([output, self.sess.run(self.w_all, feed_dict)])
        print(output.shape)
        np.savetxt(self.output_dir + 's.txt', 1 - output[self.batch_size:,], delimiter='\t', fmt='%.4f') 
开发者ID:rk2900,项目名称:DLF,代码行数:18,代码来源:DWPP.py

示例7: convert2SparseTensorValue

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def convert2SparseTensorValue(list_labels):
    #
    # list_labels: batch_major
    #
   
    #
    num_samples = len(list_labels)
    num_maxlen = max(map(lambda x: len(x), list_labels))
    #
    indices = []
    values = []
    shape = [num_samples, num_maxlen]
    #
    for idx in range(num_samples):
        #
        item = list_labels[idx]
        #
        values.extend(item)
        indices.extend([[idx, posi] for posi in range(len(item))])    
        #
    #
    return tf.SparseTensorValue(indices = indices, values = values, dense_shape = shape)
    #
# 
开发者ID:Li-Ming-Fan,项目名称:OCR-CRNN-CTC,代码行数:26,代码来源:model_recog_def.py

示例8: to_sparse_tensor

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def to_sparse_tensor(M, value=False):
    """Convert a scipy sparse matrix to a tf SparseTensor or SparseTensorValue.

    Parameters
    ----------
    M : scipy.sparse.sparse
        Matrix in Scipy sparse format.
    value : bool, default False
        Convert to tf.SparseTensorValue if True, else to tf.SparseTensor.

    Returns
    -------
    S : tf.SparseTensor or tf.SparseTensorValue
        Matrix as a sparse tensor.

    Author: Oleksandr Shchur
    """
    M = sp.coo_matrix(M)
    if value:
        return tf.SparseTensorValue(np.vstack((M.row, M.col)).T, M.data, M.shape)
    else:
        return tf.SparseTensor(np.vstack((M.row, M.col)).T, M.data, M.shape) 
开发者ID:shchur,项目名称:gnn-benchmark,代码行数:24,代码来源:util.py

示例9: _SparseTensorValue_3x50

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def _SparseTensorValue_3x50(self, indices_dtype, values_dtype):
    # NOTE: This input is intentionally not sorted to validate the
    # already_sorted flag below.
    ind = np.array([
        [0, 0],
        [1, 0], [1, 2],
        [2, 0], [2, 1],
        [1, 1]])
    # NB: these are not sorted
    indices = np.array([0, 13, 10, 33, 32, 14])
    values = np.array([-3, 4, 1, 9, 5, 1])
    shape = np.array([3, 3])
    indices = tf.SparseTensorValue(
        np.array(ind, np.int64),
        np.array(indices, indices_dtype),
        np.array(shape, np.int64))
    values = tf.SparseTensorValue(
        np.array(ind, np.int64),
        np.array(values, values_dtype),
        np.array(shape, np.int64))
    return indices, values 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:23,代码来源:sparse_ops_test.py

示例10: shape_internal

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def shape_internal(input, name=None, optimize=True, out_type=dtypes.int32):
  # pylint: disable=redefined-builtin
  """Returns the shape of a tensor.

  Args:
    input: A `Tensor` or `SparseTensor`.
    name: A name for the operation (optional).
    optimize: if true, encode the shape as a constant when possible.
    out_type: (Optional) The specified output type of the operation
      (`int32` or `int64`). Defaults to tf.int32.

  Returns:
    A `Tensor` of type `out_type`.

  """
  with ops.name_scope(name, "Shape", [input]) as name:
    if isinstance(
        input, (sparse_tensor.SparseTensor, sparse_tensor.SparseTensorValue)):
      return gen_math_ops.cast(input.shape, out_type)
    else:
      input_tensor = ops.convert_to_tensor(input)
      input_shape = input_tensor.get_shape()
      if optimize and input_shape.is_fully_defined():
        return constant(input_shape.as_list(), out_type, name=name)
      return gen_array_ops.shape(input, name=name, out_type=out_type) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:27,代码来源:array_ops.py

示例11: size_internal

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def size_internal(input, name=None, optimize=True, out_type=dtypes.int32):
  # pylint: disable=redefined-builtin,protected-access
  """Returns the size of a tensor.

  Args:
    input: A `Tensor` or `SparseTensor`.
    name: A name for the operation (optional).
    optimize: if true, encode the size as a constant when possible.
    out_type: (Optional) The specified output type of the operation
      (`int32` or `int64`). Defaults to tf.int32.

  Returns:
    A `Tensor` of type `out_type`.
  """
  with ops.name_scope(name, "Size", [input]) as name:
    if isinstance(
        input, (sparse_tensor.SparseTensor, sparse_tensor.SparseTensorValue)):
      return gen_math_ops._prod(
          gen_math_ops.cast(input.shape, out_type), 0, name=name)
    else:
      input_tensor = ops.convert_to_tensor(input)
      input_shape = input_tensor.get_shape()
      if optimize and input_shape.is_fully_defined():
        return constant(input_shape.num_elements(), out_type, name=name)
      return gen_array_ops.size(input, name=name, out_type=out_type) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:27,代码来源:array_ops.py

示例12: clip_last_batch

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def clip_last_batch(self, last_batch, true_size):
    """This method performs last batch clipping.
    Used in cases when dataset is not divisible by the batch size and model
    does not support dynamic batch sizes. In those cases, the last batch will
    contain some data from the "next epoch" and this method can be used
    to remove that data. This method works for both
    dense and sparse tensors. In most cases you will not need to overwrite this
    method.

    Args:
      last_batch (list): list with elements that could be either ``np.array``
          or ``tf.SparseTensorValue`` containing data for last batch. The
          assumption is that the first axis of all data tensors will correspond
          to the current batch size.
      true_size (int): true size that the last batch should be cut to.
    """
    return clip_last_batch(last_batch, true_size) 
开发者ID:NVIDIA,项目名称:OpenSeq2Seq,代码行数:19,代码来源:model.py

示例13: make_sparse

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def make_sparse(sequences, domain_length, peptide_length, n_amino_acids):
    def _sparsify(arr, ncols):
        nrows = arr.shape[0]

        ridxes, compressed_cidxes = np.where(arr >= 0)
        cidxes = arr[ridxes, compressed_cidxes]
        
        vals = np.ones(ridxes.size)
        
        idxes = np.vstack([ridxes, cidxes]).T
         
        shape = [nrows, ncols]
        
        return tf.SparseTensorValue(
                    indices = idxes, 
                    values = vals,
                    dense_shape = shape
                )
    
    col_sizes = [domain_length * n_amino_acids, peptide_length * n_amino_acids, domain_length * peptide_length * n_amino_acids * n_amino_acids]
    return [_sparsify(m, ncols) for m, ncols in zip(sequences, col_sizes)] 
开发者ID:aqlaboratory,项目名称:hsm,代码行数:23,代码来源:utils.py

示例14: size_internal

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def size_internal(input, name=None, optimize=True, out_type=dtypes.int32):
  # pylint: disable=redefined-builtin,protected-access
  """Returns the size of a tensor.

  Args:
    input: A `Tensor` or `SparseTensor`.
    name: A name for the operation (optional).
    optimize: if true, encode the size as a constant when possible.
    out_type: (Optional) The specified output type of the operation
      (`int32` or `int64`). Defaults to tf.int32.

  Returns:
    A `Tensor` of type `out_type`.
  """
  with ops.name_scope(name, "Size", [input]) as name:
    if isinstance(input, (sparse_tensor.SparseTensor,
                          sparse_tensor.SparseTensorValue)):
      return gen_math_ops._prod(
          gen_math_ops.cast(input.dense_shape, out_type), 0, name=name)
    else:
      input_tensor = ops.convert_to_tensor(input)
      input_shape = input_tensor.get_shape()
      if optimize and input_shape.is_fully_defined():
        return constant(input_shape.num_elements(), out_type, name=name)
      return gen_array_ops.size(input, name=name, out_type=out_type) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:27,代码来源:array_ops.py

示例15: rank_internal

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import SparseTensorValue [as 别名]
def rank_internal(input, name=None, optimize=True):
  # pylint: disable=redefined-builtin
  """Returns the rank of a tensor.

  Args:
    input: A `Tensor` or `SparseTensor`.
    name: A name for the operation (optional).
    optimize: if true, encode the rank as a constant when possible.

  Returns:
    A `Tensor` of type `int32`.
  """
  with ops.name_scope(name, "Rank", [input]) as name:
    if isinstance(input, (sparse_tensor.SparseTensor,
                          sparse_tensor.SparseTensorValue)):
      return gen_array_ops.size(input.dense_shape, name=name)
    else:
      input_tensor = ops.convert_to_tensor(input)
      input_shape = input_tensor.get_shape()
      if optimize and input_shape.ndims is not None:
        return constant(input_shape.ndims, dtypes.int32, name=name)
      return gen_array_ops.rank(input, name=name) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:24,代码来源:array_ops.py


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