zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然 pythonTensorFlow图形数据处理:队列操作

    import tensorflow as tf
    
    #1. 创建队列,并操作里面的元素。
    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
    
    #2. 这个程序每隔1秒判断是否需要停止并打印自己的ID。
    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))
                
    #3. 创建、启动并退出线程。
    coord = tf.train.Coordinator()
    threads = [threading.Thread(target=MyLoop, args=(coord, i, )) for i in range(6)]
    for t in threads:
        t.start()
    coord.join(threads)

  • 相关阅读:
    hadoop2.3.0cdh5.0.2 升级到cdh5.7.0
    strace
    ganglia3.7.2,web3.7.1安装
    hadoop balancer
    linux-小命令
    Ceph 架构以及原理分析
    Ceph 文件存储
    Ceph 对象存储
    Ceph 块存储
    Ceph 集群搭建
  • 原文地址:https://www.cnblogs.com/tszr/p/12067134.html
Copyright © 2011-2022 走看看