使用此链接进行双线性插值 http://cv-tricks.com/image-segmentation/transpose-convolution-in-tensorflow/
我正在尝试使用虚拟矩阵来获取一些结果,即在我的代码中将维度4的filter_shape命名为张量。但这给了我一个错误。谁能帮我举一个虚拟的例子来运行此双线性插值代码?
import tensorflow as tf
import numpy as np
#tensor=np.zeros((2,2,3,3))
tensor=np.random.random((2,2,3,3))
print(tensor)
def get_bilinear_filter(filter_shape, upscale_factor):
##filter_shape is [width, height, num_in_channels, num_out_channels]
kernel_size = filter_shape[1]
### Centre location of the filter for which value is calculated
if kernel_size % 2 == 1:
centre_location = upscale_factor - 1
else:
centre_location = upscale_factor - 0.5
bilinear = np.zeros([filter_shape[0], filter_shape[1]])
for x in range(filter_shape[0]):
for y in range(filter_shape[1]):
##Interpolation Calculation
value = (1 - abs((x - centre_location)/ upscale_factor)) * (1 - abs((y - centre_location)/ upscale_factor))
bilinear[x, y] = value
weights = np.zeros(filter_shape)
print(weights)
for i in range(filter_shape[2]):
weights[:, :, i, i] = bilinear
init = tf.constant_initializer(value=weights,
dtype=tf.float32)
bilinear_weights = tf.get_variable(name="decon_bilinear_filter", initializer=init,
shape=weights.shape)
print(bilinear_weights)
get_bilinear_filter(tensor,3)