gpt4 book ai didi

python - Tensorflow 添加了一个新的操作,无法从 python 导入

转载 作者:行者123 更新时间:2023-11-28 19:10:24 24 4
gpt4 key购买 nike

我按照tensorflow文档做了: https://www.tensorflow.org/how_tos/adding_an_op/#attrs

  1. https://github.com/tensorflow/tensorflow获取源代码
  2. tensorflow/core/user_ops/下添加一个zero_out.cc文件
  3. tensorflow/core/user_ops/下添加一个BUILD文件
  4. 在终端运行:$ bazel build -c opt//tensorflow/core/user_ops:zero_out.so

INFO: Found 1 target...
Target //tensorflow/core/user_ops:zero_out.so up-to-date:
bazel-bin/tensorflow/core/user_ops/zero_out.so
INFO: Elapsed time: 0.125s, Critical Path: 0.00s

但是当我在python中运行下面的代码时,出现了错误:

Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so locally
>>> zero_out_module = tf.load_op_library('zero_out.so')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/yc/tfenv/local/lib/python2.7/site-packages/tensorflow/python/framework/load_library.py", line 64, in load_op_library
None, None, error_msg, error_code)
tensorflow.python.framework.errors_impl.NotFoundError: zero_out.so: cannot open shared object file: No such file or directory

最佳答案

Bazel 会将 op 库生成到 bazel-bin 文件夹中。

当你使用 bazel 构建 ot 时,你应该尝试从那里加载它:

zero_out_module = tf.load_op_library('bazel-bin/tensorflow/user_ops/zero_out.so') 

关于python - Tensorflow 添加了一个新的操作,无法从 python 导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41215614/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com