gpt4 book ai didi

在 vgg16 架构上,tensorflow 比 pytorch 慢 2.5 倍

转载 作者:行者123 更新时间:2023-12-03 16:44:55 24 4
gpt4 key购买 nike

所以我正在尝试进入 tensorflow 并到目前为止喜欢它。

今天升级到cuda 8、cudnn 5.1和tensorflow 0.12.1。使用 Maxwell Titan X GPU。

使用以下加载预训练 vgg16 的简短代码:

import tensorflow as tf
from tensorflow.contrib import slim
from tensorflow.contrib.slim import nets

tf.reset_default_graph()
input_images = tf.placeholder(tf.float32, [None, 224, 224, 3], 'image')
preds = nets.vgg.vgg_16(input_images, is_training=False)[0]
saver = tf.train.Saver()

config = tf.ConfigProto(log_device_placement=True,
gpu_options=tf.GPUOptions(per_process_gpu_memory_fraction = 0.5))
sess = tf.InteractiveSession(config=config)
saver.restore(sess, './vgg_16.ckpt')

_in = np.random.randn(16, 224, 224, 3).astype(np.float32)

然后我为前向传球计时:

%timeit sess.run(preds, feed_dict={input_images: _in})

根据 this benchmark,我每批处理 160 毫秒(仅前向传递),这似乎比 torch 中的相应配置慢 2.5 倍(也比 MatconvNet 慢)。

这些操作似乎已正确分配给 gpu,并且正确找到了 cuda 库,我还缺少什么?

编辑:cudnn 和 cuda 正确找到

I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so locally
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties:
name: GeForce GTX TITAN X
major: 5 minor: 2 memoryClockRate (GHz) 1.076
pciBusID 0000:04:00.0
Total memory: 11.92GiB
Free memory: 11.81GiB

此外,喂食似乎不是问题,因为将 input_images 替换为 tf.random_uniform((16, 224, 224, 3), maxval=255) 确实不改变时间。

编辑 2:所以我比较了在同一台机器上运行的 pytorch 版本,我得到(16x224x224x3 的批处理):

  • Resn​​et-50:pytorch 48 毫秒 对比 tf 58 毫秒(好)
  • VGG16:pytorch 65ms vs tf 160ms(不正常)

最佳答案

最近在 cuda 9.0、tensorflow 1.9 和 pytorch 0.4.1 上进行了测试,对于相同的操作,差异现在可以忽略不计。

参见 the proper timing here .

关于在 vgg16 架构上,tensorflow 比 pytorch 慢 2.5 倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41832779/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com