模型github地址:
https://github.com/liangzulin/cwrnn_for_keras_2_1_above
模型的训练和预测结果:
模型从epochs=0一直到99次迭代后的训练准确率和预测准确率曲线:
模型的简单使用方法:
model = Sequential()
model.add(ClockworkRNN(units=90,
period_spec=[1, 2, 4, 8, 16],
input_shape=train_x.shape[1:], # ---(samples, timesteps, dimension)
dropout_W=0.4,
return_sequences=True,
debug=cwrnn_debug)) # debug is for developing mode, you can remove
model.add(Dropout(.2))
model.add(TimeDistributed(Dense(units=1, activation='linear')))
model.compile(loss='mse', optimizer='sgd', metrics=['accuracy'])
model.fit(train_x, train_y, epochs=epochs, batch_size=1, verbose=1)
不同版本keras调用可能会出现报错,需要注意调用区别:
1、
2、出现Exception: Error when checking : expected dense_input_1 to have shape (None, 784) but got array with shape (784, 1)类似的错误,说明输入数据的维度与模型需求不符合,需要更改维度(参考:by https://stackoverflow.com/questions/39950311/keras-error-on-predict/40489174、https://github.com/keras-team/keras/issues/3109)