Here is how eager execution is done in Tensorflow.
Run the code here: https://repl.it/@VinitKhandelwal/tensorflow-eager-area-triangle
Run the code here: https://repl.it/@VinitKhandelwal/tensorflow-eager-area-triangle
Example: Calculating area of triangles passed as matrix and getting output with eager execution.
import tensorflow as tf
from tensorflow.contrib.eager.python import tfe
tfe.enable_eager_execution()
#TODO: Using your non-placeholder solution, 
def compute_area(sides):
  #TODO: Write TensorFlow code to compute area of a
  a = sides[:, 0]
  b = sides[:, 1]
  c = sides[:, 2]
  #  SET of triangles given by their side lengths
  s = (a+b+c)*0.5
  areasq = s*(s-a)*(s-b)*(s-c)
  return tf.sqrt(areasq)
#  try it now using tf.eager by removing the session
area = compute_area(tf.constant([[5.0, 3.0, 7.1], [2.3, 4.1, 4.8]]))
print(area)
Comments
Post a Comment