baotrung217

tensorflow2

Dec 4th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. import numpy as np
  2. import tensorflow as tf
  3.  
  4. graph = tf.Graph()
  5.  
  6. with graph.as_default():
  7. #    in_1 = tf.placeholder(tf.float32, shape=[], name="input_a")
  8. #    in_2 = tf.placeholder(tf.float32, shape=[], name="input_b")
  9. #    const = tf.constant(3, dtype=tf.float32, name="static_value")
  10.                
  11.     with tf.name_scope("variables"):
  12.         # variable to keep track of how many times the graph has been run
  13.         global_step = tf.Variable(0, dtype=tf.int32, trainable=False, name="global_step")    
  14.         # variable that keeps track of the sum of all output values over time
  15.         total_output = tf.Variable(0.0, dtype=tf.float32, trainable=False, name= "total_output")
  16.        
  17.     with tf.name_scope("transformation"):
  18.        
  19.         # separate input layer
  20.         with tf.name_scope("input"):
  21.             # create input placeholder - takes in a vector
  22.             a = tf.placeholder(tf.float32, shape=[None], name="input_placeholder_a")
  23.        
  24.         # separate middle layer
  25.         with tf.name_scope("intermediate_layer"):
  26.             b = tf.reduce_prod(a, name="product_b")
  27.             c = tf.reduce_sum(a, name="sum_c")
  28.            
  29.         # separate output layer
  30.         with tf.name_scope("output"):
  31.             output = tf.add(b, c, name="output")
  32.    
  33.     with tf.name_scope("update"):
  34.         # increment the total_output variable by the latest output
  35.         update_total = total_output.assign_add(output)
  36.         # increment the global_step variable, should be run whenever the graph is run
  37.         increment_step = global_step.assign_add(1)
  38.            
  39.  
  40. writer = tf.summary.FileWriter('./name_scope_2', graph=graph)
  41. writer.close()
Advertisement
Add Comment
Please, Sign In to add comment