gpt4 book ai didi

python - 当我运行代码时,jupyter笔记本的内核不断死亡

转载 作者:行者123 更新时间:2023-11-30 21:58:00 25 4
gpt4 key购买 nike

我通过关注 this tutorial 迈出了深度学习的第一步,一切都很顺利,直到我需要在 Jupyter Notebook 中训练网络。我几乎尝试了所有方法,但总是收到此错误

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 上遇到了几乎所有相同的问题。

最佳答案

您下载的是哪个版本的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

对于 python :

conda update tensorflow

然后运行

import tensorflow as tf
print(tf.__version__)

验证您是否拥有最新的可用版本

关于python - 当我运行代码时,jupyter笔记本的内核不断死亡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55083432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com