首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用tensorflow的预测-gpu比tensorflow-cpu慢

使用tensorflow的预测-gpu比tensorflow-cpu慢
EN

Stack Overflow用户
提问于 2018-05-31 21:17:53
回答 2查看 1.6K关注 0票数 1

下面是我的预测代码:

start=time.time()
with tf.Session(graph=graph) as sess:
    predict('/home/4_bikes/test_images/bikerider4.jpg',sess)
    predict('/home/4_bikes/test_images/bikerider4.jpg',sess)
    predict('/home/4_bikes/test_images/bikerider4.jpg',sess)
    predict('/home/4_bikes/test_images/bikerider4.jpg',sess)
    predict('/home/4_bikes/test_images/bikerider4.jpg',sess)
    predict('/home/4_bikes/test_images/bikerider4.jpg',sess)
    predict('/home/4_bikes/test_images/bikerider4.jpg',sess)
    predict('/home/4_bikes/test_images/bikerider4.jpg',sess)
    predict('/home/4_bikes/test_images/bikerider4.jpg',sess)    
stop=time.time()
print('Time taken for prediction :: {}'.format(stop-start))

下面是我的predict函数:

def predict(file_name,sess):

  t = read_tensor_from_image_file(
      file_name,
      input_height=input_height,
      input_width=input_width,
      input_mean=input_mean,
      input_std=input_std)

  results = sess.run(output_operation.outputs[0], {
        input_operation.outputs[0]: t
    })
  results = np.squeeze(results)

  index=results.argmax()

  prediction=labels[index]
  bike_predictor = bike_classifier()
  if prediction == 'bikes':
    bike_predictor.predict(t)
  else:
    print('Predicted as :: unknown')

我在python-2上安装了tensorflow-gpu,在python-3上安装了tensorflow-cpu。当我用tensorflow-gpu运行它时,我得到:

Time taken for prediction :: 2.92091107368

当我使用tensorflow-cpu运行时,我得到:

Time taken for prediction :: 1.7942276000976562

我确信我使用的是GPU,因为当使用python-2运行时,我会得到日志:

name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.6705
pciBusID: 0000:01:00.0
totalMemory: 10.91GiB freeMemory: 10.28GiB
2018-05-31 18:23:26.762628: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0
2018-05-31 18:23:26.906629: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-05-31 18:23:26.906672: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929]      0 
2018-05-31 18:23:26.906679: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0:   N 
2018-05-31 18:23:26.906856: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 9949 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)

每次调用predict时。

有人能帮我一下吗?我哪里错了?当使用GPU时,花费的时间应该更少。

对于安装,我使用了this链接。

我使用的是Nvidia GeForce GTX1080 Ti

处理器为英特尔(R)酷睿(TM) i7-7700K CPU

型号为MobileNet_v1

EN

回答 2

Stack Overflow用户

发布于 2018-05-31 21:36:49

也许可以试着在为我创建会话(在with tf.Session(graph=graph) as sess:之后)之后把这段代码放在start=time.time()上,用gpu创建会话需要更多的时间,但预测速度很快。还有,你有没有尝试过知名的型号,我的意思是,这是你的gpu第一次表现不佳吗?

也许可以尝试使用VGG Nets,你可以从here中找出基准测试,并与你的图形处理器进行比较。如果您的gpu似乎有问题,请将注意力放在gpu上,但这可能与您的模型有关有时模型会在cpu上提供更好的性能

票数 1
EN

Stack Overflow用户

发布于 2018-05-31 21:20:31

您使用的是哪种GPU。据我所知,Tensorflow似乎针对cuda -> Nvidia进行了优化

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50625298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档