เทนเซอร์โฟลว์:: ปฏิบัติการ:: DynamicStitch
#include <data_flow_ops.h>
แทรกค่าจากเทนเซอร์ data
ลงในเทนเซอร์ตัวเดียว
สรุป
สร้างเทนเซอร์ที่ผสานเช่นนั้น
merged[indices[m][i, ..., j], ...] = data[m][i, ..., j, ...]
ตัวอย่างเช่น ถ้าแต่ละ indices[m]
เป็นสเกลาร์หรือเวกเตอร์ เราก็จะได้
# Scalar indices:
merged[indices[m], ...] = data[m][...]
# Vector indices:
merged[indices[m][i], ...] = data[m][i, ...]
แต่ละ data[i].shape
ต้องเริ่มต้นด้วย indices[i].shape
และส่วนที่เหลือของ data[i].shape
จะต้องคงที่ wrt i
นั่นคือเราต้องมี data[i].shape = indices[i].shape + constant
ในแง่ของ constant
ที่ รูปร่างผลลัพธ์คือ
merged.shape = [max(indices)] + constant
ค่าจะถูกผสานตามลำดับ ดังนั้นหากดัชนีปรากฏในทั้ง indices[m][i]
และ indices[n][j]
สำหรับ (m,i) < (n,j)
data[n][j]
จะ ปรากฏในผลลัพธ์ที่รวมเข้าด้วยกัน หากคุณไม่ต้องการการรับประกันนี้ ParallelDynamicStitch อาจทำงานได้ดีกว่าในอุปกรณ์บางชนิด
ตัวอย่างเช่น:
indices[0] = 6
indices[1] = [4, 1]
indices[2] = [[5, 2], [0, 3]]
data[0] = [61, 62]
data[1] = [[41, 42], [11, 12]]
data[2] = [[[51, 52], [21, 22]], [[1, 2], [31, 32]]]
merged = [[1, 2], [11, 12], [21, 22], [31, 32], [41, 42],
[51, 52], [61, 62]]
วิธีการนี้สามารถใช้เพื่อผสานพาร์ติชันที่สร้างโดย dynamic_partition
ดังที่แสดงในตัวอย่างต่อไปนี้:
# Apply function (increments x_i) on elements for which a certain condition
# apply (x_i != -1 in this example).
x=tf.constant([0.1, -1., 5.2, 4.3, -1., 7.4])
condition_mask=tf.not_equal(x,tf.constant(-1.))
partitioned_data = tf.dynamic_partition(
x, tf.cast(condition_mask, tf.int32) , 2)
partitioned_data[1] = partitioned_data[1] + 1.0
condition_indices = tf.dynamic_partition(
tf.range(tf.shape(x)[0]), tf.cast(condition_mask, tf.int32) , 2)
x = tf.dynamic_stitch(condition_indices, partitioned_data)
# Here x=[1.1, -1., 6.2, 5.3, -1, 8.4], the -1. values remain
# unchanged.

ข้อโต้แย้ง:
- ขอบเขต: วัตถุ ขอบเขต
ผลตอบแทน:
-
Output
: เทนเซอร์ที่ผสาน
ตัวสร้างและผู้ทำลาย | |
---|---|
DynamicStitch (const :: tensorflow::Scope & scope, :: tensorflow::InputList indices, :: tensorflow::InputList data) |
งานสาธารณะ | |
---|---|
node () const | ::tensorflow::Node * |
operator::tensorflow::Input () const | |
operator::tensorflow::Output () const |
คุณลักษณะสาธารณะ
ผสาน
::tensorflow::Output merged
การดำเนินการ
Operation operation
งานสาธารณะ
DynamicStitch
DynamicStitch(
const ::tensorflow::Scope & scope,
::tensorflow::InputList indices,
::tensorflow::InputList data
)
โหนด
::tensorflow::Node * node() const
ตัวดำเนินการ::tensorflow::อินพุต
operator::tensorflow::Input() const
ตัวดำเนินการ::tensorflow::เอาต์พุต
operator::tensorflow::Output() const