我正在尝试利用SubpixelConv2D function
我正在训练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),我相信“?”因为批次大小导致了错误,但我似乎无法解决问题。
答案 0 :(得分:0)
Lambda层的第二个功能必须仅是输入形状的功能:subpixel_shape(input_shape)
,但是您使用了第二个名为scale的参数,当仅传递input_shape时默认为undefined。尝试改为将lambda input_shape: subpixel_shape(input_shape, scale)
传递给keras.layers.Lambda
函数。然后小数位数将默认为4,具体取决于外部函数的指示。或从scale
函数参数中删除subpixel_shape
:
def outer(a=0):
def inner():
print(a)
return inner
print(outer()()) # prints 0