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

#include <array_ops.h>

แปลงเทนเซอร์จากประเภทหนึ่งไปเป็นอีกประเภทหนึ่งโดยไม่คัดลอกข้อมูล

สรุป

เมื่อรับ input เป็นเทนเซอร์ การดำเนินการนี้จะส่งคืนเทนเซอร์ที่มีข้อมูลบัฟเฟอร์เดียวกันกับ input โดยมี type ข้อมูลเป็น type

ถ้าชนิดข้อมูลอินพุต T มีขนาดใหญ่กว่า type ข้อมูลเอาต์พุต type รูปแบบจะเปลี่ยนจาก [...] เป็น [..., sizeof( T )/sizeof( type )]

ถ้า T เล็กกว่า type ตัวดำเนินการจะกำหนดให้มิติขวาสุดเท่ากับ sizeof( type )/sizeof( T ) จากนั้นรูปร่างจะเปลี่ยนจาก [..., sizeof( type )/sizeof( T )] เป็น [...]

tf.bitcast() และ tf.cast() ทำงานแตกต่างกันเมื่อแปลงชนิดข้อมูลจริงเป็นชนิดข้อมูลเชิงซ้อน (เช่น 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 ถูกนำไปใช้ในรูปแบบการแปลงประเภทข้อมูลระดับต่ำ ดังนั้นเครื่องที่มีลำดับไบต์ต่างกันจะให้ผลลัพธ์ที่แตกต่างกัน

ข้อโต้แย้ง:

การส่งคืนสินค้า:

  • 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 

ตัวดำเนินการ::เทนเซอร์โฟลว์::อินพุต

 operator::tensorflow::Input() const 

ตัวดำเนินการ::เทนเซอร์โฟลว์::เอาต์พุต

 operator::tensorflow::Output() const