为什么我的keras/tensorflow不使用GPU
我看过其他一些关于stackoverflow的帖子,但似乎没有任何帮助。我只安装了tensorflow gpu版本和keras 我检查了gpu是否被识别,它是:为什么我的keras/tensorflow不使用GPU,keras,tensorflow-gpu,Keras,Tensorflow Gpu,我看过其他一些关于stackoverflow的帖子,但似乎没有任何帮助。我只安装了tensorflow gpu版本和keras 我检查了gpu是否被识别,它是: print(device_lib.list_local_devices()) print('Tensorflow: ', tf.__version__) 出去 但是当我用TysFROW后端运行KARAS模型时,它看起来并没有比在英伟达CPU上运行我的另一台计算机时更快速,没有NVIDIA。同时看看任务管理器,我看到了CPU使用率的峰值
print(device_lib.list_local_devices())
print('Tensorflow: ', tf.__version__)
出去
<>但是当我用TysFROW后端运行KARAS模型时,它看起来并没有比在英伟达CPU上运行我的另一台计算机时更快速,没有NVIDIA。同时看看任务管理器,我看到了CPU使用率的峰值。我对这一点还不熟悉,并试图弄清楚这一切,但模型/训练是否应该运行得更快?如果使用GPU,我应该不会看到CPU使用率的上升吗
如果有人能帮忙,我们将不胜感激。我按照所有步骤安装tensorflow gpu、CUDA、cudnn等
以下是我所拥有的:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 387.92 Driver Version: 387.92 |
|-------------------------------+----------------------+----------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| 0 GeForce GTX 1070 WDDM | 00000000:01:00.0 On | N/A |
| N/A 49C P8 9W / N/A | 7028MiB / 8192MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
| 0 3740 C C:\Users\Jason\Anaconda3\pythonw.exe N/A |
| 0 3968 C+G ...dows.Cortana_cw5n1h2txyewy\SearchUI.exe N/A |
| 0 4392 C+G C:\Windows\explorer.exe N/A |
| 0 7760 C+G ...0.0_x64__8wekyb3d8bbwe\WinStore.App.exe N/A |
| 0 8976 C+G ...6)\Google\Chrome\Application\chrome.exe N/A |
| 0 9932 C+G ...rosoft Office\root\Office16\WINWORD.EXE N/A |
| 0 12632 C+G Insufficient Permissions N/A |
| 0 14168 C+G Insufficient Permissions N/A |
| 0 14548 C+G ...t_cw5n1h2txyewy\ShellExperienceHost.exe N/A |
| 0 15648 C+G Insufficient Permissions N/A |
+-----------------------------------------------------------------------------+
在培训时:
C:\Program Files\NVIDIA Corporation\NVSMI>nvidia-smi
Fri Oct 13 13:18:23 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 387.92 Driver Version: 387.92 |
|-------------------------------+----------------------+----------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| 0 GeForce GTX 1070 WDDM | 00000000:01:00.0 On | N/A |
| N/A 51C P2 34W / N/A | 7126MiB / 8192MiB | 15% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
| 0 3740 C C:\Users\Jason\Anaconda3\pythonw.exe N/A |
| 0 3968 C+G ...dows.Cortana_cw5n1h2txyewy\SearchUI.exe N/A |
| 0 4392 C+G C:\Windows\explorer.exe N/A |
| 0 7760 C+G ...0.0_x64__8wekyb3d8bbwe\WinStore.App.exe N/A |
| 0 8976 C+G ...6)\Google\Chrome\Application\chrome.exe N/A |
| 0 9932 C+G ...rosoft Office\root\Office16\WINWORD.EXE N/A |
| 0 12632 C+G Insufficient Permissions N/A |
| 0 14168 C+G Insufficient Permissions N/A |
| 0 14548 C+G ...t_cw5n1h2txyewy\ShellExperienceHost.exe N/A |
| 0 15648 C+G Insufficient Permissions N/A |
+-----------------------------------------------------------------------------+
蟒蛇3.6;
Tensorflow gpu 1.3
import numpy as np
from keras import models
from keras import layers
from keras.wrappers.scikit_learn import KerasRegressor
from sklearn.model_selection import GridSearchCV
import datetime
# Set random seed
np.random.seed(7)
# Create function returning a compiled network
def create_network(optimizer='adam',activation='relu'):
# Start neural network
network = models.Sequential()
# Add fully connected layer with a ReLU activation function
network.add(layers.Dense(units=dim, activation=activation, input_shape=(dim,)))
# Add fully connected layer with a ReLU activation function
network.add(layers.Dense(units=20, activation=activation))
# Add fully connected layer with a sigmoid activation function
network.add(layers.Dense(units=1, activation='linear'))
# Compile neural network
network.compile(loss='mse', #
optimizer=optimizer, # Optimizer
metrics=['mae']) # Accuracy performance metric
# Return compiled network
return network
# Wrap Keras model so it can be used by scikit-learn
neural_network = KerasRegressor(build_fn=create_network, verbose=2)
# Create hyperparameter space
epochs = [5, 50, 100, 150]
batches = [1, 5, 10, 100]
# Create hyperparameter options
hyperparameters = dict(epochs=epochs, batch_size=batches)
# Time the process
start_time = datetime.datetime.now()
# Create grid search
grid = GridSearchCV(estimator=neural_network, param_grid=hyperparameters)
# Fit grid search
grid_result = grid.fit(X, Y)
# View hyperparameters of best neural network
grid_result.best_params_
# summarize results
print("Best: %f using %s" % (grid_result.best_score_,
grid_result.best_params_))
means = grid_result.cv_results_['mean_test_score']
stds = grid_result.cv_results_['std_test_score']
params = grid_result.cv_results_['params']
for mean, stdev, param in zip(means, stds, params):
print("%f (%f) with: %r" % (mean, stdev, param))
end_time = datetime.datetime.now()
processing_time = end_time - start_time
print(str(processing_time).split('.')[0])
更新2:
我一直在寻找答案,也许找到了什么…也许这就是原因。。。有人能证明谁知道的比我多吗
我正在使用scikit学习实现GridSearchCV。即使我在tensorflow后端使用keras,scikit learn也不使用GPU,这可能是原因吗?因此,除非我独家使用keras,否则我不会看到GPU启动?当您进行培训时,
nvidia smi
的输出是什么?好的,我知道了如何看到nvidia smi(就像我说的,我是新手)。因此,它在训练时显示出0%到15%的差异。但是它的运行速度并没有明显加快。你有没有考虑过这个模型可能太小而无法从GPU加速中获益?Matias,我没有考虑过这一点。我一直将数据过滤(因为它无法处理所有数据,所以将数据过滤成更小的大小。我还试图看看过滤是否会改进模型)。但由于对TF的使用还不熟悉,只是不知道会发生什么。但是,如果你有经验,并且说如果两个(CPU和GPU)上的型号没有显著的差异,那么这就是为什么我在这里问。。。因此,我将尝试扩展它以看到不同之处。当我设想GPU将完成大部分工作时,我突然发现CPU利用率急剧上升。@chitown88我们还没有看到你的模型,所以我说的只是一个假设。
import numpy as np
from keras import models
from keras import layers
from keras.wrappers.scikit_learn import KerasRegressor
from sklearn.model_selection import GridSearchCV
import datetime
# Set random seed
np.random.seed(7)
# Create function returning a compiled network
def create_network(optimizer='adam',activation='relu'):
# Start neural network
network = models.Sequential()
# Add fully connected layer with a ReLU activation function
network.add(layers.Dense(units=dim, activation=activation, input_shape=(dim,)))
# Add fully connected layer with a ReLU activation function
network.add(layers.Dense(units=20, activation=activation))
# Add fully connected layer with a sigmoid activation function
network.add(layers.Dense(units=1, activation='linear'))
# Compile neural network
network.compile(loss='mse', #
optimizer=optimizer, # Optimizer
metrics=['mae']) # Accuracy performance metric
# Return compiled network
return network
# Wrap Keras model so it can be used by scikit-learn
neural_network = KerasRegressor(build_fn=create_network, verbose=2)
# Create hyperparameter space
epochs = [5, 50, 100, 150]
batches = [1, 5, 10, 100]
# Create hyperparameter options
hyperparameters = dict(epochs=epochs, batch_size=batches)
# Time the process
start_time = datetime.datetime.now()
# Create grid search
grid = GridSearchCV(estimator=neural_network, param_grid=hyperparameters)
# Fit grid search
grid_result = grid.fit(X, Y)
# View hyperparameters of best neural network
grid_result.best_params_
# summarize results
print("Best: %f using %s" % (grid_result.best_score_,
grid_result.best_params_))
means = grid_result.cv_results_['mean_test_score']
stds = grid_result.cv_results_['std_test_score']
params = grid_result.cv_results_['params']
for mean, stdev, param in zip(means, stds, params):
print("%f (%f) with: %r" % (mean, stdev, param))
end_time = datetime.datetime.now()
processing_time = end_time - start_time
print(str(processing_time).split('.')[0])