GPU 的预测比 CPU 慢得多?

时间:2020-12-18 17:59:57

标签: tensorflow keras

奇怪的是,我刚刚发现我的 CPU 的预测速度要快得多。 使用 GPU 进行推理比使用 CPU 慢得多。

我有一个带有简单密集层的 tf.keras (tf2) NN 模型:

input = tf.keras.layers.Input(shape=(100,), dtype='float32')
X = X = tf.keras.layers.Dense(2)(input)
model = tf.keras.Model(input,X)

#also initiialized with weights from a file
weights = np.load("weights.npy", allow_pickle=True )
model.layers[-1].set_weights(weights)

scores = model.predict_on_batch(data)

对于 100 个样本进行预测,我得到:

2 s for GPU
0.07 s for CPU (!)

我使用的是带有 2gb 的简单 geforce mx150

我也尝试了 predict_on_batch(x),因为有人建议这样做,因为它比预测更快。但这里是同一时间。

参考:Why does keras model predict slower after compile?

有没有人知道,那里发生了什么?可能是什么问题?

0 个答案:

没有答案