'Could not find variable lstm/lstm_cell/recurrent_kernel
Trying to run this code:
import numpy as np
import tensorflow as tf
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.optimizer_v1 import RMSprop
from tensorflow.python.keras.layers import Activation, Dense, LSTM
tf.compat.v1.disable_eager_execution()
text = open('poems.txt', 'rb').read().decode(encoding='utf-8').lower()
characters = sorted(set(text))
char_to_index = dict((c, i) for i, c in enumerate(characters))
index_to_char = dict((i, c) for i, c in enumerate(characters))
SEQ_LENGTH = 40
STEP_SIZE = 3
sentences = []
next_char = []
for i in range(0, len(text) - SEQ_LENGTH, STEP_SIZE):
sentences.append(text[i: i + SEQ_LENGTH])
next_char.append(text[i + SEQ_LENGTH])
x = np.zeros((len(sentences), SEQ_LENGTH,
len(characters)), dtype=np.bool)
y = np.zeros((len(sentences),
len(characters)), dtype=np.bool)
for i, satz in enumerate(sentences):
for t, char in enumerate(satz):
x[i, t, char_to_index[char]] = 1
y[i, char_to_index[next_char[i]]] = 1
model = Sequential()
model.add(LSTM(128,input_shape=(SEQ_LENGTH,len(characters))))
model.add(Dense(len(characters)))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy',
optimizer=RMSprop(lr=0.01))
model.fit(x, y, batch_size=256, epochs=4)
model.save('poetryGen')
But I keep getting this error:
Could not find variable lstm/lstm_cell/recurrent_kernel. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Container localhost does not exist. (Could not find resource: localhost/lstm/lstm_cell/recurrent_kernel)
[[{{node lstm/lstm_cell/recurrent_kernel/Read/ReadVariableOp}}]]
What could be the problem?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
