tensorflow随笔-队列(11)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010255642/article/details/82767328
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Sep  6 10:16:37 2018
@author: myhaspl
@email:[email protected]
"""
 
import tensorflow as tf
import numpy as np
 
q=tf.RandomShuffleQueue(capacity=200,min_after_dequeue=2,dtypes="float")
x=np.random.randint(100,size=10)
enqueue_op=q.enqueue([x])
 

init=tf.global_variables_initializer()
qr=tf.train.QueueRunner(q,enqueue_ops=[enqueue_op]*1)
#主线程
with tf.Session() as sess: 
    sess.run(init)
    coord=tf.train.Coordinator()#协调器,协调线程间的关系。
    enqueue_threads=qr.create_threads(sess,coord=coord,start=True)#启动入队线程
    for i in range(0,10):
        print sess.run(q.dequeue())
    coord.request_stop()#通知其它线程关闭
    coord.join(enqueue_threads)#关闭其它线程后,合并到主线程
 
 
    
 
    
[69. 16. 50. 50. 50. 76. 25. 75. 58. 77.]
[69. 16. 50. 50. 50. 76. 25. 75. 58. 77.]
[69. 16. 50. 50. 50. 76. 25. 75. 58. 77.]
[69. 16. 50. 50. 50. 76. 25. 75. 58. 77.]
[69. 16. 50. 50. 50. 76. 25. 75. 58. 77.]
[69. 16. 50. 50. 50. 76. 25. 75. 58. 77.]
[69. 16. 50. 50. 50. 76. 25. 75. 58. 77.]
[69. 16. 50. 50. 50. 76. 25. 75. 58. 77.]
[69. 16. 50. 50. 50. 76. 25. 75. 58. 77.]
[69. 16. 50. 50. 50. 76. 25. 75. 58. 77.]

猜你喜欢

转载自blog.csdn.net/u010255642/article/details/82767328
今日推荐