【发布时间】:2017-09-04 20:22:31
【问题描述】:
Tensorflow tf.subtract 对于大型数组来说花费的时间太长。
我的工作站配置:
CPU:至强 E5 2699 v3
内存:384 GB
显卡:NVIDIA K80
CUDA:8.5
CUDNN:5.1
TensorFlow:1.1.0,GPU 版本
以下是测试代码和结果。
import tensorflow as tf
import numpy as np
import time
W=3000
H=4000
in_a = tf.placeholder(tf.float32,(W,H))
in_b = tf.placeholder(tf.float32,(W,H))
def test_sub(number):
sess=tf.Session()
out = tf.subtract(in_a,in_b)
for i in range(number):
a=np.random.rand(W,H)
b=np.random.rand(W,H)
feed_dict = {in_a:a,
in_b:b}
t0=time.time()
out_ = sess.run(out,feed_dict=feed_dict)
t_=(time.time()-t0) * 1000
print "index:",str(i), " total time:",str(t_)," ms"
test_sub(20)
结果:
索引:0 总时间:338.145017624 毫秒
索引:1 总时间:137.024879456 毫秒
索引:2 总时间:132.538080215 毫秒
索引:3 总时间:133.152961731 毫秒
索引:4 总时间:132.885932922 毫秒
索引:5 总时间:135.06102562 毫秒
索引:6 总时间:136.723041534 毫秒
索引:7 总时间:137.926101685 毫秒
索引:8 总时间:133.605003357 毫秒
索引:9 总时间:133.143901825 毫秒
索引:10 总时间:136.317968369 毫秒
索引:11 总时间:137.830018997 毫秒
索引:12 总时间:135.458946228 毫秒
索引:13 总时间:132.793903351 毫秒
索引:14 总时间:144.603967667 毫秒
索引:15 总时间:134.593963623 毫秒
索引:16 总时间:135.535001755 毫秒
索引:17 总时间:133.697032928 毫秒
索引:18 总时间:136.134147644 毫秒
索引:19 总时间:133.810043335 毫秒
测试结果表明(即tf.subtract)处理一次3000x4000的减法耗时超过130毫秒,显然太长了,尤其是在NVIDIA k80 GPU平台上。
谁能提供一些优化 tf.subtract 的方法? 提前致谢。
【问题讨论】:
标签: tensorflow