简体   繁体   English

Keras LSTM 后实例运行缓慢

[英]Instance running slow after Keras LSTM

I have an EC2 instance in AWS running a python script creating models for a bunch of stocks using Keras LSTM.我在 AWS 中有一个 EC2 实例,它运行一个 python 脚本,使用 Keras LSTM 为一堆股票创建模型。 Every model takes about 6 minutes to be fitted and stored.每个模型大约需要 6 分钟才能安装和存储。 The problem that I am facing is a slowdown in AWS instance, so the models are not finished to be fitted.我面临的问题是 AWS 实例速度变慢,因此模型还没有完成安装。 It takes more and more time for each model to be calculated.计算每个模型需要越来越多的时间。 Let's say the first 6-7 models are calculated right in about 6 minutes each, but then the eighth model takes more than 15 minutes and the ninth more than an hour and then it stops.假设前 6-7 个模型分别在大约 6 分钟内计算正确,但是第八个模型需要 15 多分钟,第九个模型需要一个多小时,然后它就停止了。

Curiously I ran the script saturday morning without a problem.奇怪的是,我星期六早上运行脚本没有问题。 Then I tried again and it stopped.然后我又试了一次,它停止了。 And now every time I try it gets stuck after a couple of models.现在每次我尝试它都会在几个模型之后卡住。 I stopped and restarted the instance.我停止并重新启动了实例。 It seems to deblock a bit, so if I run the script it starts fine (about 6 minutes) but again, after a while, the time increases and stops.它似乎有点解除阻塞,所以如果我运行脚本,它开始正常(大约 6 分钟),但又过了一会儿,时间增加并停止。

It's a really simple script: I have the tickers in a list and then:这是一个非常简单的脚本:我在列表中有代码,然后:

for ticker in tickers:对于股票代码:

get_and_prepare_data(ticker) get_and_prepare_data(股票代码)

create_and_save_model(ticker) create_and_save_model(股票代码)

As I suppose, the memory gets full or something like that.正如我想的那样,内存变得满了或类似的东西。 So maybe there is a way to free memory within the script.所以也许有一种方法可以在脚本中释放内存。 I don't know... or meybe even if I restart the instance there is some memory allocated in the instance...我不知道......或者即使我重新启动实例,实例中也会分配一些内存......

Thanks in advance提前致谢

OK, after searching a while I found the solution using Keras Backend Clear_session().好的,经过一段时间的搜索,我找到了使用 Keras Backend Clear_session() 的解决方案。

You can find more info here https://www.tensorflow.org/api_docs/python/tf/keras/backend/clear_session你可以在这里找到更多信息https://www.tensorflow.org/api_docs/python/tf/keras/backend/clear_session

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM