首页 > 编程语言 > 详细

吴裕雄 python 神经网络——TensorFlow 队列操作

时间:2019-05-18 13:10:51      阅读:104      评论:0      收藏:0      [点我收藏+]
import tensorflow as tf

q = tf.FIFOQueue(2, "int32")
init = q.enqueue_many(([0, 10],))
x = q.dequeue()
y = x + 1
q_inc = q.enqueue([y])
with tf.Session() as sess:
    init.run()
    for _ in range(5):
        v, _ = sess.run([x, q_inc])
        print(v)

技术分享图片

import time
import threading
import numpy as np

def MyLoop(coord, worker_id):
    while not coord.should_stop():
        if np.random.rand()<0.1:
            print("Stoping from id: %d\n" % worker_id,coord.request_stop())
        else:
            print("Working on id: %d\n" % worker_id, time.sleep(1))
coord = tf.train.Coordinator()
threads = [threading.Thread(target=MyLoop, args=(coord, i, )) for i in xrange(5)]
for t in threads:
    t.start()
coord.join(threads)

技术分享图片

 

吴裕雄 python 神经网络——TensorFlow 队列操作

原文:https://www.cnblogs.com/tszr/p/10885370.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!