tensorflow:: عملیات:: بیت‌کست

#include <array_ops.h>

بیت‌کرَست (Bitcast) یک تانسور را از یک نوع به نوع دیگر بدون کپی کردن داده‌ها، تبدیل می‌کند.

خلاصه

با دریافت 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() خطای ماژول می‌دهد. برای مثال،

مثال ۱:

>>> 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)
مثال ۲:
>>> tf.bitcast(tf.constant(0xffffffff, dtype=tf.uint32), tf.uint8)
<tf.Tensor: ... shape=(4,), dtype=uint8, numpy=array([255, 255, 255, 255], dtype=uint8)>
مثال ۳:
>>> 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)

نکته : بیت‌کست به عنوان یک تبدیل سطح پایین پیاده‌سازی شده است، بنابراین ماشین‌هایی با ترتیب‌های مختلف اندیان، نتایج متفاوتی خواهند داشت.

استدلال‌ها:

بازده:

  • 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