-1
   model.add(layers.MaxPooling1D(pool_size=3))
        ^
SyntaxError: invalid syntax

我得到了这个错误。问题是什么?我已经搜索过了,但几乎在所有地方都发现了相同的语法

这是我的整个模型。模型中是否还有其他问题?我正在对音素进行语音识别

import tensorflow as tf 
from keras import layers
from keras import models

model = models.Sequential()

#First Conv1D layer
model.add(layers.Conv1D(8,13, input_shape=(-1,8000,1), activation='relu',padding='valid', strides=1))
model.add(layers.MaxPooling1D(pool_size=3))
model.add(layers.Dropout(0.3))

model.add(layers.BatchNormalization(axis=-1, momentum=0.99, epsilon=1e-3, center=True, scale=True)(inputs))
#Second Conv1D layer

model.add(layers.Conv1D(16, 11,activation='relu', padding='valid', strides=1)
model.add(layers.MaxPooling1D(pool_size=3))
model.add(layers.Dropout(0.3))

#Third Conv1D layer
model.add(layers.Conv1D(32, 9, activation='relu',padding='valid', strides=1)
model.add(layers.MaxPooling1D(pool_size=3))
model.add(layers.Dropout(0.3))

model.add(layers.BatchNormalization(axis=-1, momentum=0.99, epsilon=1e-3, center=True, scale=True))

model.add(layers.Bidirectional(GRU(128, return_sequences=True), merge_mode='sum'))
model.add(layers.Bidirectional(GRU(128, return_sequences=True), merge_mode='sum'))
model.add(layers.Bidirectional(LSTM(128, return_sequences=False), merge_mode='sum'))

model.add(layers.BatchNormalization(axis=-1, momentum=0.99, epsilon=1e-3, center=True, scale=True))

#Flatten layer
model.add(layers.Flatten())

#Dense Layer 1
model.add(layers.Dense(256, activation='relu'))
model.add(layers.Dense(len(labels), activation="softmax"))

model.summary()
4

1 回答 1

1

在这条线上

#Second Conv1D layer

model.add(layers.Conv1D(16, 11,activation='relu', padding='valid', strides=1)

你忘了关闭括号。

改成这个

model.add(layers.Conv1D(16, 11,activation='relu', padding='valid', strides=1))

以下行出现相同的错误

#Third Conv1D layer
model.add(layers.Conv1D(32, 9, activation='relu',padding='valid', strides=1)

要修复它,只需添加最后一个括号

#Third Conv1D layer
model.add(layers.Conv1D(32, 9, activation='relu',padding='valid', strides=1))
于 2020-08-11T16:15:10.210 回答