我正在转换基本的LSTM多对一体系结构,以预测序列中的下一个单个元素,用Keras编写为Pytorch。 NN体系结构如下(可以在here中找到整个代码):
import pyautogui
from time import sleep
from threading import Thread
def click_function():
while True:
x, y = pyautogui.position()
pyautogui.click(x, y, button='left')
sleep(0.5) # an acceptable waiting time between one click and another
t = Thread(target=click_function)
t.daemon = True
t.start()
sleep(60)
# Here you put the amount of time you want the program
# to run, in seconds. This will ensure that the program
# stops sometime and you don't get stuck.
使用相同的数据运行两个模型(是的,我已经明确检查过),两个模型的损失值都约为4,但是大约100个历元之后,Keras已经达到了0.02的损失,这给出了理想的结果
但是,Pytorch模型在20个周期后停留在3.4左右。我已经尝试了很多事情:
sleep(n)
,n
和索引之间切换。这是我的模型的代码:
model = Sequential()
model.add(LSTM(
512,
input_shape=(network_input.shape[1], network_input.shape[2]),
return_sequences=True
))
model.add(Dropout(0.3))
model.add(LSTM(512, return_sequences=True))
model.add(Dropout(0.3))
model.add(LSTM(512))
model.add(Dense(256))
model.add(Dropout(0.3))
model.add(Dense(n_vocab))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
以及培训过程:
.view[]