จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เทนเซอร์โฟลว์:: ปฏิบัติการ:: เปรียบเทียบและ Bitpack
#include <math_ops.h>
เปรียบเทียบค่าของ input
กับ threshold
และแพ็คบิตผลลัพธ์ลงใน uint8
สรุป
การเปรียบเทียบแต่ละครั้งจะส่งคืนบูลีน 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]
ข้อโต้แย้ง:
- ขอบเขต: วัตถุ ขอบเขต
- อินพุต: ค่าที่จะเปรียบเทียบกับ
threshold
และบิตแพ็ก - เกณฑ์: เกณฑ์ที่จะเปรียบเทียบ
ผลตอบแทน:
-
Output
: การเปรียบเทียบแบบบิตแพ็ก
คุณลักษณะสาธารณะ
งานสาธารณะ
โหนด
::tensorflow::Node * node() const
operator::tensorflow::Input() const
ตัวดำเนินการ::tensorflow::เอาต์พุต
operator::tensorflow::Output() const
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[],[],null,["# tensorflow::ops::CompareAndBitpack Class Reference\n\ntensorflow::ops::CompareAndBitpack\n==================================\n\n`#include \u003cmath_ops.h\u003e`\n\nCompare values of `input` to `threshold` and pack resulting bits into a `uint8`.\n\nSummary\n-------\n\nEach comparison returns a boolean `true` (if `input_value \u003e threshold`) or and `false` otherwise.\n\nThis 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:\n\n\n```transact-sql\ncodebook_size = 50\ncodebook_bits = codebook_size * 32\ncodebook = tf.get_variable('codebook', [x.shape[-1].value, codebook_bits],\n dtype=x.dtype,\n initializer=tf.orthogonal_initializer())\ncodes = compare_and_threshold(tf.matmul(x, codebook), threshold=0.)\ncodes = tf.bitcast(codes, tf.int32) # go from uint8 to int32\n# now codes has shape x.shape[:-1] + [codebook_size]\n```\n\n\u003cbr /\u003e\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 a `uint8` tensor shaped `[s0, s1, ..., s_n / 8]`.\n\nArguments:\n\n- scope: A [Scope](/versions/r2.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n- input: Values to compare against `threshold` and bitpack.\n- threshold: Threshold to compare against.\n\n\u003cbr /\u003e\n\nReturns:\n\n- [Output](/versions/r2.3/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output): The bitpacked comparisons.\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| [CompareAndBitpack](#classtensorflow_1_1ops_1_1_compare_and_bitpack_1aa00f05feb63c6001dbeb274f30d67977)`(const ::`[tensorflow::Scope](/versions/r2.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, ::`[tensorflow::Input](/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` threshold)` ||\n\n| ### Public attributes ||\n|-------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|\n| [operation](#classtensorflow_1_1ops_1_1_compare_and_bitpack_1a844ac2bc7be66b00b7165a65b4fd7b5c) | [Operation](/versions/r2.3/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_compare_and_bitpack_1a52739fa1033fe1e93ee013270d8adb3c) | `::`[tensorflow::Output](/versions/r2.3/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n\n| ### Public functions ||\n|-------------------------------------------------------------------------------------------------------------------------------|------------------------|\n| [node](#classtensorflow_1_1ops_1_1_compare_and_bitpack_1af6f8f9c40e4b60d75a6a6eb9d0c39ae8)`() const ` | `::tensorflow::Node *` |\n| [operator::tensorflow::Input](#classtensorflow_1_1ops_1_1_compare_and_bitpack_1a107c8a31460e12f5d2c4892c9e3c6c1e)`() const ` | ` ` ` ` |\n| [operator::tensorflow::Output](#classtensorflow_1_1ops_1_1_compare_and_bitpack_1ade9a5b902ca0f3af8969b0157da966de)`() const ` | ` ` ` ` |\n\nPublic attributes\n-----------------\n\n### operation\n\n```text\nOperation operation\n``` \n\n### output\n\n```text\n::tensorflow::Output output\n``` \n\nPublic functions\n----------------\n\n### CompareAndBitpack\n\n```gdscript\n CompareAndBitpack(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input input,\n ::tensorflow::Input threshold\n)\n``` \n\n### node\n\n```gdscript\n::tensorflow::Node * node() const \n``` \n\n### operator::tensorflow::Input\n\n```gdscript\n operator::tensorflow::Input() const \n``` \n\n### operator::tensorflow::Output\n\n```gdscript\n operator::tensorflow::Output() const \n```"]]