进入动态形状时,tf.keras.layers.Conv3DTranspose引发TypeError

时间:2019-04-16 12:00:26

标签: python tensorflow keras

这是我的代码:

input_img = keras.layers.Input( shape=( None, len(params2), len(params2), 1 ) ) # adapt this if using `channels_first` image data format

conv1 = keras.layers.Conv3D(filters=32, kernel_size=(1, 3, 3), strides=(1, 1, 1), activation='selu', padding='same', data_format='channels_last', name='conv1')(input_img)
conv2 = keras.layers.Conv3D(filters=64, kernel_size=(1, 3, 3), strides=(1, 2, 2), activation='selu', padding='same', data_format='channels_last', name='conv2')(conv1)
conv3 = keras.layers.Conv3D(filters=128,kernel_size=(1, 3, 3), strides=(1, 2, 2), activation='selu', padding='same', data_format='channels_last', name='conv3')(conv2)
conv4 = keras.layers.Conv3D(filters=256,kernel_size=(1, 3, 3), strides=(1, 2, 2), activation='selu', padding='same', data_format='channels_last', name='conv4')(conv3)

convlstm1 = keras.layers.ConvLSTM2D(filters=32, return_sequences=True, kernel_size=(3, 3), strides=(1, 1), activation='selu', padding='same', data_format='channels_last', name='convlstm1')(conv1)
convlstm2 = keras.layers.ConvLSTM2D(filters=64, return_sequences=True, kernel_size=(3, 3), strides=(1, 1), activation='selu', padding='same', data_format='channels_last', name='convlstm2')(conv2)
convlstm3 = keras.layers.ConvLSTM2D(filters=128,return_sequences=True, kernel_size=(3, 3), strides=(1, 1), activation='selu', padding='same', data_format='channels_last', name='convlstm3')(conv3)
convlstm4 = keras.layers.ConvLSTM2D(filters=256,return_sequences=True, kernel_size=(3, 3), strides=(1, 1), activation='selu', padding='same', data_format='channels_last', name='convlstm4')(conv4)

deconv4 = keras.layers.Conv3DTranspose(filters=128, kernel_size=(1, 2, 2), strides=(1, 2, 2), activation='selu', padding='valid', output_padding=(0, -1, -1), data_format='channels_last', name='deconv4')(convlstm4)
concat4 = keras.layers.Concatenate(axis=4, name='concat4')([convlstm3, deconv4])
deconv3 = keras.layers.Conv3DTranspose(filters=64 , kernel_size=(1, 2, 2), strides=(1, 2, 2), activation='selu', padding='valid', output_padding=(0, -1, -1), data_format='channels_last', name='deconv3')(concat4)
concat3 = keras.layers.Concatenate(axis=4, name='concat3')([convlstm2, deconv3])
deconv2 = keras.layers.Conv3DTranspose(filters=32 , kernel_size=(1, 3, 3), strides=(1, 2, 2), activation='selu', padding='same' , data_format='channels_last', name='deconv2')(concat3)
concat2 = keras.layers.Concatenate(axis=4, name='concat2')([convlstm1, deconv2])
deconv1 = keras.layers.Conv3DTranspose(filters=1  , kernel_size=(1, 3, 3), strides=(1, 1, 1), activation='selu', padding='same' , data_format='channels_last', name='deconv1')(concat2)

autoencoder = keras.models.Model(input_img, deconv1)
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')
autoencoder.summary()

没有问题,这应该向我发送框架摘要。但是,这是我收到的错误消息:

TypeError                                 Traceback (most recent call last)
<ipython-input-150-83622ca7a77b> in <module>
     28     return autoencoder
     29 
---> 30 autoencoder1(1700)

<ipython-input-150-83622ca7a77b> in autoencoder1(file_length)
     14     convlstm4 = keras.layers.ConvLSTM2D(filters=256,return_sequences=True, kernel_size=(3, 3), strides=(1, 1), activation='selu', padding='same', data_format='channels_last', name='convlstm4')(conv4)
     15 
---> 16     deconv4 = keras.layers.Conv3DTranspose(filters=128, kernel_size=(1, 2, 2), strides=(1, 2, 2), activation='selu', padding='valid', output_padding=(0, -1, -1), data_format='channels_last', name='deconv4')(convlstm4)
     17     concat4 = keras.layers.Concatenate(axis=4, name='concat4')([convlstm3, deconv4])
     18     deconv3 = keras.layers.Conv3DTranspose(filters=64 , kernel_size=(1, 2, 2), strides=(1, 2, 2), activation='selu', padding='valid', output_padding=(0, -1, -1), data_format='channels_last', name='deconv3')(concat4)

~/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs)
    552             # In graph mode, failure to build the layer's graph
    553             # implies a user-side bug. We don't catch exceptions.
--> 554             outputs = self.call(inputs, *args, **kwargs)
    555           else:
    556             try:

~/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/layers/convolutional.py in call(self, inputs)
   1138       else:
   1139         outputs_4d = array_ops.reshape(outputs, [
-> 1140             outputs_shape[0], outputs_shape[1] * outputs_shape[2],
   1141             outputs_shape[3], outputs_shape[4]
   1142         ])

TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

人们说此错误已在2018年解决,但我不确定为什么这里仍然存在错误消息。

0 个答案:

没有答案