代码开头加上
gpus
= tf
.config
.experimental
.list_physical_devices
('GPU')
if gpus
:
try:
tf
.config
.experimental
.set_visible_devices
(gpus
[0], 'GPU')
for gpu
in gpus
:
tf
.config
.experimental
.set_memory_growth
(gpu
, True)
logical_gpus
= tf
.config
.experimental
.list_logical_devices
('GPU')
print(len(gpus
), "Physical GPUs,", len(logical_gpus
), "Logical GPUs")
except RuntimeError
as e
:
print(e
)
转载请注明原文地址: https://lol.8miu.com/read-9168.html