9951 explained code solutions for 126 technologies


python-tensorflowHow do I create a Python app using TensorFlow?


Using TensorFlow to create a Python app requires a few steps.

  1. Install TensorFlow, either using pip install tensorflow or conda install tensorflow.

  2. Create a Python script, such as my_app.py

  3. Import TensorFlow into the script, using import tensorflow as tf

  4. Create a TensorFlow graph, with operations such as tf.add() and tf.multiply()

Example

import tensorflow as tf

a = tf.add(3,5)
b = tf.multiply(3,5)

with tf.Session() as sess:
    print("a =", sess.run(a))
    print("b =", sess.run(b))

Output example

a = 8
b = 15
  1. Run the TensorFlow graph within a session, using tf.Session()

  2. Execute the graph with sess.run()

  3. Close the session with sess.close()

Helpful links

Edit this code on GitHub