我强烈怀疑有更好的方法来设置它,欢迎提出建议,但我在这里:
我想在Keras中使用递归神经网络对时间序列数据进行多类分类。我的模型定义如下:
model = Sequential()
model.add(LSTM(out_dim, input_shape = (X_train.shape[1], X_train.shape[2]), return_sequences = False))
model.add(Dense(num_classes, activation='sigmoid'))
optim_type = ["rmsprop", "adam", "sgd"]
for optim_val in optim_type:
if optim_val == "sgd" and default_val == False:
...
else:
optim_use = optim_type
model.compile(loss='categorical_crossentropy', optimizer = optim_use, metrics = ['accuracy'])
hist = model.fit(X_train, dummy_y, validation_data=(X_test, dummy_y_test), nb_epoch = epochs, batch_size = b_size)
我得到的错误是:
Using TensorFlow backend.
Traceback (most recent call last):
File "../rnn_new.py", line 213, in <module>
network_LSTM_rnn(data_in, out_dim, optim_type, b_size, save_file, num_classes, epochs, default_val)
File "../rnn_new.py", line 166, in network_LSTM_rnn
hist = model.fit(X_train, dummy_y, validation_data=(X_test, dummy_y_test), nb_epoch = epochs, batch_size = b_size)
File "/user/pkgs/anaconda2/envs/my_env/lib/python2.7/site-packages/keras/models.py", line 627, in fit
sample_weight=sample_weight)
File "/user/pkgs/anaconda2/envs/my_env/lib/python2.7/site-packages/keras/engine/training.py", line 1097, in fit
self._make_train_function()
File "/user/pkgs/anaconda2/envs/my_env/lib/python2.7/site-packages/keras/engine/training.py", line 712, in _make_train_function
training_updates = self.optimizer.get_updates(self._collected_trainable_weights,
AttributeError: 'list' object has no attribute 'get_updates'
如何修复此错误?你还需要我发布什么吗?
答案 0 :(得分:0)
我只是无法命名变量。我有optim_use = optim_type我应该有optim_use = optim_val。不管怎样,谢谢你!