是什么导致Tensorflow中的“Check failed:ret==0(11 vs.0)通过pthread_create()创建线程失败”

2024-06-16 06:21:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我用python制作了一个discord机器人,现在使用Tensorflow和NLTK在其中添加了“聊天机器人”功能。当我在本地运行bot时,它运行完全正常,没有任何问题,但是当我将它移动到我的namescape托管包(我在其中托管我的投资组合)时,它开始给出一个错误,说:

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.

现在运行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告诉哪些文件包含bot的哪个部分

bot托管在共享主机上,服务器的详细信息和技术规格如下:

  • 内存:1GB
  • 存储:20GB SSD
  • CPU(已使用):英特尔(R)至强(R)黄金6140CPU@2.30GHz

据我所知,这两个问题都是由有限的RAM或CPU使用引起的。但是现在,Python脚本本身阻止了使用。
那么,是什么导致了这一点(如果我不正确)以及如何修复这一点


Tags: defaultstreamtensorflowbot错误createnot机器人
1条回答
网友
1楼 · 发布于 2024-06-16 06:21:57

经过一段时间的头脑风暴和谷歌搜索,我发现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)

相关问题 更多 >