【问题标题】:Tensorflow: Cannot import user_ops from my python fileTensorflow:无法从我的 python 文件中导入 user_ops
【发布时间】:2015-11-23 23:54:40
【问题描述】:

我已经运行了教程并成功地在 tensorflow 中创建了自己的神经网络实现。然后我决定再进一步添加我自己的操作,因为我需要对数据进行一些自己的预处理。我按照 tensorflow 网站上的教程添加了一个操作。在编写自己的 c++ 文件后,我成功构建了 tensorflow。然后,当我尝试从我的代码中使用它时,我得到了

'module' object has no attribute 'sec_since_midnight'

我的代码确实反映在 bazel-genfiles/tensorflow/python/ops/gen_user_ops.py 中,因此包装器确实为它正确生成。看起来我看不到导入该文件的 tensorflow/python/user_ops/user_ops.py。

现在,当我测试这个模块时,我得到了以下奇怪的行为。它不应该通过,因为我给它的预期向量与结果不匹配。但是,尽管说通过了,但也许测试永远不会执行?

INFO: Found 1 test target...
Target //tensorflow/python:sec_since_midnight_op_test up-to-date:
  bazel-bin/tensorflow/python/sec_since_midnight_op_test
INFO: Elapsed time: 6.131s, Critical Path: 5.36s
//tensorflow/python:sec_since_midnight_op_test              (1/0 cached) PASSED

Executed 0 out of 1 tests: 1 test passes.
There were tests whose specified size is too big. Use the --test_verbose_timeout_warnings command line option to see which ones these are.

【问题讨论】:

  • 我现在也在为导入我自己的自定义操作而苦苦挣扎……请告诉我你是如何导入它的? 'bazel-genfiles/tensorflow/python/ops/gen_user'应该反映哪些变化?

标签: operation tensorflow


【解决方案1】:

嗯。好吧,我卸载了 tensorflow,然后从我刚刚构建的内容重新安装,我写的内容突然被识别出来。我现在已经连续两次看到这种行为需要卸载。综上所述,添加我自己的操作后的步骤是:

$ pip uninstall tensorflow
$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package

# To build with GPU support:
$ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

# The name of the .whl file will depend on your platform.
$ pip install /tmp/tensorflow_pkg/tensorflow-0.5.0-cp27-none-linux_x86_64.whl

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-09
    • 2022-12-18
    • 1970-01-01
    • 2018-06-12
    • 2019-04-26
    • 2019-05-17
    • 2021-10-02
    • 1970-01-01
    相关资源
    最近更新 更多