2 回答

TA貢獻1797條經驗 獲得超6個贊
我曾經面臨過這個問題。我從一個我再也找不到的人那里找到了解決方案。我將他的解決方案粘貼在下面。事實上,我發現如果你設置allow_growth=True,tensorflow 似乎會使用你所有的內存。所以你應該只設置你的最大限制。
嘗試這個:
gpus = tf.config.experimental.list_physical_devices("GPU")
if gpus:
# Restrict TensorFlow to only use the first GPU
try:
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, False)
tf.config.experimental.set_virtual_device_configuration(
gpu,
[
tf.config.experimental.VirtualDeviceConfiguration(
memory_limit=12288 # set your limit
)
],
)
tf.config.experimental.set_visible_devices(gpus[0], "GPU")
logical_gpus = tf.config.experimental.list_logical_devices("GPU")
print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPU")
except RuntimeError as e:
# Visible devices must be set before GPUs have been initialized
print(e)

TA貢獻1816條經驗 獲得超4個贊
使用 SGD 進行訓練以及一批中的整個訓練數據可能(取決于您的輸入數據)非常消耗內存。嘗試將您的batch_size
尺寸調整為較小的尺寸(例如 8、16、32)
添加回答
舉報