在conv2d中,keras无法推断输出形状

时间:2019-07-20 17:00:27

标签: tensorflow machine-learning keras

我尝试过使用功能性API和python样式的方式来构建模型。 我发现,由于设置了拨号比例,因此其output_shape将变为None,None ... 我将向您展示我的代码。

如果您检查conv1,就可以了 从conv2开始,output_shape开始变为(16,None,1)


from tensorflow.python.keras.layers import *
from tensorflow.python.keras import *
import tensorflow as tf

inputlayer = InputLayer(input_shape=(256,1),batch_size=16)

conv1 = Conv1D(1, kernel_size=3, strides=1, padding='same', dilation_rate=1, activation='relu')

conv2 = Conv1D(1, kernel_size=3, strides=1, padding='same', dilation_rate=2, activation='relu')

conv3 = Conv1D(1, kernel_size=3, strides=1, padding='same', dilation_rate=4, activation='relu')

conv4 = Conv1D(1, kernel_size=3, strides=1, padding='same', dilation_rate=8, activation='relu')

conv5 = Conv1D(1, kernel_size=3, strides=1, padding='same', dilation_rate=16, activation='relu')

flatten = Flatten()

dense1 = Dense(1024)

bn1 = BatchNormalization()

act1 = Activation('sigmoid')

dense2 = Dense(1024)

bn2 = BatchNormalization()

act2 = Activation('sigmoid')

y = Dense(1)

model = Sequential()
model.add(inputlayer)
model.add(conv1)
model.add(conv2)
model.add(conv3)
model.add(conv4)
model.add(conv5)
model.add(flatten)
model.add(dense1)
model.add(bn1)
model.add(act1)
model.add(dense2)
model.add(bn2)
model.add(act2)
model.add(y)

model.compile(optimizer='adam', loss='mse')

print(model.summary())
raise ValueError('The last dimension of the inputs to `Dense` '
ValueError: The last dimension of the inputs to `Dense` should be defined. Found `None`.

我希望它可以得到正确的形状,然后我可以运行model.compile() 但是keras让我想起density1出错了。

0 个答案:

没有答案