【发布时间】:2021-09-23 02:56:55
【问题描述】:
class SmallerVGGNet:
@staticmethod
def build(width, height, depth, classes, finalAct="softmax"):
# initialize the model along with the input shape to be
# "channels last" and the channels dimension itself
model = Sequential()
inputShape = (height, width, depth)
chanDim = -1
units = 1
if K.image_data_format() == "channels_first":
inputShape = (depth, height, width)
chanDim = 1
# CONV => RELU => POOL
model.add(Conv2D(16, (3, 3), padding="same", input_shape=inputShape,))
model.add(BatchNormalization(axis=chanDim))
model.add(Activation("relu"))
model.add(
LSTM(128, activation='tanh', return_sequences=True, use_bias=True, kernel_initializer="glorot_uniform"))
# softmax classifier
model.add(Flatten())
model.add(Dropout(0.5))
print(model.summary())
return model
如何解决这个错误? str(x.shape.as_list())) ValueError: 层 lstm 的输入 0 与层不兼容:预期 ndim=3,发现 ndim=4。收到的完整形状:[None, 16, 16, 128]
【问题讨论】:
标签: tensorflow keras conv-neural-network lstm recurrent-neural-network