tensorflow 文件队列

使用文件队列,防止爆内存

# # 通过队列打开图片文件
    file_queue = tf.train.string_input_producer(paths)
    img_reader = tf.WholeFileReader()
    key, value = img_reader.read(file_queue)
    img = tf.image.decode_jpeg(value)
    with tf.Session() as sess:
        coord = tf.train.Coordinator()  # 协同启动线程
        threads = tf.train.start_queue_runners(sess,coord)  # 启动线程运行队列
        images = []

        for _ in paths:
            cv2.imshow('frame', img.eval())
            cv2.waitKey(20)
            images.append(img.eval())
        images = np.array(images)
        print(images.shape)
        coord.request_stop()  # 停止所有线程
        coord.join(threads)

 

posted on 2019-01-23 10:18  天下无槛,不服就干  阅读(163)  评论(0编辑  收藏  举报

导航