Each comparison returns a boolean true (if input_value > threshold)
or and false otherwise.
This operation is useful for Locality-Sensitive-Hashing (LSH) and other
algorithms that use hashing approximations of cosine and L2 distances;
codes can be generated from an input via:
codebook_size=50codebook_bits=codebook_size*32codebook=tf.get_variable('codebook',[x.shape[-1].value,codebook_bits],dtype=x.dtype,initializer=tf.orthogonal_initializer())codes=compare_and_threshold(tf.matmul(x,codebook),threshold=0.)codes=tf.bitcast(codes,tf.int32)# go from uint8 to int32# now codes has shape x.shape[:-1] + [codebook_size]
Given an input shaped [s0, s1, ..., s_n], the output is
a uint8 tensor shaped [s0, s1, ..., s_n / 8].
Args
input
A Tensor. Must be one of the following types: bool, half, float32, float64, int8, int16, int32, int64.
Values to compare against threshold and bitpack.
threshold
A Tensor. Must have the same type as input.
Threshold to compare against.
[null,null,["Last updated 2021-05-14 UTC."],[],[],null,["# tf.raw_ops.CompareAndBitpack\n\n\u003cbr /\u003e\n\nCompare values of `input` to `threshold` and pack resulting bits into a `uint8`.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.raw_ops.CompareAndBitpack`](https://www.tensorflow.org/api_docs/python/tf/raw_ops/CompareAndBitpack)\n\n\u003cbr /\u003e\n\n tf.raw_ops.CompareAndBitpack(\n input, threshold, name=None\n )\n\nEach comparison returns a boolean `true` (if `input_value \u003e threshold`)\nor and `false` otherwise.\n\nThis operation is useful for Locality-Sensitive-Hashing (LSH) and other\nalgorithms that use hashing approximations of cosine and `L2` distances;\ncodes can be generated from an input via: \n\n codebook_size = 50\n codebook_bits = codebook_size * 32\n codebook = tf.get_variable('codebook', [x.shape[-1].value, codebook_bits],\n dtype=x.dtype,\n initializer=tf.orthogonal_initializer())\n codes = compare_and_threshold(tf.matmul(x, codebook), threshold=0.)\n codes = tf.bitcast(codes, tf.int32) # go from uint8 to int32\n # now codes has shape x.shape[:-1] + [codebook_size]\n\n| **Note:** Currently, the innermost dimension of the tensor must be divisible by 8.\n\nGiven an `input` shaped `[s0, s1, ..., s_n]`, the output is\na `uint8` tensor shaped `[s0, s1, ..., s_n / 8]`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input` | A `Tensor`. Must be one of the following types: `bool`, `half`, `float32`, `float64`, `int8`, `int16`, `int32`, `int64`. Values to compare against `threshold` and bitpack. |\n| `threshold` | A `Tensor`. Must have the same type as `input`. Threshold to compare against. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor` of type `uint8`. ||\n\n\u003cbr /\u003e"]]