np.insert in tensorflow 的替代品



numpy 中有一个函数,可以将给定的值插入数组: https://docs.scipy.org/doc/numpy/reference/generated/numpy.insert.html

张量流中有类似的东西吗?

或者,张量流中是否有一个函数可以使用张量值之间的零进行张量上采样?

tf.nn.conv2d_transpose可以进行这种上采样(通过仔细设计output_shapestrides(。示例代码:

import tensorflow as tf
import numpy as np
input = tf.convert_to_tensor(np.ones((1, 20, 20, 1)))
input = tf.cast(input, tf.float32)
b = np.zeros((3, 3, 1, 1))
b[1, 1, 0, 0] = 1
weight = tf.convert_to_tensor(b)
weight = tf.cast(weight, tf.float32)
output = tf.nn.conv2d_transpose(input, weight, output_shape=(1, 40, 40, 1), strides=[1, 2, 2, 1])
sess = tf.Session()
print sess.run(output[0, :, :, 0])

我相信检查它的 api 会帮助你更多。

最新更新