简体   繁体   English

Jupyter Notebook kernel 在编译神经网络时死机

[英]Jupyter Notebook kernel dies while compiling Neural Network

While creating and compiling a keras Dense Neural Network my jupyter notebook kernel always dies.在创建和编译 keras 密集神经网络时,我的 jupyter notebook kernel 总是死机。 The terminal gives me a message that it couldn't allocate space and that CUDA is out of memory.终端给我一条消息,它无法分配空间,并且 CUDA 已超出 memory。 My GPU (2060 Super) has already run this model many times, just not on jupyter.我的 GPU(2060 Super)已经运行了这个 model 很多次,只是没有在 jupyter 上运行。 I have already done a lot of searching whithout an answer that actually works.我已经做了很多搜索,但没有一个真正有效的答案。 Some of the things I tried were changing my kernel, using numba device.reset() and reinstalling both conda and jupyter but nothing seems to work.我尝试的一些事情是更改我的 kernel,使用 numba device.reset() 并重新安装 conda 和 jupyter,但似乎没有任何效果。

Here is the code block that always gets the error:这是总是得到错误的代码块:

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"])

Try adding this function to your notebook.尝试将此 function 添加到您的笔记本中。 I am not certain but it may help.我不确定,但它可能会有所帮助。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM