當前位置: 首頁>>代碼示例>>Python>>正文


Python tensorflow.string_to_hash_bucket_fast方法代碼示例

本文整理匯總了Python中tensorflow.string_to_hash_bucket_fast方法的典型用法代碼示例。如果您正苦於以下問題:Python tensorflow.string_to_hash_bucket_fast方法的具體用法?Python tensorflow.string_to_hash_bucket_fast怎麽用?Python tensorflow.string_to_hash_bucket_fast使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.string_to_hash_bucket_fast方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _get_features_dict

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import string_to_hash_bucket_fast [as 別名]
def _get_features_dict(input_dict):
  """Extracts features dict from input dict."""

  source_id = _replace_empty_string_with_random_number(
      input_dict[fields.InputDataFields.source_id])

  hash_from_source_id = tf.string_to_hash_bucket_fast(source_id, HASH_BINS)
  features = {
      fields.InputDataFields.image:
          input_dict[fields.InputDataFields.image],
      HASH_KEY: tf.cast(hash_from_source_id, tf.int32),
      fields.InputDataFields.true_image_shape:
          input_dict[fields.InputDataFields.true_image_shape],
      fields.InputDataFields.original_image_spatial_shape:
          input_dict[fields.InputDataFields.original_image_spatial_shape]
  }
  if fields.InputDataFields.original_image in input_dict:
    features[fields.InputDataFields.original_image] = input_dict[
        fields.InputDataFields.original_image]
  return features 
開發者ID:ahmetozlu,項目名稱:vehicle_counting_tensorflow,代碼行數:22,代碼來源:inputs.py

示例2: _instruction

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import string_to_hash_bucket_fast [as 別名]
def _instruction(self, instruction):
    # Split string.
    splitted = tf.string_split(instruction)
    dense = tf.sparse_tensor_to_dense(splitted, default_value='')
    length = tf.reduce_sum(tf.to_int32(tf.not_equal(dense, '')), axis=1)

    # To int64 hash buckets. Small risk of having collisions. Alternatively, a
    # vocabulary can be used.
    num_hash_buckets = 1000
    buckets = tf.string_to_hash_bucket_fast(dense, num_hash_buckets)

    # Embed the instruction. Embedding size 20 seems to be enough.
    embedding_size = 20
    embedding = snt.Embed(num_hash_buckets, embedding_size)(buckets)

    # Pad to make sure there is at least one output.
    padding = tf.to_int32(tf.equal(tf.shape(embedding)[1], 0))
    embedding = tf.pad(embedding, [[0, 0], [0, padding], [0, 0]])

    core = tf.contrib.rnn.LSTMBlockCell(64, name='language_lstm')
    output, _ = tf.nn.dynamic_rnn(core, embedding, length, dtype=tf.float32)

    # Return last output.
    return tf.reverse_sequence(output, length, seq_axis=1)[:, 0] 
開發者ID:deepmind,項目名稱:scalable_agent,代碼行數:26,代碼來源:experiment.py

示例3: _graph_fn_call

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import string_to_hash_bucket_fast [as 別名]
def _graph_fn_call(self, text_inputs):
        """
        Args:
            text_inputs (SingleDataOp): The Text input to generate a hash bucket for.

        Returns:
            tuple:
                - SingleDataOp: The hash lookup table (int64) that can be used as input to embedding-lookups.
                - SingleDataOp: The length (number of words) of the longest string in the `text_input` batch.
        """
        if get_backend() == "tf":
            # Split the input string.
            split_text_inputs = tf.string_split(source=text_inputs, delimiter=self.delimiter)
            # Build a tensor of n rows (number of items in text_inputs) words with
            dense = tf.sparse_tensor_to_dense(sp_input=split_text_inputs, default_value="")

            length = tf.reduce_sum(input_tensor=tf.cast(x=tf.not_equal(x=dense, y=""), dtype=tf.int32), axis=-1)
            if self.hash_function == "fast":
                hash_bucket = tf.string_to_hash_bucket_fast(input=dense, num_buckets=self.num_hash_buckets)
            else:
                hash_bucket = tf.string_to_hash_bucket_strong(input=dense,
                                                              num_buckets=self.num_hash_buckets,
                                                              key=self.hash_keys)

            # Int64 is tf's default for `string_to_hash_bucket` operation: Can leave as is.
            if self.dtype != "int64":
                hash_bucket = tf.cast(x=hash_bucket, dtype=dtype_(self.dtype))

            # Hash-bucket output is always batch-major.
            hash_bucket._batch_rank = 0
            hash_bucket._time_rank = 1

            return hash_bucket, length 
開發者ID:rlgraph,項目名稱:rlgraph,代碼行數:35,代碼來源:string_to_hash_bucket.py

示例4: _get_features_dict

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import string_to_hash_bucket_fast [as 別名]
def _get_features_dict(input_dict):
  """Extracts features dict from input dict."""
  hash_from_source_id = tf.string_to_hash_bucket_fast(
      input_dict[fields.InputDataFields.source_id], HASH_BINS)
  features = {
      fields.InputDataFields.image:
          input_dict[fields.InputDataFields.image],
      HASH_KEY: tf.cast(hash_from_source_id, tf.int32),
      fields.InputDataFields.true_image_shape:
          input_dict[fields.InputDataFields.true_image_shape]
  }
  if fields.InputDataFields.original_image in input_dict:
    features[fields.InputDataFields.original_image] = input_dict[
        fields.InputDataFields.original_image]
  return features 
開發者ID:ambakick,項目名稱:Person-Detection-and-Tracking,代碼行數:17,代碼來源:inputs.py

示例5: hash_float

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import string_to_hash_bucket_fast [as 別名]
def hash_float(x, big_num=1000 * 1000):
    """Hash a tensor 'x' into a floating point number in the range [0, 1)."""
    return tf.cast(
        tf.string_to_hash_bucket_fast(x, big_num), tf.float32
    ) / tf.constant(float(big_num)) 
開發者ID:uizard-technologies,項目名稱:realmix,代碼行數:7,代碼來源:utils.py

示例6: testStringToOneHashBucketFast

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import string_to_hash_bucket_fast [as 別名]
def testStringToOneHashBucketFast(self):
    with self.test_session():
      input_string = tf.placeholder(tf.string)
      output = tf.string_to_hash_bucket_fast(input_string, 1)
      result = output.eval(feed_dict={input_string: ['a', 'b', 'c']})

      self.assertAllEqual([0, 0, 0], result) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:9,代碼來源:string_to_hash_bucket_op_test.py

示例7: testStringToHashBucketsFast

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import string_to_hash_bucket_fast [as 別名]
def testStringToHashBucketsFast(self):
    with self.test_session():
      input_string = tf.placeholder(tf.string)
      output = tf.string_to_hash_bucket_fast(input_string, 10)
      result = output.eval(feed_dict={input_string: ['a', 'b', 'c', 'd']})

      # Fingerprint64('a') -> 12917804110809363939 -> mod 10 -> 9
      # Fingerprint64('b') -> 11795596070477164822 -> mod 10 -> 2
      # Fingerprint64('c') -> 11430444447143000872 -> mod 10 -> 2
      # Fingerprint64('d') -> 4470636696479570465 -> mod 10 -> 5
      self.assertAllEqual([9, 2, 2, 5], result) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:13,代碼來源:string_to_hash_bucket_op_test.py

示例8: hash_in_range

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import string_to_hash_bucket_fast [as 別名]
def hash_in_range(self, buckets, base, limit):
    """Return true if the hashed id falls in the range [base, limit)."""
    hash_bucket = tf.string_to_hash_bucket_fast(self.id, buckets)
    return tf.logical_and(
        tf.greater_equal(hash_bucket, base), tf.less(hash_bucket, limit)) 
開發者ID:google,項目名稱:stereo-magnification,代碼行數:7,代碼來源:datasets.py

示例9: call

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import string_to_hash_bucket_fast [as 別名]
def call(self, x, mask=None, **kwargs):
        if x.dtype != tf.string:
            x = tf.as_string(x, )
        try:
            hash_x = tf.string_to_hash_bucket_fast(x, self.num_buckets if not self.mask_zero else self.num_buckets - 1,
                                                    name=None)  # weak hash
        except:
            hash_x = tf.strings.to_hash_bucket_fast(x, self.num_buckets if not self.mask_zero else self.num_buckets - 1,
                                               name=None)  # weak hash
        if self.mask_zero:
            mask_1 = tf.cast(tf.not_equal(x, "0"), 'int64')
            mask_2 = tf.cast(tf.not_equal(x, "0.0"), 'int64')
            mask = mask_1 * mask_2
            hash_x = (hash_x + 1) * mask
        return hash_x 
開發者ID:shenweichen,項目名稱:DeepCTR,代碼行數:17,代碼來源:utils.py


注:本文中的tensorflow.string_to_hash_bucket_fast方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。