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


    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
    " % worker_id,coord.request_stop())
            else:
                print("Working on id: %d
    " % 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)

  • 相关阅读:
    作业三
    作业二
    4.9上机作业
    4.2Java
    Java作业
    第四周上级作业
    第三周作业
    第一次上机练习
    [ZJOI2009]假期的宿舍
    [ZJOI2007]矩阵游戏
  • 原文地址:https://www.cnblogs.com/tszr/p/10885370.html
Copyright © 2020-2023  润新知