[英]Prediction with tensorflow-gpu is slower than tensorflow-cpu
以下是我的預測代碼:
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 時花費的時間應該更少。
對於安裝,我按照此鏈接進行操作。
我正在使用Nvidia GeForce GTX 1080 Ti 。
CPU 是Intel(R) Core(TM) i7-7700K CPU
模型為MobileNet_v1
也許嘗試start=time.time()
在創建會話后放置此代碼(在with tf.Session(graph=graph) as sess:
)對我來說,使用 gpu 創建會話需要更多時間,但可以快速進行預測。 您是否也嘗試過使用眾所周知的模型,我的意思是第一次您的 GPU 性能不佳?
也許嘗試使用 VGG Nets,您可以從這里找到基准並與您的 GPU 進行比較。 如果您的 gpu 似乎有問題,請關注它,但也許這與您的模型有關,有時模型會在 cpu 上提供更好的性能
你用的是什么GPU之王。 據我了解,Tensorflow 似乎針對cuda -> Nvidia 進行了優化
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.