Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 卷积双线性插值_Python_Numpy_Tensorflow_Convolution_Bilinear Interpolation - Fatal编程技术网

Python 卷积双线性插值

Python 卷积双线性插值,python,numpy,tensorflow,convolution,bilinear-interpolation,Python,Numpy,Tensorflow,Convolution,Bilinear Interpolation,我尝试通过转置卷积进行上采样。由于我无法计算内核权重,我尝试了以下方法 按因子增加图像采样(使用最近邻法) 滑动一个2x2过滤器,其上有0.25个值。 这将产生除最后一列和第二行以外的所有值。 以下代码仅在输入和输出过滤器为单位大小时才能正常工作 from tensorflow.keras import layers import numpy as np nof = 9 # The input data (could be an image). temp = tf.constant([i fo

我尝试通过转置卷积进行上采样。由于我无法计算内核权重,我尝试了以下方法

按因子增加图像采样(使用最近邻法) 滑动一个2x2过滤器,其上有0.25个值。 这将产生除最后一列和第二行以外的所有值。 以下代码仅在输入和输出过滤器为单位大小时才能正常工作

from tensorflow.keras import layers
import numpy as np

nof = 9
# The input data (could be an image).
temp = tf.constant([i for i in range(2*2*nof)], tf.float64)
temp2 = tf.reshape(temp, [1, 2, 2,nof])

# A filter (affects the convolution).
filter = tf.constant([0.25 for i in range(2*2*nof*nof)], tf.float64)
filter2 = tf.reshape(filter, [2, 2, nof, nof])


img = layers.UpSampling2D(2)(temp2)
print(img.shape)


# Use convolution layer on 4D matrices.
#convolution = tf.nn.conv2d(img, filter2, [1, 1, 1, 1], padding="SAME")
convolution1 = tf.nn.conv2d(img, filter2, [1, 1, 1, 1], padding="VALID")
# Initialize session.
session = tf.Session()
tf.global_variables_initializer()


print("FILTER")
print([i for i in np.ravel(session.run(filter2))])
print('\n')


print(session.run(temp2),'\n')
image = session.run(img)
print(image)

print("CONVOLUTION")
c1 = session.run(convolution1)
print(c1)




问题是什么?只有当输入过滤器和输出过滤器的数量为1时,上述代码才能正常工作。有什么建议吗?