Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用tensorflow gpu进行预测比tensorflow cpu慢_Python_Tensorflow - Fatal编程技术网

Python 使用tensorflow gpu进行预测比tensorflow cpu慢

Python 使用tensorflow gpu进行预测比tensorflow cpu慢,python,tensorflow,Python,Tensorflow,下面是我的预测代码: 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)

下面是我的预测代码:

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时,所花费的时间应该更少

对于安装,我遵循链接

我使用的是英伟达GeForce GTX 1080 Ti

CPU是英特尔(R)核心(TM)i7-7700K CPU


型号是MobileNet_v1

您使用的是哪种GPU之王。据我所知,Tensorflow似乎针对->Nvidia进行了优化也许可以尝试
开始=时间.time()
在创建会话后(使用tf.session(graph=graph)作为sess:对我来说,使用gpu创建会话需要更多时间,但预测速度更快。 另外,您是否尝试过知名型号的gpu?我的意思是,这是您的gpu第一次性能不佳吗?

也许可以尝试使用VGG网络,您可以从中找到基准,并与您的gpu进行比较。如果您的gpu出现问题,请关注它,但这可能与您的型号有关有时型号在cpu上的性能要好得多

我使用Nvidia GeForce GTX 1080 Ti。这很奇怪。。。。。。。你的操作系统/驱动程序呢?还有,你的CPU是什么?(我的threadripper 1950X在许多高度并行化的工作中也比GPU工作得更好)驱动程序是驱动程序版本:384.130。操作系统是ubuntu-16。CPU是Intel(R)Core(TM)i7-7700K CPU@4.20GHZ,因此您使用的是专有软件。检查您是否有libcuda1-384。如果是这样的话,我就没有更多的俱乐部了。你能指导我如何检查吗?同样的结果,没有change@PratikKumar你有没有试过著名的型号,我的意思是,这是你的gpu第一次性能不好?也许可以尝试使用VGG网络,您可以从中找到基准,并与您的gpu进行比较。如果你的gpu出现了问题,请关注它,但可能是因为你的模型,有时模型在cpu上的性能要好得多。我正在运行mobilenet_v1upvote,支持在基准体系结构上测试的想法。因为,我使用的是mobilenet,它比其他架构更小,这就是为什么CPU可能更快的原因。GPU有一个CPU部分,用于提供图像。这很可能是瓶颈。GPU在等待图像的大部分时间里都处于理想状态。@vijaym要克服这个问题吗?是的,使用dataset API构建一个
输入数据管道
,将CPU上的数据加载部分和GPU上的数字处理并行化。检查: