Python Jupyter笔记本内核在编译神经网络时死亡

Python Jupyter笔记本内核在编译神经网络时死亡,python,tensorflow,keras,deep-learning,jupyter-notebook,Python,Tensorflow,Keras,Deep Learning,Jupyter Notebook,在创建和编译keras密集型神经网络时,我的jupyter笔记本内核总是会死掉。终端给我一个消息,它无法分配空间,CUDA内存不足。我的GPU 2060 Super已经多次运行此型号,只是没有在jupyter上运行。我已经做了很多搜索,但没有一个真正有效的答案。我尝试过的一些事情是更改我的内核,使用numba device.reset并重新安装conda和jupyter,但似乎没有任何效果 以下是始终获取错误的代码块: inputs = keras.Input(shape=(69,)) fc1

在创建和编译keras密集型神经网络时,我的jupyter笔记本内核总是会死掉。终端给我一个消息,它无法分配空间,CUDA内存不足。我的GPU 2060 Super已经多次运行此型号,只是没有在jupyter上运行。我已经做了很多搜索,但没有一个真正有效的答案。我尝试过的一些事情是更改我的内核,使用numba device.reset并重新安装conda和jupyter,但似乎没有任何效果

以下是始终获取错误的代码块:

inputs = keras.Input(shape=(69,))
fc1 = keras.layers.Dense(100, activation='relu')(inputs)
d1 = keras.layers.Dropout(0.1)(fc1, training=True)
bn1 = keras.layers.BatchNormalization()(d1)
fc2 = keras.layers.Dense(150, activation='relu')(bn1)
d2 = keras.layers.Dropout(0.1)(fc2, training=True)
bn2 = keras.layers.BatchNormalization()(d2)
fc3 = keras.layers.Dense(200, activation='relu')(bn2)
d3 = keras.layers.Dropout(0.1)(fc3, training=True)
bn3 = keras.layers.BatchNormalization()(d3)
fc4 = keras.layers.Dense(120, activation='relu')(bn3)
d4 = keras.layers.Dropout(0.1)(fc4, training=True)
bn4 = keras.layers.BatchNormalization()(d4)
fc5 = keras.layers.Dense(60, activation='relu')(bn4)
bn5 = keras.layers.BatchNormalization()(fc5)
outputs = keras.layers.Dense(2, activation='softmax')(bn5)
model = keras.Model(inputs, outputs)

model.summary()
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])

尝试将此功能添加到笔记本中。我不确定,但这可能会有帮助

def setup_gpus():
gpus = tf.config.list_physical_devices('GPU')
if gpus:
    try:
        tf.config.experimental.set_visible_devices(gpus[0],'GPU')
        tf.config.experimental.set_virtual_device_configuration(gpus[0],[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=1500)])
    except RuntimeError as e:
        print(e)