问题描述
我想在张量流中使用fft2d变换,然后用卷积层分析幅度和相位结果...我制作了一个具有Lambda层的系统,以使用张量流函数并获取幅度和相位.但是,当我添加Conv2d图层时,出现错误
I want to use fft2d transform in tensorflow and then analyse the magnitude and phase result with convolutional layers... I have made a system with Lambda layers to use tensorflow functions and get the magnitude and the phase. But when I add the Conv2d layer, I get the error
输入深度(3)不是输入形状为[?,199,199,3],[[_,199,199,3]的'1_Magn_Conv_f500_k2_2/convolution'(op:'Conv2D')的过滤器(199)输入深度的倍数.2,2,199,500]
我不知道什么是形状[2,2,199,500]
,是什么导致此错误.
I don't understand what is the shape [2,2,199,500]
and what is causing this error.
我试图减少网络中的层数,以检测是哪个层造成了问题.我已经检查过magn_angle输出两个具有形状[None,199,199,3]
的张量.我正在与Google colab合作.
I have tried to reduce the number of layers in my networks to detect which one creates the problem. I have checked that magn_angle outputs two tensors with shapes [None,199,199,3]
.I am working with google colab.
这是重现该错误的最少代码
Here is the minimal code to reproduce the error
inpt = Input(shape = (199, 199, 3),name=str(0)+'_'+'Image')
def magn_angle(x):
x = Lambda(lambda x:K.cast(x,dtype=tf.complex64))(x)
x_list_magn = []
x_list_angle = []
for i in range(3):
fft = Lambda(lambda x: tf.fft2d(x[:,:,:,i]), output_shape=(None,199,199))(x)# 2-dimensional discrete Fourier transform over the inner-most 2 dimensions
x_list_magn.append(Lambda(lambda fft:K.expand_dims(tf.math.abs(fft),axis=-1), output_shape=(None,199,199))(fft))
x_list_angle.append(Lambda(lambda fft: K.expand_dims(tf.math.angle(fft),axis=-1), output_shape=(None,199,199))(fft))
magn = Concatenate()(x_list_magn)
angle = Concatenate()(x_list_angle)
magn = Lambda(lambda magn: K.cast(magn,dtype=tf.float32), output_shape=(None,199,199))(magn)
angle = Lambda(lambda angle: K.cast(angle,dtype=tf.float32), output_shape=(None,199,199))(angle)
return magn,angle
magn, angle = magn_angle(inpt)
magn = Conv2D(filters=500,kernel_size=(2,2),activation=None,strides=(1,1),padding='SAME',name=str(1)+'_'+'Magn_Conv_f500_k2',data_format="channels_last")(magn)
...
哪些产出
InvalidArgumentError:输入深度(3)不是输入形状为[[,, 199,199,3]的'1_Magn_Conv_f500_k2_3/convolution'(op:'Conv2D')的过滤器(199)输入深度的倍数.,[2,2,199,500]
.
推荐答案
更改 keras....
导入到 tensorflow.keras....
解决了这个问题.
Changing keras. ...
imports to tensorflow.keras. ...
has solved the problem.
这篇关于卷积2D“输入深度不是滤波器的输入深度的倍数".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!