Let t
be a Tensorflow tensor of shape (m, n)
. Let F
be a list of p
functions f_1, f_2, ...
where each function of these takes a tensor and outputs a tensor of the same shape.
I need to compute the tensor T
of shape (p, m, n)
such that T[i]=f_i(t)
.
Notice that this is the inverse setup of the map function where we apply 1 function to a collection of element. Here, we need to apply a collection of functions to 1 element. Additionally, we need to do that in parallel .
The naive approach (non-parallel) would be stacking results of these computations generated via a for loop (or a list comprehension).
T = tf.stack([
f(t) for f in F
])
Tensorflow version: 2.0.0a. Mode: eager
假设r1.13
不急于执行tf.parallel_stack
应该做的伎俩。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.