จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เทนเซอร์โฟลว์:: ปฏิบัติการ:: บิตคาสต์
#include <array_ops.h>
Bitcasts เทนเซอร์จากประเภทหนึ่งไปยังอีกประเภทหนึ่งโดยไม่ต้องคัดลอกข้อมูล
สรุป
เมื่อได้รับ input
เทนเซอร์ การดำเนินการนี้จะส่งคืนเทนเซอร์ที่มีข้อมูลบัฟเฟอร์เหมือนกับ input
type
ข้อมูล
หากประเภทข้อมูลอินพุต T
มีขนาดใหญ่กว่า type
ข้อมูลเอาต์พุต รูปร่างจะเปลี่ยนจาก [...] เป็น [..., sizeof( T
)/sizeof( type
)]
หาก T
มีขนาดเล็กกว่า type
ตัวดำเนินการต้องการให้มิติด้านขวาสุดเท่ากับ sizeof( type
)/sizeof( T
) รูปร่างจะเปลี่ยนจาก [..., sizeof( type
)/sizeof( T
)] เป็น [...]
tf.bitcast() และ tf.cast() ทำงานแตกต่างกันเมื่อ dtype จริงถูกร่ายเป็น dtype ที่ซับซ้อน (เช่น tf.complex64 หรือ tf.complex128) เนื่องจาก tf.cast() สร้างส่วนจินตภาพ 0 ในขณะที่ tf.bitcast() ให้โมดูล ข้อผิดพลาด. ตัวอย่างเช่น,
ตัวอย่างที่ 1:
>>> a = [1., 2., 3.]
>>> equality_bitcast = tf.bitcast(a,tf.complex128)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot bitcast from float to complex128: shape [3] [Op:Bitcast]
>>> equality_cast = tf.cast(a,tf.complex128)
>>> print(equality_cast)
tf.Tensor([1.+0.j 2.+0.j 3.+0.j], shape=(3,), dtype=complex128)
ตัวอย่างที่ 2:
>>> tf.bitcast(tf.constant(0xffffffff, dtype=tf.uint32), tf.uint8)
<tf.Tensor: ... shape=(4,), dtype=uint8, numpy=array([255, 255, 255, 255], dtype=uint8)>
ตัวอย่างที่ 3:
>>> x = [1., 2., 3.]
>>> y = [0., 2., 3.]
>>> equality= tf.equal(x,y)
>>> equality_cast = tf.cast(equality,tf.float32)
>>> equality_bitcast = tf.bitcast(equality_cast,tf.uint8)
>>> print(equality)
tf.Tensor([False True True], shape=(3,), dtype=bool)
>>> print(equality_cast)
tf.Tensor([0. 1. 1.], shape=(3,), dtype=float32)
>>> print(equality_bitcast)
tf.Tensor(
[[ 0 0 0 0]
[ 0 0 128 63]
[ 0 0 128 63]], shape=(3, 4), dtype=uint8)
หมายเหตุ : Bitcast ถูกนำมาใช้เป็นการแคสต์ระดับต่ำ ดังนั้นเครื่องที่มีลำดับ endian ต่างกันจะให้ผลลัพธ์ที่แตกต่างกัน
ข้อโต้แย้ง:
ผลตอบแทน:
คุณลักษณะสาธารณะ
งานสาธารณะ
โหนด
::tensorflow::Node * node() const
operator::tensorflow::Input() const
ตัวดำเนินการ::tensorflow::เอาต์พุต
operator::tensorflow::Output() const
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 2025-07-25 UTC"],[],[],null,["# tensorflow::ops::Bitcast Class Reference\n\ntensorflow::ops::Bitcast\n========================\n\n`#include \u003carray_ops.h\u003e`\n\nBitcasts a tensor from one type to another without copying data.\n\nSummary\n-------\n\nGiven a tensor `input`, this operation returns a tensor that has the same buffer data as `input` with datatype `type`.\n\nIf the input datatype `T` is larger than the output datatype `type` then the shape changes from \\[...\\] to \\[..., sizeof(`T`)/sizeof(`type`)\\].\n\nIf `T` is smaller than `type`, the operator requires that the rightmost dimension be equal to sizeof(`type`)/sizeof(`T`). The shape then goes from \\[..., sizeof(`type`)/sizeof(`T`)\\] to \\[...\\].\n\ntf.bitcast() and tf.cast() work differently when real dtype is casted as a complex dtype (e.g. tf.complex64 or tf.complex128) as tf.cast() make imaginary part 0 while tf.bitcast() gives module error. For example,\n\nExample 1: \n\n```carbon\n\u003e\u003e\u003e a = [1., 2., 3.]\n\u003e\u003e\u003e equality_bitcast = tf.bitcast(a,tf.complex128)\ntensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot bitcast from float to complex128: shape [3] [Op:Bitcast]\n\u003e\u003e\u003e equality_cast = tf.cast(a,tf.complex128)\n\u003e\u003e\u003e print(equality_cast)\ntf.Tensor([1.+0.j 2.+0.j 3.+0.j], shape=(3,), dtype=complex128)\n```\nExample 2: \n\n```gdscript\n\u003e\u003e\u003e tf.bitcast(tf.constant(0xffffffff, dtype=tf.uint32), tf.uint8)\n\u003ctf.Tensor: ... shape=(4,), dtype=uint8, numpy=array([255, 255, 255, 255], dtype=uint8)\u003e\n```\nExample 3: \n\n```carbon\n\u003e\u003e\u003e x = [1., 2., 3.]\n\u003e\u003e\u003e y = [0., 2., 3.]\n\u003e\u003e\u003e equality= tf.equal(x,y)\n\u003e\u003e\u003e equality_cast = tf.cast(equality,tf.float32)\n\u003e\u003e\u003e equality_bitcast = tf.bitcast(equality_cast,tf.uint8)\n\u003e\u003e\u003e print(equality)\ntf.Tensor([False True True], shape=(3,), dtype=bool)\n\u003e\u003e\u003e print(equality_cast)\ntf.Tensor([0. 1. 1.], shape=(3,), dtype=float32)\n\u003e\u003e\u003e print(equality_bitcast)\ntf.Tensor(\n[[ 0 0 0 0]\n [ 0 0 128 63]\n [ 0 0 128 63]], shape=(3, 4), dtype=uint8)\n```\n\n\u003cbr /\u003e\n\n*NOTE* : [Bitcast](/versions/r2.0/api_docs/cc/class/tensorflow/ops/bitcast#classtensorflow_1_1ops_1_1_bitcast) is implemented as a low-level cast, so machines with different endian orderings will give different results.\n\nArguments:\n\n- scope: A [Scope](/versions/r2.0/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n\n\u003cbr /\u003e\n\nReturns:\n\n- [Output](/versions/r2.0/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output): The output tensor.\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| [Bitcast](#classtensorflow_1_1ops_1_1_bitcast_1a05bc5afdb6742a02847bb3a8d621b149)`(const ::`[tensorflow::Scope](/versions/r2.0/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.0/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, DataType type)` ||\n\n| ### Public attributes ||\n|-------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|\n| [operation](#classtensorflow_1_1ops_1_1_bitcast_1a73096d45a2f9d4344e1129af8152435c) | [Operation](/versions/r2.0/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_bitcast_1a4b3a50f16d6247d11bfe2d42f5a438fd) | `::`[tensorflow::Output](/versions/r2.0/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n\n| ### Public functions ||\n|-------------------------------------------------------------------------------------------------------------------|------------------------|\n| [node](#classtensorflow_1_1ops_1_1_bitcast_1a999d383445adeaf4c5306b84acc32444)`() const ` | `::tensorflow::Node *` |\n| [operator::tensorflow::Input](#classtensorflow_1_1ops_1_1_bitcast_1a26b9e16d876ed44fa37352c733696aec)`() const ` | ` ` ` ` |\n| [operator::tensorflow::Output](#classtensorflow_1_1ops_1_1_bitcast_1ad3b38ccb536d06b4ce4f2f48af30b1f5)`() 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### Bitcast\n\n```gdscript\n Bitcast(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input input,\n DataType type\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```"]]