'Q: RuntimeError: Attempted to use a closed Session
There is my problem. I don't know what to do please somebody help me :(
2022-05-17 01:31:16.792782: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-05-17 01:31:16.801640: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
WARNING:tensorflow:From C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\compat\v2_compat.py:107: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term
curses is not supported on this machine (please install/reinstall curses for an optimal experience)
Scipy not supported!
WARNING:tensorflow:From C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\initializations.py:164: calling TruncatedNormal.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
2022-05-17 01:31:26.468482: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2022-05-17 01:31:26.477347: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
2022-05-17 01:31:26.488251: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-SGILDDN
2022-05-17 01:31:26.498663: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-SGILDDN
2022-05-17 01:31:26.504631: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
---------------------------------
Run id: LJ9JCK
Log directory: /tmp/tflearn_logs/
---------------------------------
Training samples: 26
Validation samples: 0
--
Traceback (most recent call last):
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\client\session.py", line 1377, in _do_call
return fn(*args)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\client\session.py", line 1360, in _run_fn
return self._call_tf_sessionrun(options, feed_dict, fetch_list,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\client\session.py", line 1453, in _call_tf_sessionrun
return tf_session.TF_SessionRun_wrapper(self._session, options, feed_dict,
tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [8,8] rhs shape= [0,0]
[[{{node save_1/Assign_11}}]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\saver.py", line 1400, in restore
sess.run(self.saver_def.restore_op_name,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\client\session.py", line 967, in run
result = self._run(None, fetches, feed_dict, options_ptr,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\client\session.py", line 1190, in _run
results = self._do_run(handle, final_targets, final_fetches,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\client\session.py", line 1370, in _do_run
return self._do_call(_run_fn, feeds, fetches, targets, options,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\client\session.py", line 1396, in _do_call
raise type(e)(node_def, op, message) # pylint: disable=no-value-for-parameter
tensorflow.python.framework.errors_impl.InvalidArgumentError: Graph execution error:
Detected at node 'save_1/Assign_11' defined at (most recent call last):
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 262, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 95, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\Dell\Desktop\chat bot\chat bot.py", line 77, in <module>
model = tflearn.DNN(net)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\models\dnn.py", line 57, in __init__
self.trainer = Trainer(self.train_ops,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\helpers\trainer.py", line 149, in __init__
self.restorer = tf.train.Saver(
Node: 'save_1/Assign_11'
Assign requires shapes of both tensors to match. lhs shape= [8,8] rhs shape= [0,0]
[[{{node save_1/Assign_11}}]]
Original stack trace for 'save_1/Assign_11':
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 262, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 95, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\Dell\Desktop\chat bot\chat bot.py", line 77, in <module>
model = tflearn.DNN(net)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\models\dnn.py", line 57, in __init__
self.trainer = Trainer(self.train_ops,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\helpers\trainer.py", line 149, in __init__
self.restorer = tf.train.Saver(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\saver.py", line 919, in __init__
self.build()
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\saver.py", line 931, in build
self._build(self._filename, build_save=True, build_restore=True)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\saver.py", line 959, in _build
self.saver_def = self._builder._build_internal( # pylint: disable=protected-access
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\saver.py", line 529, in _build_internal
restore_op = self._AddRestoreOps(filename_tensor, saveables,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\saver.py", line 372, in _AddRestoreOps
assign_ops.append(saveable.restore(saveable_tensors, shapes))
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\saving\saveable_object_util.py", line 77, in restore
return state_ops.assign(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\state_ops.py", line 352, in assign
return gen_state_ops.assign(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\gen_state_ops.py", line 57, in assign
_, _, _op, _outputs = _op_def_library._apply_op_helper(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 740, in _apply_op_helper
op = g._create_op_internal(op_type_name, inputs, dtypes=None,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\ops.py", line 3776, in _create_op_internal
ret = Operation(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\ops.py", line 2175, in __init__
self._traceback = tf_stack.extract_stack_for_node(self._c_op)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\Dell\Desktop\chat bot\chat bot.py", line 80, in <module>
model.load("model.tflearn")
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\models\dnn.py", line 302, in load
self.trainer.restore(model_file, weights_only, **optargs)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\helpers\trainer.py", line 500, in restore
self.restorer.restore(self.session, model_file)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\saver.py", line 1436, in restore
raise _wrap_restore_error_with_msg(
tensorflow.python.framework.errors_impl.InvalidArgumentError: Restoring from checkpoint failed. This is most likely due to a mismatch between the current graph and the graph from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:
Graph execution error:
Detected at node 'save_1/Assign_11' defined at (most recent call last):
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 262, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 95, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\Dell\Desktop\chat bot\chat bot.py", line 77, in <module>
model = tflearn.DNN(net)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\models\dnn.py", line 57, in __init__
self.trainer = Trainer(self.train_ops,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\helpers\trainer.py", line 149, in __init__
self.restorer = tf.train.Saver(
Node: 'save_1/Assign_11'
Assign requires shapes of both tensors to match. lhs shape= [8,8] rhs shape= [0,0]
[[{{node save_1/Assign_11}}]]
Original stack trace for 'save_1/Assign_11':
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 262, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 95, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\Dell\Desktop\chat bot\chat bot.py", line 77, in <module>
model = tflearn.DNN(net)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\models\dnn.py", line 57, in __init__
self.trainer = Trainer(self.train_ops,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\helpers\trainer.py", line 149, in __init__
self.restorer = tf.train.Saver(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\saver.py", line 919, in __init__
self.build()
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\saver.py", line 931, in build
self._build(self._filename, build_save=True, build_restore=True)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\saver.py", line 959, in _build
self.saver_def = self._builder._build_internal( # pylint: disable=protected-access
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\saver.py", line 529, in _build_internal
restore_op = self._AddRestoreOps(filename_tensor, saveables,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\saver.py", line 372, in _AddRestoreOps
assign_ops.append(saveable.restore(saveable_tensors, shapes))
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\saving\saveable_object_util.py", line 77, in restore
return state_ops.assign(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\state_ops.py", line 352, in assign
return gen_state_ops.assign(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\gen_state_ops.py", line 57, in assign
_, _, _op, _outputs = _op_def_library._apply_op_helper(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 740, in _apply_op_helper
op = g._create_op_internal(op_type_name, inputs, dtypes=None,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\ops.py", line 3776, in _create_op_internal
ret = Operation(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\ops.py", line 2175, in __init__
self._traceback = tf_stack.extract_stack_for_node(self._c_op)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\Dell\.vscode\extensions\ms-python.python-2022.6.2\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 262, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 95, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\Dell\Desktop\chat bot\chat bot.py", line 82, in <module>
model.fit(training, output, n_epoch=1000, batch_size=8, show_metric=True)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\models\dnn.py", line 196, in fit
self.trainer.fit(feed_dicts, val_feed_dicts=val_feed_dicts,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\helpers\trainer.py", line 341, in fit
snapshot = train_op._train(self.training_state.step,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\helpers\trainer.py", line 826, in _train
tflearn.is_training(True, session=self.session)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tflearn\config.py", line 95, in is_training
tf.get_collection('is_training_ops')[0].eval(session=session)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\ops.py", line 1060, in eval
return _eval_using_default_session(self, feed_dict, self.graph, session)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\ops.py", line 5769, in _eval_using_default_session
return session.run(tensors, feed_dict)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\client\session.py", line 967, in run
result = self._run(None, fetches, feed_dict, options_ptr,
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\client\session.py", line 1115, in _run
raise RuntimeError('Attempted to use a closed Session.')
RuntimeError: Attempted to use a closed Session.
PS C:\Users\Dell\Desktop\chat bot>
Actually I am making a chatbot.
I don't know where this error came from.
Can you find where does it came from?
Here is my code -
import nltk
from nltk.stem.lancaster import LancasterStemmer
stemmer = LancasterStemmer()
import numpy
import tflearn
import tensorflow
from tensorflow.python.framework import ops
import random
import json
import pickle
with open("intents.json") as file:
data = json.load(file)
try:
with open("data.pickle", "rb") as f:
words, labels, training, output = pickle.load(f)
except:
words = []
labels = []
docs_x = []
docs_y = []
for intent in data["intents"]:
for pattern in intent["patterns"]:
wrds = nltk.word_tokenize(pattern)
words.extend(wrds)
docs_x.append(wrds)
docs_y.append(intent["tag"])
if intent["tag"] not in labels:
labels.append(intent["tag"])
words = [stemmer.stem(w.lower()) for w in words if w != "?"]
words = sorted(list(set(words)))
labels = sorted(labels)
training = []
output = []
out_empty = [0 for _ in range(len(labels))]
for x, doc in enumerate(docs_x):
bag = []
wrds = [stemmer.stem(w.lower()) for w in doc]
for w in words:
if w in wrds:
bag.append(1)
else:
bag.append(0)
output_row = out_empty[:]
output_row[labels.index(docs_y[x])] = 1
training.append(bag)
output.append(output_row)
training = numpy.array(training)
output = numpy.array(output)
with open("data.pickle", "wb") as f:
pickle.dump((words, labels, training, output), f)
ops.reset_default_graph()
net = tflearn.input_data(shape=[None, len(training[0])])
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, len(output[0]), activation="softmax")
net = tflearn.regression(net)
model = tflearn.DNN(net)
try:
model.load("model.tflearn")
except:
model.fit(training, output, n_epoch=1000, batch_size=8, show_metric=True)
model.save("model.tflearn")
def bag_of_words(s, words):
bag = [0 for _ in range(len(words))]
s_words = nltk.word_tokenize(s)
s_words = [stemmer.stem(word.lower()) for word in s_words]
for se in s_words:
for i, w in enumerate(words):
if w == se:
bag[i] = 1
return numpy.array(bag)
def chat():
print("Start talking with the bot (type quit to stop)!")
while True:
inp = input("You: ")
if inp.lower() == "quit":
break
results = model.predict([bag_of_words(inp, words)])
results_index = numpy.argmax(results)
tag = labels[results_index]
for tg in data["intents"]:
if tg['tag'] == tag:
responses = tg['responses']
print(random.choice(responses))
chat()
If you know the answer please give me that. Answer as fast as you can.
But don't edit too much!
God bless you 🙏
Thank you very much!!!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
