0
我想用一個卷積神經網絡(CNN)訓練我的數據,我開始重塑我的數據不是建立我的模型:Conolutional Neural Network:float()參數必須是字符串或數字嗎?
model = Sequential()
input_traces = Input(shape=(3253,))
model.add(Convolution1D(nb_filter=32, filter_length=3, border_mode='same',
activation='relu',input_dim=input_traces))
model.add(MaxPooling1D(pool_length=2))
model.add(Flatten())
model.add(Dense(250, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=
['accuracy'])
print(model.summary())
model.fit(x_train, y_train, batch_size=15, nb_epoch=30, show_accuracy=True,
validation_data=(x_test, y_test))
但這段代碼給了我這個錯誤:
CNN_Based_Attack.py:139: UserWarning: Update your `Conv1D` call to the Keras 2 API: `Conv1D(activation="relu", input_shape=(None, /in..., padding="same", filters=32, kernel_size=3)`
model.add(Convolution1D(nb_filter=32, filter_length=3, border_mode='same', activation='relu',input_dim=input_traces))
Traceback (most recent call last):
File "CNN_Based_Attack.py", line 139, in <module>
model.add(Convolution1D(nb_filter=32, filter_length=3, border_mode='same', activation='relu',input_dim=input_traces))
File "/home/.local/lib/python2.7/site-packages/keras/models.py", line 430, in add
layer(x)
File "/home/.local/lib/python2.7/site-packages/keras/engine/topology.py", line 557, in __call__
self.build(input_shapes[0])
File "/home/.local/lib/python2.7/site-packages/keras/layers/convolutional.py", line 134, in build
constraint=self.kernel_constraint)
File "/home/.local/lib/python2.7/site-packages/keras/legacy/interfaces.py", line 88, in wrapper
return func(*args, **kwargs)
File "/home/.local/lib/python2.7/site-packages/keras/engine/topology.py", line 390, in add_weight
weight = K.variable(initializer(shape), dtype=dtype, name=name)
File "/home/.local/lib/python2.7/site-packages/keras/initializers.py", line 200, in __call__
scale /= max(1., float(fan_in + fan_out)/2)
TypeError: float() argument must be a string or a number
我真的不明白這個錯誤。你可以幫我嗎。