我有一台配备 RTX 2060 GPU 的笔记本电脑,我使用 Keras 和 TF 2 在其上训练 LSTM。我还通过以下方式监控 GPU 使用情况nvidia-smi
我注意到 jupyter 笔记本和 TF 的使用率最多为 35%,而 GPU 通常使用率在 10-25% 之间。
以目前的条件,训练这个模型花了7个多小时,我想知道是我做错了什么还是Keras和TF的限制?
我的 nvidia-smi 输出:
Sun Nov 3 00:07:37 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 430.26 Driver Version: 430.26 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce RTX 2060 Off | 00000000:01:00.0 On | N/A |
| N/A 51C P3 22W / N/A | 834MiB / 5931MiB | 24% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1032 G /usr/lib/xorg/Xorg 330MiB |
| 0 1251 G /usr/bin/gnome-shell 333MiB |
| 0 1758 G ...equest-channel-token=622209288718607755 121MiB |
| 0 5086 G ...uest-channel-token=12207632792533837012 47MiB |
+-----------------------------------------------------------------------------+
My LSTM:
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import LSTM
from tensorflow.keras.layers import Dropout
regressor = Sequential()
regressor.add(LSTM(units = 180, return_sequences = True, input_shape = (X_train.shape[1], 3)))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units = 180, return_sequences = True))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units = 180, return_sequences = True))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units = 180, return_sequences = True))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units = 180, return_sequences = True))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units = 180))
regressor.add(Dropout(0.2))
regressor.add(Dense(units = 1))
regressor.compile(optimizer = 'adam', loss = 'mean_squared_error')
regressor.fit(X_train, y_train, epochs = 10, batch_size = 32, callbacks=[cp_callback])