我正在大型数据库上训练ResNet-50网络。当检查我的GPU的使用百分比时,我发现它的变化范围在0%和4%之间!虽然我正在使用tensorflow-GPU。 这是我的CPU和GPU使用率:
当我运行以下两个命令行时:
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
我明白了
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 4622338339054789933
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 13594420839
locality {
bus_id: 1
links {
}
}
incarnation: 17927686236275886371
physical_device_desc: "device: 0, name: Quadro
P5000, pci bus id: 0000:01:00.0, compute
capability: 6.1"
]
任何人都可以通过简单的说明帮助我,如何正确,完全利用我的GPU? 我必须提到的是,我在训练期间使用ImageDataGenerator对象及其两个方法flow_from_directory和fit_generator,因此我可以设置特定的参数(例如worker参数)来提高GPU的使用率。 这是我使用ImageDataGenerator的方式
input_imgen = ImageDataGenerator()
train_it = input_imgen.flow_from_directory(directory=data_path_l,target_size=
(224,224),
color_mode="rgb",
batch_size=batch_size,
class_mode="categorical",
shuffle=False,
)
valid_it = input_imgen.flow_from_directory(directory=test_data_path_l,target_size=
(224,224),
color_mode="rgb",
batch_size=batch_size,
class_mode="categorical",
shuffle=False,
)
model = resnet.ResnetBuilder.build_resnet_50((img_channels, img_rows,
img_cols), num_classes)
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
filepath=".\conv2D_models\weights-improvement-{epoch:02d}-
{val_acc:.2f}.hdf5"
mc = ModelCheckpoint(filepath, save_weights_only=False, verbose=1,
monitor='loss', mode='min')
history=model.fit_generator(train_it,
steps_per_epoch= train_images // batch_size,
validation_data = valid_it,
validation_steps = val_images// batch_size,
epochs = epochs,callbacks=[mc],
shuffle=False)