添加新的队列运行器会导致程序过早退出

普里雅坦

我有一个包含图像的目录和另一个包含标签文件的目录(对于每个图像)。我正在尝试使用队列和读取操作读取图像和标签。

image_file_queue = tf.train.string_input_producer(image_files, num_epochs=1, shuffle=False)

image_reader = tf.WholeFileReader()
image_contents = image_reader.read(image_file_queue)[1]

image = tf.image.decode_jpeg(image_contents, channels=3)
image = tf.image.resize_images(image, [image_size, image_size])

image_batch = tf.train.batch([image],
                             batch_size,
                             num_threads=4,
                             capacity=2 * batch_size,
                             allow_smaller_final_batch=True)

label_file_queue = tf.train.string_input_producer(label_files, num_epochs=1, shuffle=False)
label_reader = tf.WholeFileReader()
label_contents = tf.string_split([label_reader.read(label_file_queue)[1]], delimiter='\n').values

labels = tf.decode_csv(label_contents, [tf.constant([], dtype=tf.float32)] * 5, field_delim=' ')
label_queue = tf.FIFOQueue(2 * batch_size, [tf.float32])

enqueue_op = label_queue.enqueue([labels])

label_queue_runner = tf.train.QueueRunner(label_queue, enqueue_ops=[enqueue_op] * 2)
tf.train.add_queue_runner(label_queue_runner)

coord = tf.train.Coordinator()
sess.run(tf.group(tf.local_variables_initializer(), tf.global_variables_initializer()))

threads = tf.train.start_queue_runners(sess=sess, coord=coord)

然而这行不通。在此之后立即coord.should_stop()返回True评论tf.train.add_queue_runner(...)确实有效,也就是说,image_batch是经过计算的,我可以通过 CNN 运行它。如果我不评论它,它image_batch似乎比它应该的要小(batch_size是 128,但image_batch.eval().shape可以小到 8)。我认为这可能是由于线程不足造成的,但是增加两者inter_op_parallelism_threadsintra_op_parallelism_threads不能解决这个问题。

普里雅坦

jkschin 是对的。图像阅读器的数量只有一个,num_threads64 个不会改变这一点。并且由于image_batch不能足够快地填充,程序在image_batch出队且为空时过早停止

解决这个问题的正确方法是增加图像阅读器的数量(多个相同的子图),如阅读数据中所述

image_list = [read_image(image_file_dequeue) for _ in range(num_readers)]
image_batch = tf.train.batch_join(image_list, ...)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法启动服务Prometheus:oci运行时错误:container_linux.go:235:启动容器进程导致“容器初始化过早退出”

由于postharp错误,构建失败:管道服务器过早退出,退出代码为1

WSL2 互操作问题导致过早退出 shell 脚本中的读取循环

子节点“ 2”过早退出

输入回路过早退出

Shell脚本:While循环过早退出

Android应用程式过早退出

递归函数不会过早退出

如何修复我的代码,以免过早退出?

如何过早退出std.algorithm.iteration.reduce?

Curl_multi在文件下载时过早退出

Bash 脚本循环在 If 语句上过早退出

如何过早退出 __enter__ 并跳过 Python 中的 with 块?

使用Docker绑定安装器运行容器会导致容器返回Node版本并退出

为什么在任务运行时添加Console.CancelKeyPress处理程序会阻止调试器CTRL + C退出

为什么我的并发函数在Go中过早退出?

任务主机节点过早退出错误。日志文件位置

TFS上的HeatDirectory故障,出现MSBUILD错误MSB4166:子节点“ 3”过早退出

Django celery WorkerLostError:Worker 过早退出:信号 9(SIGKILL)错误

MSB4166的间歇性构建中断:子节点“#”过早退出。VS 15.9

set -e和grep惯用法防止未找到模式时从shell脚本过早退出

VB.NET For Each循环过早退出/代码在完成之前返回给调用方

添加 if 条件会退出电话管理器中的 android 应用程序

如何使用队列运行器退出 TensorFlow 会话

即使活动退出后,处理程序可运行也会运行

为什么添加选择器标签会导致Web应用程序冻结?

zsh,同时使用浮点算法在三层嵌套循环中过早退出循环

导入zbar会导致python以退出代码139退出-在运行10.9的Mac上,这可能导致什么呢?

添加C ++插件会导致打包的应用程序崩溃,但是如果我运行“ yarn start”,它会起作用