Jupyter Notebook在运行代码时,核心经常死掉。

10

我是通过跟随这个教程开始学习深度学习的,一切都进行得很顺利,直到我需要在jupyter笔记本上训练网络。我尝试了几乎所有方法,但总是出现这个错误。

The kernel appears to have died. It will restart automatically.

当我检查终端时,我可以看到这个。
 [I 18:32:24.897 NotebookApp] Adapting to protocol v5.1 for kernel 0d2f57af-46f5-419c-8c8e-9676c14dd9e3
2019-03-09 18:33:12.906756: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2019-03-09 18:33:12.907661: I tensorflow/core/common_runtime/process_util.cc:69] Creating new thread pool with default inter op setting: 4. Tune using inter_op_parallelism_threads for best performance.
OMP: Error #15: Initializing libiomp5.dylib, but found libiomp5.dylib already initialized.
OMP: Hint: This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
[I 18:33:13.864 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
WARNING:root:kernel 0d2f57af-46f5-419c-8c8e-9676c14dd9e3 restarted

我尝试运行的代码非常简单(即使对于刚开始涉足深度学习的我来说也是如此)。
import tensorflow as tf  

mnist = tf.keras.datasets.mnist  
(x_train, y_train),(x_test, y_test) = mnist.load_data()  

x_train = tf.keras.utils.normalize(x_train, axis=1)  
x_test = tf.keras.utils.normalize(x_test, axis=1) 

model = tf.keras.models.Sequential()  
model.add(tf.keras.layers.Flatten())  
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))  
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))  
model.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax))  

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

model.fit(x_train, y_train, epochs=3)  

val_loss, val_acc = model.evaluate(x_test, y_test)  
print(val_loss)  
print(val_acc)  

我尝试了我所有的想法,并在Google上遇到了几乎相同的问题。


这种情况我也遇到过。我需要对数百万条数据进行模型测试。但是接着几分钟后,Jupyter笔记本显示“DEAD KERNEL(死内核)”。 - YusufUMS
在一个单独的Anaconda环境中安装TensorFlow,并确保你的库已经更新。 - Irfanuddin
你能否在jupyter笔记本之外重现这个崩溃?如果可以,那么你发现了一个bug,需要在github上进行报告。 - Alexandre Passos
那个问题还存在吗?我之前也遇到了同样的问题,我认为是使用conda而不是pip导致的。卸载conda中的tensorflow,然后使用pip安装tensorflow对我有用。 - Anytoe
4个回答

3

你下载的是哪个版本的TensorFlow?

从错误日志来看,似乎存在一些OpenMP库的问题,我建议您将Tensorflow重新安装到最新稳定版本。

为了让那段代码正常工作,我不得不更新我的TensorFlow(1.13.1)安装,以下是我的输出内容。

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
Epoch 1/3
60000/60000 [==============================] - 6s 94us/sample - loss: 0.2652 - acc: 0.9213
Epoch 2/3
60000/60000 [==============================] - 6s 95us/sample - loss: 0.1103 - acc: 0.9660
Epoch 3/3
60000/60000 [==============================] - 6s 100us/sample - loss: 0.0735 - acc: 0.9765
10000/10000 [==============================] - 0s 35us/sample - loss: 0.0875 - acc: 0.9731
0.08748154099322855
0.9731

根据您使用的库管理器不同,尝试升级

对于Pip和Python3:

pip3 install tensorflow --upgrade

针对Anaconda:

conda update tensorflow

然后运行。
import tensorflow as tf
print(tf.__version__)

为确认您拥有最新版本,请执行以下操作:


1
我已经检查过了,我有最新版本,但问题仍然存在。 - Matija
@Matija 我也遇到了同样的问题,将tensorflow升级到1.13版本后问题得到了解决。 - the_ccalderon
你尝试在BASH或者你正在使用的任何shell中设置错误消息中的环境变量了吗?KMP_DUPLICATE_LIB_OK=TRUE现在这只是一个权宜之计,看起来jupyter内核在某种程度上捕捉到了多个OpenMP链接,而它应该只看到一个。你是否在anaconda和另一个平台上安装了TF?你可能安装了多个版本,并且Jupyter不知道该使用哪个。 - Orrbifold

1
你可以尝试在命令提示符中运行python -m notebook(或python3 -m notebook),并尝试在该内核中运行代码。对我有用。

1
我尝试了各种建议的选项-升级matplotlib,将matplotlib降级到2.x.x版本,升级TensorFlow到1.13.1等等。都没有成功。对于我来说,即使是像下面这样简单的虚拟情节也会在Keras的fit方法调用后遇到plot方法时立即失败并显示“OMP: Error #15”。
acc = [i for i in range(20) ]
epochs = range(1, len(acc) + 1)
loss = range(1, len(acc) + 1)
plt.plot(epochs, loss, 'bo', label='Training loss')

根据此帖子的建议,以下内容对我很有帮助。

conda install nomkl

0

更新您的tensorflow软件包并重新启动计算机。此外,请确保您已激活一个内核,然后再次运行代码。这应该可以解决问题。

使用以下命令升级您的tensorflow:

pip install tensorflow --upgrade

对于pip3,请使用以下命令:

pip3 install tensorflow --upgrade

对于conda,请使用以下命令:

conda update tensorflow


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接