daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. v_dimen = 300
  2. n_samples = 10000
  3. batch_size = 32
  4. X = tf.random_normal([n_samples, v_dimen], mean=0, stddev=1)
  5. Y = tf.random_normal([n_samples, 1], mean=0, stddev=1)
  6.  
  7. q_in = tf.FIFOQueue(capacity=5, dtypes=tf.float32) # enqueue 5 batches
  8. enqueue_op = q_in.enqueue(X)
  9. numberOfThreads = 1
  10. qr = tf.train.QueueRunner(q_in, [enqueue_op] * numberOfThreads)
  11. tf.train.add_queue_runner(qr)
  12. X_batch = q_in.dequeue()    
  13.  
  14. q_out = tf.FIFOQueue(capacity=5, dtypes=tf.float32)  # enqueue 5 batches
  15. enqueue_op = q_out.enqueue(Y)
  16. numberOfThreads = 1
  17. qr = tf.train.QueueRunner(q_out, [enqueue_op] * numberOfThreads)
  18. tf.train.add_queue_runner(qr)
  19. Y_batch = q_out.dequeue()
  20.  
  21. W = tf.Variable(tf.random.truncated_normal((v_dimen, 1), mean=0.0,stddev=0.001))
  22. predicted_Y = f(X_batch) # some function on X, like tf.matmul(X_batch,W)
  23. loss = tf.nn.l2_loss(Y_batch - predicted_Y)
  24. optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01).minimize(loss, var_list=[W])
  25. init = tf.global_variables_initializer()
  26.  
  27. with tf.Session() as sess:
  28.     sess.run(init)
  29.     coord = tf.train.Coordinator()
  30.     threads = tf.train.start_queue_runners(coord=coord)
  31.     for i in range(1000):
  32.         sess.run([optimizer]) # would like to run on mini batches
  33.  
  34.     coord.request_stop()
  35.     coord.join(threads)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top