可能原因是GPU显存不足,限制GPU显存使用大小即可
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
import tensorflow as tf
gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
tf.config.experimental.set_memory_growth(gpus[0], True) # 设置显存按需申请
tf.config.experimental.set_virtual_device_configuration(gpus[0], [tf.config.experimental.
VirtualDeviceConfiguration(memory_limit=1024)]) # 限制最大显存使用1G