Could not find cuda drivers on your machine, GPU will not be used

我安装了cuda,pytorch可以检查gpu,但是tensorflow检测不到,从这里安装tensorflow:

pip install --extra-index-url https://pypi.nvidia.com tensorflow[and-cuda]
 

2024-04-04 13:51:41.596916: I external/local_tsl/tsl/cuda/cudart_stub.cc:31] Could not find cuda drivers on your machine, GPU will not be used.

2024-04-04 13:51:41.635006: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered

2024-04-04 13:51:41.635035: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered

2024-04-04 13:51:41.636666: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS

(tensorflow) root@DESKTOP-RVNE65O:~/work/model_zoo# python extracttflite.py 2025-03-07 14:57:53.720064: I tensorflow/core/util/port.cc:111] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 2025-03-07 14:57:53.772008: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used. 2025-03-07 14:57:53.999328: E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered 2025-03-07 14:57:53.999476: E tensorflow/compiler/xla/stream_executor/cuda/cuda_fft.cc:609] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered 2025-03-07 14:57:54.001268: E tensorflow/compiler/xla/stream_executor/cuda/cuda_blas.cc:1518] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered 2025-03-07 14:57:54.137256: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used. 2025-03-07 14:57:54.138160: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 AVX_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. 2025-03-07 14:57:55.181380: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT INFO: Created TensorFlow Lite XNNPACK delegate for CPU. Traceback (most recent call last): File "/root/work/model_zoo/extracttflite.py", line 52, in <module> extractSubgraphToTflite(interpreter, subgraph1Inputs, subgraph1Outputs, './model/tflite/MicroISP_1.tflite') File "/root/work/model_zoo/extracttflite.py", line 39, in extractSubgraphToTflite converter = tf.lite.TFLiteConverter.from_concrete_functions([interpreter.get_signature_runner()]) File "/opt/anaconda3/envs/tensorflow/lib/python3.10/site-packages/tensorflow/lite/python/interpreter.py", line 853, in get_signature_runner raise ValueError( ValueError: SignatureDef signature_key is None and model has 0 Signatures. None is only allowed when the model has 1 SignatureDef
最新发布
03-08
<think>嗯,用户在执行一个Python脚本extracttflite.py时遇到了错误。我需要先看看错误信息。首先,用户的环境是TensorFlow,他们在尝试提取TFLite模型时出现了问题。 错误日志里有几个部分。开头是关于oneDNN的警告,提到可能会因为计算顺序不同导致数值差异,但应该不影响主要问题。然后是CUDA相关的错误,比如找不到cuda驱动,无法注册cuDNN、cuFFT、cuBLAS的工厂。这可能是因为用户没有安装NVIDIA驱动或者CUDA工具包,或者TensorFlow版本和CUDA不兼容,但用户可能是在没有GPU的环境下运行,所以这些警告可能可以忽略,但需要确认是否会影响后续步骤。 接下来是CPU指令集的提示,建议用户重新编译TensorFlow以支持AVX2等指令,不过这通常只是性能提示,不会导致程序崩溃。然后是TF-TRT的警告,找不到TensorRT,这可能也是因为环境配置问题,但同样可能不是关键问题。 主要的错误在Traceback部分,指向extracttflite.py的第52行和第39行。错误是ValueError,提示说SignatureDef的signature_key是None,而模型有0个Signatures。当模型没有或超过一个SignatureDef时,使用None是不允许的。错误发生在尝试获取signature_runner时,因为模型没有签名。 用户的问题可能出在他们如何加载和转换模型。可能他们的模型没有定义任何签名,而代码假设模型有一个默认的签名。或者,在转换过程中没有正确指定签名。 我需要考虑可能的解决方法。首先,检查模型是否有签名。使用TensorFlow的SavedModel CLI工具可以查看模型的签名。如果模型没有签名,可能需要修改转换代码,明确指定输入输出,而不是依赖签名。或者,在转换时手动指定具体的函数。 另一个可能是,用户使用的转换方法不正确。例如,他们可能在使用Interpreter而不是正确的Converter方法。代码中的converter = tf.lite.TFLiteConverter.from_concrete_functions([interpreter.get_signature_runner()]) 这里可能有问题,因为Interpreter可能没有正确加载模型,或者模型没有签名,导致get_signature_runner()失败。 建议用户检查模型的保存方式,确保保存时包含签名。如果使用SavedModel格式,是否有正确的签名。或者,在转换时使用from_saved_model方法,或者使用具体的concrete functions,而不是依赖签名。 另外,可能需要使用TFLiteConverter的其他方法,比如from_keras_model,或者直接加载SavedModel,并明确指定输入输出张量,而不是依赖签名。 用户可能需要修改他们的extracttflite.py脚本,确保正确加载模型并指定具体的函数或签名。例如,如果模型没有签名,可能需要手动构建concrete function,或者在转换时指定输入输出。</think>这个错误信息显示您在使用TensorFlow Lite模型转换时遇到了签名定义(SignatureDef)相关的问题。以下是逐步分析和解决方案: --- ### **错误原因分析** 1. **核心错误**: ```python ValueError: SignatureDef signature_key is None and model has 0 Signatures. None is only allowed when the model has 1 SignatureDef ``` 表示您尝试使用默认的签名(`signature_key=None`)转换模型,但原始模型**未定义任何签名**。 2. **背景知识**: - TensorFlow Lite模型通过`SignatureDef`定义输入/输出接口。 - 如果模型未显式定义签名,转换时需要**手动指定输入/输出张量**。 --- ### **解决方案** #### 方法1:为原始模型添加签名(推荐) 如果原始模型是Keras模型,在保存时添加签名: ```python # 保存模型时定义签名 tf.saved_model.save(model, "saved_model_path", signatures={ "serving_default": model.call.get_concrete_function( tf.TensorSpec(shape=[None, 224, 224, 3], dtype=tf.float32) ) } ) ``` #### 方法2:手动指定输入/输出(无签名时) 修改`extracttflite.py`中转换代码: ```python # 替换这行代码: # converter = tf.lite.TFLiteConverter.from_concrete_functions([interpreter.get_signature_runner()]) # 改为手动指定输入输出张量名称 converter = tf.lite.TFLiteConverter.from_saved_model( saved_model_dir, input_arrays=['input_tensor_name'], output_arrays=['output_tensor_name'] ) ``` --- ### **环境警告解释** 1. **GPU相关警告**: ```log Could not find cuda drivers on your machine, GPU will not be used. ``` 表示当前环境未检测到NVIDIA GPU驱动,TensorFlow将回退到CPU模式。如需GPU加速,请安装CUDA驱动。 2. **CPU优化提示**: ```log This TensorFlow binary is optimized to use available CPU instructions... ``` 建议重新编译TensorFlow以支持AVX2指令集,但这只会影响性能,不会导致当前错误。 --- ### **完整修复步骤** 1. 检查原始模型是否包含签名: ```bash saved_model_cli show --dir /path/to/model --all ``` 2. 如果无签名,使用上述方法2修改转换代码。 3. 重新运行脚本: ```bash TF_ENABLE_ONEDNN_OPTS=0 python extracttflite.py # 关闭oneDNN优化(可选) ``` --- 通过上述调整,您应该能正确导出TFLite模型。如果问题仍然存在,请提供模型保存方式以便进一步诊断。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值