Python内核在带有tensorflow 2的Jupyter Notebook上死亡 [英] Python kernel dies on Jupyter Notebook with tensorflow 2

查看:219
本文介绍了Python内核在带有tensorflow 2的Jupyter Notebook上死亡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我根据这些在conda上的Mac上安装了tensorflow 2. >说明:

I installed tensorflow 2 on my mac using conda according these instructions:

conda create -n tf2 tensorflow

然后我安装了ipykernel,将这个新环境添加到我的jupyter笔记本内核中,如下所示:

Then I installed ipykernel to add this new environment to my jupyter notebook kernels as follows:

conda activate tf2
conda install ipykernel
python -m ipykernel install --user --name=tf2

这似乎很好,我可以在jupyter笔记本内核上看到我的 tf2 环境.

That seemed to work well, I am able to see my tf2 environment on my jupyter notebook kernels.

然后,我尝试运行简单的MNIST 示例,以检查是否一切正常正确,当我执行以下代码行时:

Then I tried to run the simple MNIST example to check if all was working properly and I when I execute this line of code:

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

我的jupyter笔记本的内核死了,没有更多信息.

The kernel of my jupyter notebook dies without more information.

我通过 python mnist_test.py 在我的终端上执行了相同的代码,也通过 ipython (逐个命令)执行了相同的代码,所以我没有任何问题,这让我们我假设我的tensorflow 2已正确安装在conda环境中.

I executed the same code on my terminal via python mnist_test.py and also via ipython (command by command) and I don't have any issues, which let's me assume that my tensorflow 2 is correctly installed on my conda environment.

关于安装过程中出了什么问题的任何想法?

Any ideas on what went wrong during the install?

版本:

python==3.7.5
tensorboard==2.0.0
tensorflow==2.0.0
tensorflow-estimator==2.0.0
ipykernel==5.1.3
ipython==7.10.2
jupyter==1.0.0
jupyter-client==5.3.4
jupyter-console==5.2.0
jupyter-core==4.6.1

在这里,我放置了完整的脚本以及执行的标准输出:

Here I put the complete script as well as the STDOUT of the execution:

import tensorflow as tf
import matplotlib.pyplot as plt
import seaborn as sns

mnist = tf.keras.datasets.mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()

x_train, x_test = x_train / 255.0, x_test / 255.0

nn_model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10, activation='softmax')
])

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

nn_model.fit(x_train, y_train, epochs=5)

nn_model.evaluate(x_test,  y_test, verbose=2)

(tf2)➜tensorflow2 python mnist_test.py 2020-01-03 10:46:10.854619: 我tensorflow/core/platform/cpu_feature_guard.cc:145]这个TensorFlow 英特尔®MKL-DNN对二进制文件进行了优化,以使用以下CPU 性能关键操作中的说明:SSE4.1 SSE4.2 AVX AVX2 FMA要在非MKL-DNN操作中启用它们,请重建TensorFlow 带有适当的编译器标志. 2020-01-03 10:46:10.854860:I tensorflow/core/common_runtime/process_util.cc:115]创建新 带有默认互操作设置的线程池:8.使用 inter_op_parallelism_threads以获得最佳性能.火车上60000 样本时代1/5 60000/60000 [==============================]-6s 102us/样本-损失:0.3018-准确性:0.9140时代2/5 60000/60000 [=============================]-6s 103us/sample-损失:0.1437- 精度:0.9571纪元3/5 60000/60000 [=============================]-6s 103us/sample-损失:0.1054- 精度:0.9679时代4/5 60000/60000 [=============================]-6s 103us/sample-损失:0.0868- 精度:0.9729时代5/5 60000/60000 [=============================]-6s 103us/sample-损失:0.0739- 精度:0.9772 10000/1-1s-损耗:0.0359-精度:0.9782(tf2) ➜tensorflow2

(tf2) ➜ tensorflow2 python mnist_test.py 2020-01-03 10:46:10.854619: I tensorflow/core/platform/cpu_feature_guard.cc:145] This TensorFlow binary is optimized with Intel(R) MKL-DNN to use the following CPU instructions in performance critical operations: SSE4.1 SSE4.2 AVX AVX2 FMA To enable them in non-MKL-DNN operations, rebuild TensorFlow with the appropriate compiler flags. 2020-01-03 10:46:10.854860: I tensorflow/core/common_runtime/process_util.cc:115] Creating new thread pool with default inter op setting: 8. Tune using inter_op_parallelism_threads for best performance. Train on 60000 samples Epoch 1/5 60000/60000 [==============================] - 6s 102us/sample - loss: 0.3018 - accuracy: 0.9140 Epoch 2/5 60000/60000 [==============================] - 6s 103us/sample - loss: 0.1437 - accuracy: 0.9571 Epoch 3/5 60000/60000 [==============================] - 6s 103us/sample - loss: 0.1054 - accuracy: 0.9679 Epoch 4/5 60000/60000 [==============================] - 6s 103us/sample - loss: 0.0868 - accuracy: 0.9729 Epoch 5/5 60000/60000 [==============================] - 6s 103us/sample - loss: 0.0739 - accuracy: 0.9772 10000/1 - 1s - loss: 0.0359 - accuracy: 0.9782 (tf2) ➜ tensorflow2

推荐答案

尝试了不同的方法后,我使用以下命令在调试模式下运行jupyter notebook:

After trying different things I run jupyter notebook on debug mode by using the command:

jupyter notebook --debug

然后在笔记本上执行命令后,我得到了错误消息:

Then after executing the commands on my notebook I got the error message:

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/.

并在讨论之后,在虚拟环境上安装nomkl对我有用. /p>

And following this discussion, installing nomkl on the virtual environment worked for me.

conda install nomkl

这篇关于Python内核在带有tensorflow 2的Jupyter Notebook上死亡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆