Reputation: 83
I'm trying to explore use of tensorflow with custom ops. I build a simple switch op and verified it as suggested in tensorflow document. Now I'm trying to build the graph and then call run()
method in a tensorflow
Session. Below is my code. I get the following error. Can someone help what should I do to fix it. Do I need to re-install tensorflow everytime I add a new custom op to /user_ops/
?
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()
When executed in python interpreter I get the following error:
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'
Upvotes: 2
Views: 1384
Reputation: 126154
After 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 using Bazel. (The unit test would pass because running bazel test
would cause TensorFlow to be rebuilt, and the rebuilt version to be used when running the tests.)
NOTE: This feature is experimental, and an improved workflow for adding user-defined ops is in development.
Upvotes: 2