在张量流中使用自定义操作构建图形
Building a graph with custom ops in tensorflow
我正在尝试探索将 tensorflow 与自定义操作结合使用。我构建了一个简单的开关操作并按照 tensorflow 文档中的建议对其进行了验证。现在我正在尝试构建图形,然后在张量流中调用 run()
方法
Session。下面是我的代码。我收到以下错误。有人可以帮助我应该怎么做才能解决它。每次我向 /user_ops/
添加新的自定义操作时都需要 re-install tensorflow 吗?
import tensorflow as tf
# Create a Constant op that produce integer value
input1 = tf.constant(10)
# Create another op that produce an integer value
input2 = tf.constant(5)
# Create op that produce 0 or 1 as the control input in a switch
input3 = tf.constant(1)
# Create a switch op that takes input1 and input2 as inputs and input3 as
# the control input to produce an output
out = tf.user_ops.simple_switch(input1, input2, input3)
# Launch a default graph
sess = tf.Session()
# Call the 'run()' method and get the result
result = sess.run(out)
print(result)
# Close the Session when we're done!
sess.close()
在 python 解释器中执行时出现以下错误:
Traceback (most recent call last):
File "tensorflow-switch.py", line 14, in
out = tf.simple_switch(input1, input2, input3)
AttributeError: 'module' object has no attribute 'simple_switch'
adding a user-defined op (in TensorFlow 0.6.0 or earlier), to use it in the Python interpreter you must reinstall from the source repository. The easiest way to do this is to build and install a PIP package 使用 Bazel 之后。 (单元测试会通过,因为 运行 bazel test
会导致重建 TensorFlow,并在 运行 测试时使用重建版本。)
注意:此功能是实验性的,用于添加 user-defined 操作的改进工作流程正在开发中。
我正在尝试探索将 tensorflow 与自定义操作结合使用。我构建了一个简单的开关操作并按照 tensorflow 文档中的建议对其进行了验证。现在我正在尝试构建图形,然后在张量流中调用 run()
方法
Session。下面是我的代码。我收到以下错误。有人可以帮助我应该怎么做才能解决它。每次我向 /user_ops/
添加新的自定义操作时都需要 re-install tensorflow 吗?
import tensorflow as tf
# Create a Constant op that produce integer value
input1 = tf.constant(10)
# Create another op that produce an integer value
input2 = tf.constant(5)
# Create op that produce 0 or 1 as the control input in a switch
input3 = tf.constant(1)
# Create a switch op that takes input1 and input2 as inputs and input3 as
# the control input to produce an output
out = tf.user_ops.simple_switch(input1, input2, input3)
# Launch a default graph
sess = tf.Session()
# Call the 'run()' method and get the result
result = sess.run(out)
print(result)
# Close the Session when we're done!
sess.close()
在 python 解释器中执行时出现以下错误:
Traceback (most recent call last): File "tensorflow-switch.py", line 14, in out = tf.simple_switch(input1, input2, input3) AttributeError: 'module' object has no attribute 'simple_switch'
adding a user-defined op (in TensorFlow 0.6.0 or earlier), to use it in the Python interpreter you must reinstall from the source repository. The easiest way to do this is to build and install a PIP package 使用 Bazel 之后。 (单元测试会通过,因为 运行 bazel test
会导致重建 TensorFlow,并在 运行 测试时使用重建版本。)
注意:此功能是实验性的,用于添加 user-defined 操作的改进工作流程正在开发中。