首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在训练keras模型时,GPU的性能应该是多少?

在训练keras模型时,GPU的性能应该是多少?
EN

Stack Overflow用户
提问于 2020-05-05 09:28:51
回答 1查看 464关注 0票数 2

我在mnist数据集上使用RTX 2080 ti。我安装了tensrflow-gpu。在其他环境中,它比仅在CPU上运行快近12倍。

我正在检查任务管理器CPU和GPU的性能,同时训练。以下是培训期间的表演:

GPU环境: CPU =20% GPU = 10%训练时间=24秒

CPU环境: CPU =100% GPU = 10%训练时间= 500秒

我想知道GPU在10%上运行是否正常?我可以手动增加或降低性能吗?

EN

回答 1

Stack Overflow用户

发布于 2020-05-20 09:43:33

这取决于你的申请。GPU利用率低并不少见。尝试增加批处理大小以获得更多的利用率。

尽管如此,MNIST大小的网络很小,很难为它们实现高的GPU (或CPU)效率,我认为10%的利用率和CPU一起在您的应用程序中并不少见。您将获得更高的计算效率和更大的批处理大小,这意味着您可以处理更多的例子每秒,但您也将获得较低的统计效率,这意味着您需要处理更多的例子总数,以达到目标的准确性。所以这是一种交换。对于微型字符模型,统计效率在100之后会迅速下降,因此可能不值得尝试增加训练的批处理大小。为了进行推断,您应该使用尽可能大的批处理大小。

还可以将设备类型设置为在程序中使用。在您的情况下,强制您的程序只使用GPU和验证GPU利用率。

例如,在程序中只对model.fit使用GPU

代码语言:javascript
复制
%tensorflow_version 2.x
print(tf.__version__)
# MLP for Pima Indians Dataset saved to single file
import numpy as np
from numpy import loadtxt
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import model_from_json

# load pima indians dataset
dataset = np.loadtxt("/content/pima-indians-diabetes.csv", delimiter=",")

# split into input (X) and output (Y) variables
X = dataset[:,0:8]
Y = dataset[:,8]

# define model
model = Sequential()
model.add(Dense(12, input_dim=8, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

# compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

# Model Summary
model.summary()

# Fit the model
with tf.device("/device:GPU:0"):
  model.fit(X, Y, epochs=150, batch_size=10, verbose=0)

# evaluate the model
scores = model.evaluate(X, Y, verbose=0)
print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))

产出-

代码语言:javascript
复制
2.2.0
Model: "sequential_6"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_18 (Dense)             (None, 12)                108       
_________________________________________________________________
dense_19 (Dense)             (None, 8)                 104       
_________________________________________________________________
dense_20 (Dense)             (None, 1)                 9         
=================================================================
Total params: 221
Trainable params: 221
Non-trainable params: 0
_________________________________________________________________
accuracy: 78.39%

希望这能回答你的问题。学习愉快。

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

https://stackoverflow.com/questions/61609913

复制
相关文章

相似问题

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