tensorflow 是不支持像numpy一样对tensor/array 进行直接赋值的, 并且如果输出[batchsize, img_height, img_width, img_ch]的tensor, 如何对一个batch中的每个图片进行操作也比较麻烦。
解决这个问题主要是靠tensorflow的两个函数。
1、tf.map_fn(fn, elems, dtype)
这个函数有很多博客讲的很好,随便一搜就可以。 但是博客上一般都默认elems只有一个值,比如对视频进行卷积操作。 如果对每个batch中的每个图片进行操作呢?
看API:
"""map on the list of tensors unpacked from `elems` on dimension 0.
The simplest version of `map_fn` repeatedly applies the callable `fn` to a
sequence of elements from first to last. The elements are made of the
tensors unpacked from `elems`. `dtype` is the data type of the return
value of `fn`. Users must provide `dtype` if it is different from
the data type of `elems`.
这里介绍了函数是用来干嘛的。 简单地说就是函数把elements中的元素按照dimension 0展开,然后重复的给fn运行。dtype代表的是fn的返回值类型。
Suppose that `elems` is