SyntaxError:具有一种热编码的标识符CNN模型中的无效字符

时间:2019-07-16 16:45:32

标签: python deep-learning one-hot-encoding

我现在正迷失方向尝试解决此问题。我尝试在“ relu”和其他格式后添加括号,但由于某种原因,我没有看到/解决此问题。任何帮助将非常感激。我敢肯定这很简单,我很累。

在'reul'之后添加括号

from keras.models import Sequential
from keras.layers import Dense, Conv2D, Flatten
#create model
model = Sequential()
#add model layers
model.add(Conv2D(64, kernel_size=3, activation=’relu’, input_shape=(99,4457,4)))
model.add(Conv2D(32, kernel_size=3, activation=’relu’))
model.add(Flatten())
model.add(Dense(10, activation=’softmax’))

文件“”,第6行     model.add(Conv2D(64,kernel_size = 3,激活='relu',input_shape =(99,4457,4)))                                                         ^ SyntaxError:标识符中的字符无效

2 个答案:

答案 0 :(得分:1)

使用3,3代替kernel_size=3。它将解决您的问题。

from keras.models import Sequential
from keras.layers import Dense, Conv2D, Flatten
#create model
model = Sequential()
#add model layers
model.add(Conv2D(64, 3, 3, activation='relu', input_shape=(99,4457,4)))
model.add(Conv2D(32, 3, 3, activation='relu'))
model.add(Flatten())
model.add(Dense(10, activation=’softmax’))

答案 1 :(得分:0)

有同样的问题,对我来说改变的是更改标识符“包围” relu一词。这个''-示例:'relu',而不是高逗号’。所以:

from keras.models import Sequential
from keras.layers import Dense, Conv2D, Flatten
#create model
model = Sequential()
#add model layers
model.add(Conv2D(64, kernel_size=3, activation='relu', input_shape=(28,28,1)))
model.add(Conv2D(32, kernel_size=3, activation='relu'))
model.add(Flatten())
model.add(Dense(10, activation='softmax'))