我正在尝试利用SubpixelConv2D 函数
我正在训练一个 GAN,并且想使用子像素而不是插值或卷积转置来上采样,因为它们留下了伪影。
我正在使用 Tensorflow/1.4.0 和 Keras/2.2.4
当我尝试调用该函数时,我收到以下错误:
“ValueError:不支持任何值。”
我使用以下方法调用该函数:
import tensorflow as tf
from tensorflow import keras
import Utils
def up_sampling_block(model):
#model = keras.layers.Conv2DTranspose(filters = filters, kernel_size = kernal_size, strides = strides, padding = "same")(model)
model = Utils.SubpixelConv2D(model)(model)
#model = keras.layers.UpSampling2D(size = 2)(model)
#model = keras.layers.Conv2D(filters = filters, kernel_size = kernal_size, strides = strides, padding = "same")(model)
#model = keras.layers.LeakyReLU(alpha = 0.2)(model)
return model
功能如下:
# Subpixel Conv will upsample from (h, w, c) to (h/r, w/r, c/r^2)
def SubpixelConv2D(input_shape, scale=4):
def subpixel_shape(input_shape, scale):
dims = [input_shape[0], input_shape[1] * scale, input_shape[2] * scale, int(input_shape[3] / (scale ** 2))]
output_shape = tuple(dims)
return output_shape
def subpixel(x):
return tf.depth_to_space(x, scale)
return keras.layers.Lambda(subpixel, subpixel_shape)
输入张量的大小是(?,48,48,64),我相信“?” 因为批量大小导致错误,但我似乎无法解决问题。