Name 'LSTM' is not defined
See original GitHub issueI’m making a simple LSTM model, but I’m having issues with the model function
Top of code
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from tensorflow import keras
from hyperopt import Trials, STATUS_OK, tpe
from hyperas import optim
from hyperas.distributions import choice, uniform
from keras.layers.core import Dense, Dropout
from keras.layers.recurrent import LSTM
from keras.models import Sequential
def create_model(x_train, y_train, x_test, y_test):
from keras.layers.core import Dense, Dropout
from keras.layers.recurrent import LSTM
model = Sequential()
model.add(LSTM( {{choice([512, 1024, 2048])}} , input_shape=(14,1)))
if {{choice(["dropout", "none"])}} == "dropout":
model.add(Dropout({{uniform(0, 1)}}))
model.add(Dense(1))
model.compile(optimizer={{choice(['adam', 'adagrad', 'rmsprop'])}},loss='mse', metrics=['rmse'])
x_train = x_train.reshape((x_train.shape[0],x_train.shape[1],1))
x_test = x_test.reshape((x_test.shape[0],x_test.shape[1],1))
model.fit(X_train,y_train,epochs=20,validation_data=(X_test,y_test),shuffle=False)
score, err = model.evaluate(x_test, y_test, verbose=0)
print('Test accuracy:', err)
return {'loss': err, 'status': STATUS_OK, 'model': model}
But I keep getting the error: “Name ‘LSTM’ is not defined” When I try to run the optimizer. I looked at the LSTM examples and I do not seem to be doing much different from them, besides defining an input_shape. But if the input_shape is the problem, how would I be able to run my LSTM with this input? Thanks
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
NameError: name 'LSTM' is not defined · Issue #37137 - GitHub
It should be from tensorflow.keras.layers import LSTM. Thank you. 2
Read more >I am using keras and I get an error message saying "No ...
python - I am using keras and I get an error message saying "No module named 'lstm'" - Stack Overflow. Stack Overflow for...
Read more >Keras | NameError: name 'LSTM' is not defined_一只殿鹿的博客
问题描述:使用keras搭建神经网络时报错: model = tf.keras.Sequential([ LSTM(80, return_sequences=True), Dropout(0.2), LSTM(100), Dropout(0.2) ...
Read more >LSTM seq2seq with keras - Kaggle
input/fra2eng-dataset/fra-eng")) FileNotFoundError: [Errno 2] No such file or directory: '. ... NameError: name 'num_encoder_tokens' is not defined.
Read more >tf.keras.layers.LSTM | TensorFlow v2.11.0
When the input numpy array is not compatible with the RNN layer state, either size wise or dtype wise. Was this helpful?
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
one of the main reasons I advocate against notebooks btw.
@JohnnyUrosevic so I see from your notebook cell that you import this
but the hyperas output file says
this does not align at all. Hyperas can’t magically add
Activation
at the end for you. This means your notebook cell execution order is off (most likely).