tf.raw_ops.CompareAndBitpack
Сравнение значений input с threshold и упаковка результирующих битов в uint8.
tf.raw_ops.CompareAndBitpack(
input, threshold, name=None
)
Каждое сравнение возвращает булевое значение true (если input_value > threshold) или и false в противном случае.
Эта операция полезна для Locality-Sensitive-Hashing (LSH) и других алгоритмов, использующих хеширующие приближения косинусных и L2 расстояний; коды могут быть сгенерированы из входных данных следующим образом:
codebook_size = 50
codebook_bits = codebook_size * 32
codebook = 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]
Примечание: В настоящее время внутреннее измерение тензора должно быть кратно 8.
Учитывая тензор формы input типа [s0, s1, ..., s_n], выходной тензор имеет форму uint8 типа [s0, s1, ..., s_n / 8].
| Аргументы | |
|---|---|
input | A Tensor. Должен быть одним из следующих типов: bool, half, float32, float64, int8, int16, int32, int64. Значения для сравнения с threshold и упаковки битов. |
threshold | A Tensor. Должен иметь тот же тип, что и input. Пороговое значение для сравнения. |
name | Имя операции (необязательно). |
| Возвращаемое значение | |
|---|---|
A Tensor типа uint8. |
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.3/api_docs/python/tf/raw_ops/CompareAndBitpack