2 回答

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊
我曾經(jīng)面臨過(guò)這個(gè)問(wèn)題。我從一個(gè)我再也找不到的人那里找到了解決方案。我將他的解決方案粘貼在下面。事實(shí)上,我發(fā)現(xiàn)如果你設(shè)置allow_growth=True,tensorflow 似乎會(huì)使用你所有的內(nèi)存。所以你應(yīng)該只設(shè)置你的最大限制。
嘗試這個(gè):
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貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超4個(gè)贊
使用 SGD 進(jìn)行訓(xùn)練以及一批中的整個(gè)訓(xùn)練數(shù)據(jù)可能(取決于您的輸入數(shù)據(jù))非常消耗內(nèi)存。嘗試將您的batch_size
尺寸調(diào)整為較小的尺寸(例如 8、16、32)
添加回答
舉報(bào)