เทนเซอร์โฟลว์:: ปฏิบัติการ:: บิตคาสต์

#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() ทำงานแตกต่างออกไปเมื่อ real dtype ถูกร่ายเป็น dtype ที่ซับซ้อน (เช่น tf.complex64 หรือ tf.complex128) เนื่องจาก tf.cast() สร้างจินตภาพส่วนที่ 0 ในขณะที่ tf.bitcast() ให้โมดูล ข้อผิดพลาด. ตัวอย่างเช่น,

ตัวอย่างที่ 1:

a = [1., 2., 3.] equality_bitcast = tf.bitcast(a, tf.complex128) Traceback (การโทรล่าสุดครั้งล่าสุด): ... InvalidArgumentError: ไม่สามารถบิตคาสต์ได้ตั้งแต่ 1 ถึง 18 [Op: Bitcast ] equality_cast = tf.cast (a, tf.complex128) พิมพ์ (equality_cast) tf.Tensor ([1.+0.j 2.+0.j 3.+0.j], รูปร่าง = (3,), dtype = complex128)

ตัวอย่างที่ 2:

tf.bitcast(tf.constant(0xffffffff, dtype=tf.uint32), tf.uint8)

ตัวอย่างที่ 3:

x = [1., 2., 3.] y = [0., 2., 3.] ความเท่าเทียมกัน= tf.equal(x,y) ความเท่าเทียมกัน_cast = tf.cast(ความเท่าเทียมกัน,tf.float32) ความเท่าเทียมกัน_bitcast = tf bitcast (equality_cast, tf.uint8) พิมพ์ (ความเท่าเทียมกัน) tf.Tensor ([False True True], รูปร่าง = (3,), dtype = bool) พิมพ์ (equality_cast) tf.Tensor ([0. 1. 1.], รูปร่าง = (3,), dtype = float32) พิมพ์ (equality_bitcast) tf.Tensor ( [[ 0 0 0 0] [ 0 0 128 63] [ 0 0 128 63]], รูปร่าง = (3, 4), dtype= uint8)

หมายเหตุ : Bitcast ถูกนำมาใช้เป็นการแคสต์ระดับต่ำ ดังนั้นเครื่องที่มีลำดับ endian ต่างกันจะให้ผลลัพธ์ที่แตกต่างกัน

ข้อโต้แย้ง:

ผลตอบแทน:

  • Output : เทนเซอร์เอาท์พุต

ตัวสร้างและผู้ทำลาย

Bitcast (const :: tensorflow::Scope & scope, :: tensorflow::Input input, DataType type)

คุณลักษณะสาธารณะ

operation
output

งานสาธารณะ

node () const
::tensorflow::Node *
operator::tensorflow::Input () const
operator::tensorflow::Output () const

คุณลักษณะสาธารณะ

การดำเนินการ

Operation operation

เอาท์พุท

::tensorflow::Output output

งานสาธารณะ

บิตคาสต์

 Bitcast(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input input,
  DataType type
)

โหนด

::tensorflow::Node * node() const 

ตัวดำเนินการ::tensorflow::อินพุต

 operator::tensorflow::Input() const 

ตัวดำเนินการ::tensorflow::เอาต์พุต

 operator::tensorflow::Output() const