Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.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

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 培训keras模型时,GPU性能应该是多少?_Python_Tensorflow_Keras_Gpu - Fatal编程技术网

Python 培训keras模型时,GPU性能应该是多少?

Python 培训keras模型时,GPU性能应该是多少?,python,tensorflow,keras,gpu,Python,Tensorflow,Keras,Gpu,我在mnist数据集上使用RTX 2080 ti。我已经安装了tensrflow gpu。它的速度几乎是其他环境中仅在CPU上运行的速度的12倍 我在培训时检查任务管理器CPU和GPU性能。 以下是培训期间的表现: GPU环境:CPU=20%GPU=10%训练时间=24秒 CPU环境:CPU=100%GPU=10%训练时间=500秒 我想知道GPU在10%上运行是否正常?我可以手动提高性能还是降低性能 这取决于您的应用程序。GPU利用率低并不罕见。尝试增加批处理大小以提高利用率 尽管如此,MNI

我在mnist数据集上使用RTX 2080 ti。我已经安装了tensrflow gpu。它的速度几乎是其他环境中仅在CPU上运行的速度的12倍

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

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

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


我想知道GPU在10%上运行是否正常?我可以手动提高性能还是降低性能

这取决于您的应用程序。GPU利用率低并不罕见。尝试增加批处理大小以提高利用率

尽管如此,MNIST大小的网络很小,很难为它们实现高GPU(或CPU)效率,我认为10%的利用率以及CPU对于您的应用程序来说并不罕见。批量越大,计算效率越高,这意味着每秒可以处理更多的示例,但统计效率也会降低,这意味着需要处理更多的示例才能达到目标精度。因此,这是一种权衡。对于微小的角色模型,统计效率在100后会很快下降,因此可能不值得尝试增加训练的批量大小。为了进行推断,您应该使用可以使用的最大批量

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

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

%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))
输出-

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%

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

如果您只是在CPU上进行培训,那么在培训期间不应该使用GPU,您的GPU被用于其他目的。@osamub-希望我们已经回答了您的问题。如果你对答案感到满意,请接受并投票。