Tensorflow 中导致 "Check failed: ret == 0 (11 vs. 0)Thread creation via pthread_create() failed." 的原因

What causes "Check failed: ret == 0 (11 vs. 0)Thread creation via pthread_create() failed." in Tensorflow

我在 python 中制作了一个 discord 机器人,现在使用 Tensorflow 和 NLTK 在其中添加了“Chatbot”功能。当我在本地 运行 机器人时,它工作得非常好,没有任何问题,但是当我将它移动到我托管我的投资组合的 namecheap 托管包时,它开始报错:

OpenBLAS blas_thread_init: pthread_create failed for thread 29 of 64: Resource temporarily unavailable

nltk 和 tensorflow 未导入,机器人崩溃。

我用谷歌搜索并找到了一个解决方案,它告诉我在使用任何导入之前使用 os.environ['OPENBLAS_NUM_THREADS'] = '1'。这解决了之前的错误,但现在又给出了另一个错误:

Check failed: ret == 0 (11 vs. 0)Thread creation via pthread_create() failed.

运行ning python main.py 上的完整输出现在是:

2021-06-10 11:18:19.606471: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2021-06-10 11:18:19.606497: 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.
2021-06-10 11:18:21.090650: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2021-06-10 11:18:21.090684: W tensorflow/stream_executor/cuda/cuda_driver.cc:326] failed call to cuInit: UNKNOWN ERROR (303)
2021-06-10 11:18:21.090716: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (server270.web-hosting.com): /proc/driver/nvidia/version does not exist
2021-06-10 11:18:21.091042: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 AVX512F FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-06-10 11:18:21.092409: F tensorflow/core/platform/default/env.cc:73] Check failed: ret == 0 (11 vs. 0)Thread creation via pthread_create() failed.

为了不让这个问题太长,源文件已经托管在 GitHub 此处:https://github.com/Nalin-2005/The2020CoderBot 并且 README.md 告诉哪些文件包含机器人的哪个部分。

该机器人托管在 Namecheap 共享主机上,有关服务器的详细信息和技术规格为:

据我所知,这两个问题都是由有限的 RAM 或 CPU 使用引起的。但是现在,Python 脚本本身会阻止使用。
那么,是什么原因造成的(如果我不正确),我该如何解决?

经过一段时间的集思广益和谷歌搜索,我发现了 Tensorflow Lite,它消耗的资源更少,但在我的服务器上提供相同的性能*,我可以轻松地将它与以前的代码集成,以生成一个资源效率更高的模型。 对于想知道如何将任何 keras 模型转换为 Tensorflow lite 的用户,这里是说明。

  1. 训练时,将 model.save("/path/to/model.h5") 替换为:
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
with open("/path/to/model.tflite", "wb") as f:
    f.write(tflite_model)
  1. 使用时,使用:
model = tf.lite.Interpreter("/path/to/model.tflite")
model.allocate_tensors()
input_details = model.get_input_details()
output_details = model.get_output_details()

# prepare input data

model.set_tensor(input_details[0]['index'],input_data)
model.invoke()
output_data = model.get_tensor(output_details[0]['index'])
results = np.squeeze(output_data)