【发布时间】:2017-07-09 08:40:21
【问题描述】:
我已经使用 tensorflow API 运行了一个图像处理脚本。事实证明,当我在会话运行过程之外设置 for-loop 时,处理时间迅速减少。谁能告诉我为什么?有没有副作用?
原代码:
with tf.Session() as sess:
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in range(len(file_list)):
start = time.time()
image_crop, bboxs_crop = sess.run(crop_image(file_list[i], bboxs_list[i], sess))
print( 'Done image %d th in %d ms \n'% (i, ((time.time() - start)*1000)))
# image_crop, bboxs_crop, image_debug = sess.run(crop_image(file_list[i], bboxs_list[i], sess))
labels, bboxs = filter_bbox(labels_list[i], bboxs_crop)
# Image._show(Image.fromarray(np.asarray(image_crop)))
# Image._show(Image.fromarray(np.asarray(image_debug)))
save_image(image_crop, ntpath.basename(file_list[i]))
#save_desc_file(file_list[i], labels_list[i], bboxs_crop)
save_desc_file(file_list[i], labels, bboxs)
coord.request_stop()
coord.join(threads)
修改的代码:
for i in range(len(file_list)):
with tf.Graph().as_default(), tf.Session() as sess:
start = time.time()
image_crop, bboxs_crop = sess.run(crop_image(file_list[i], bboxs_list[i], sess))
print( 'Done image %d th in %d ms \n'% (i, ((time.time() - start)*1000)))
labels, bboxs = filter_bbox(labels_list[i], bboxs_crop)
save_image(image_crop, ntpath.basename(file_list[i]))
save_desc_file(file_list[i], labels, bboxs)
原始代码中的时间成本会不断增加,从 200 毫秒增加到 20000 毫秒。修改后的日志信息显示有不止一个图,并且在运行过程中创建了tensorflow设备,这是为什么呢?
python random_crop_images_hongyuan.py 我 tensorflow/stream_executor/dso_loader.cc:135]成功打开CUDA 本地库 libcublas.so.8.0 我 tensorflow/stream_executor/dso_loader.cc:135]成功打开CUDA 本地库 libcudnn.so.5 我 tensorflow/stream_executor/dso_loader.cc:135]成功打开CUDA 本地库 libcufft.so.8.0 我 tensorflow/stream_executor/dso_loader.cc:135]成功打开CUDA 本地库 libcuda.so.1 我 tensorflow/stream_executor/dso_loader.cc:135]成功打开CUDA 本地库 libcurand.so.8.0 W tensorflow/core/platform/cpu_feature_guard.cc:45] TensorFlow 库未编译为使用 SSE3 指令,但这些是 在您的机器上可用,并且可以加快 CPU 计算速度。 W tensorflow/core/platform/cpu_feature_guard.cc:45] TensorFlow 库未编译为使用 SSE4.1 指令,但这些是 在您的机器上可用,并且可以加快 CPU 计算速度。 W tensorflow/core/platform/cpu_feature_guard.cc:45] TensorFlow 库未编译为使用 SSE4.2 指令,但这些是 在您的机器上可用,并且可以加快 CPU 计算速度。 W tensorflow/core/platform/cpu_feature_guard.cc:45] TensorFlow 库未编译为使用 AVX 指令,但这些是 在您的机器上可用,并且可以加快 CPU 计算速度。 W tensorflow/core/platform/cpu_feature_guard.cc:45] TensorFlow 库未编译为使用 AVX2 指令,但这些是 在您的机器上可用,并且可以加快 CPU 计算速度。 W tensorflow/core/platform/cpu_feature_guard.cc:45] TensorFlow 库未编译为使用 FMA 指令,但这些是 在您的机器上可用,并且可以加快 CPU 计算速度。一世 tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:910] 成功 从 SysFS 读取的 NUMA 节点具有负值 (-1),但必须有 至少一个 NUMA 节点,所以返回 NUMA 节点零 I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] 找到设备 0 具有属性:名称:GeForce GT 730M 主要:3 次要:5 memoryClockRate (GHz) 0.758 pciBusID 0000:01:00.0 总内存: 982.88MiB 可用内存:592.44MiB I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA:0 I 张量流/核心/common_runtime/gpu/gpu_device.cc:916] 0:是我 tensorflow/core/common_runtime/gpu/gpu_device.cc:975] 创建 TensorFlow 设备 (/gpu:0) -> (设备: 0, 名称: GeForce GT 730M, pci bus id: 0000:01:00.0) 在 317 毫秒内完成第 3000 张图像
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] 创建 TensorFlow 设备 (/gpu:0) -> (设备: 0, 名称: GeForce GT 730M, pci 总线 ID:0000:01:00.0)在 325 毫秒内完成第 3001 个图像
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] 创建 TensorFlow 设备 (/gpu:0) -> (设备: 0, 名称: GeForce GT 730M, pci bus id: 0000:01:00.0) 在 312 毫秒内完成第 3002 个图像
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] 创建 TensorFlow 设备 (/gpu:0) -> (设备: 0, 名称: GeForce GT 730M, pci 总线 ID:0000:01:00.0)在 147 毫秒内完成第 3003 个图像
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] 创建 TensorFlow 设备 (/gpu:0) -> (设备: 0, 名称: GeForce GT 730M, pci bus id: 0000:01:00.0) 在 447 毫秒内完成第 3004 个图像
【问题讨论】:
标签: tensorflow