我正在学习udemy深度学习课程,并且在构建具有数据增强功能的第一个图像分类CNN时,我选择尝试使用我的GPU(Nvidia GTX 1060)来加快处理速度。据我所知,它只能在几分钟内在CPU上运行。但是已经过了4-5个小时,而我才到达12/25时。我已经搜索了很多,却找不到解释。 另外,我的GPU使用率最高,而CPU使用率则为20-26%。
我的数据集是用于训练的8000张图像和用于测试的2000张图像。 我已经从Anaconda Navigator(带有tensorflow / tensorflow-gpu 2.1的安装程序)中安装了keras-gpu。
当我运行nvidia-smi
命令时,我可以在最后一行看到python进程,但在“内存使用率”内存中看到的是“ N / A”。这是否意味着我的CNN没有使用GPU?
如果是这样,我不明白为什么我在运行这段代码时得到CPU和GPU设备:
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
这是代码和nvidia-smi信息,如果您想检查的话:
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D
from keras.layers import Flatten, Dense
classifier = Sequential()
classifier.add(Conv2D(32, kernel_size = 3, padding = 'same', input_shape = (64, 64, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = 2))
classifier.add(Flatten())
classifier.add(Dense(units = 128, activation = 'relu'))
classifier.add(Dense(units = 1, activation = 'sigmoid'))
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(rescale= 1./255, shear_range = 0.2, zoom_range = 0.2, horizontal_flip = True)
test_datagen = ImageDataGenerator(rescale = 1./255)
training_set = train_datagen.flow_from_directory('dataset/training_set', target_size = (64, 64), batch_size = 32, class_mode = 'binary')
test_set = test_datagen.flow_from_directory('dataset/test_set', target_size = (64, 64), batch_size = 32, class_mode = 'binary')
classifier.fit(training_set, steps_per_epoch = 8000, epochs = 25, validation_data = test_set, validation_steps = 2000, verbose = 2)
nvidia-smi:
C:\Program Files\NVIDIA Corporation\NVSMI>nvidia-smi
Mon Jun 01 01:15:59 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 446.14 Driver Version: 446.14 CUDA Version: 11.0 |
|-------------------------------+----------------------+----------------------+
| 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 106... WDDM | 00000000:01:00.0 Off | N/A |
| N/A 64C P2 24W / N/A | 2510MiB / 3072MiB | 10% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU PID Type Process name GPU Memory |
| Usage |
|=============================================================================|
| 0 248 C+G ...cw5n1h2txyewy\LockApp.exe N/A |
| 0 2576 C+G ...X2_APP\DolbyDAX2Toast.exe N/A |
| 0 6152 C+G ...es.TextInput.InputApp.exe N/A |
| 0 9592 C+G ...ekyb3d8bbwe\YourPhone.exe N/A |
| 0 16232 C ...nvs\tensorflow\python.exe N/A |
+-----------------------------------------------------------------------------+
预先感谢:)