Python Tensorflow-读取TFRecord时内存泄漏(或其他)

Python Tensorflow-读取TFRecord时内存泄漏(或其他),python,machine-learning,memory-leaks,tensorflow,Python,Machine Learning,Memory Leaks,Tensorflow,我正在研究tensorflow中的一些CNN模型,但我有一个与数据读取相关的问题 我有一个文件,一个TFRecord文件,使用GZIP压缩,我想批量读取这个文件中的数据,我设置了下一个代码: def _input_fn( files ): print( files ) thread_count = multiprocessing.cpu_count() batch_size = 2 # for debug num_epochs =

我正在研究tensorflow中的一些CNN模型,但我有一个与数据读取相关的问题

我有一个文件,一个TFRecord文件,使用GZIP压缩,我想批量读取这个文件中的数据,我设置了下一个代码:

 def _input_fn( files ):
        print( files )
        thread_count = multiprocessing.cpu_count()
        batch_size = 2 # for debug
        num_epochs = 2 
        min_after_dequeue = 1000

        queue_size_multiplier = thread_count + 3

        filename_queue = tf.train.string_input_producer( files , num_epochs = num_epochs )

        example_id , encoded_examples = tf.TFRecordReader(
            options = tf.python_io.TFRecordOptions  (
                compression_type= TFRecordCompressionType.GZIP
            )
        ).read_up_to( filename_queue , batch_size)
        features, targets = example_parser(encoded_examples )
        capacity = min_after_dequeue + queue_size_multiplier

        images , labels = tf.train.shuffle_batch(
            [features , targets ] , batch_size , num_threads = thread_count ,
            capacity = capacity , min_after_dequeue = min_after_dequeue ,
            enqueue_many = True 
        )

        return images , labels 
读取TFR记录的常用代码。然后我创建了一个测试图,而不是实际的NN,用于测试

inputs, labels = _inpunt_fn(files )
# the shape of the tensors returned by _input_fn is correct. [batch_size ,150*150*150      ]
ss = inputs + 1 # some computation  
init_op = tf.group(tf.global_variables_initializer(),
                   tf.local_variables_initializer())

sess = tf.Session()

sess.run( init_op  )

coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
# i cut some things to make it shorter ... 
while not coord.should_stop():
    sess.run( [ ss ] )
    print(" test ")
我运行这段代码,却从来没有看到“测试”打印出来。该程序使我的电脑崩溃。我使用“top”命令观察内存使用情况,它会快速增长,直到程序和电脑中的所有内容崩溃

数据集很大。每个样本是一个3d矩阵(150 x 150 x 150),共有1000个样本。但我(理论上)并没有把它载入内存,我只是一小批地阅读,对吗,那么为什么会发生这种情况。。。我读取文件的方式有什么问题,如何解决


先谢谢你。欢迎有任何见解

您可能会从输入管道中使用的内部队列中看到额外的内存使用。如果你使用tf.data,你能看到同样的问题吗?