Chapter 6 - page 204

I’m getting the following errors:

55%20PM

That happens every time I run this, or I get to this point in the code:

pred = model.predict(x)
print(pred)

When I run the next code I get the following output.

26%20PM

This has been run in a MacBook Pro mid 2015 i7 2.8 16GB. I thing this machine is capable of running this simple program.

Thank you!

When you get the “Kernel Restarting” message, it means that Python has crashed. Unfortunately, it doesn’t really tell you why but it’s likely that there was a problem with Keras or TensorFlow.

Does the Terminal window from which you launched Jupyter notebook show any messages?

(By the way, after such a crash happens, you will need to run every cell in the notebook again, you can’t just continue with the next one.)

Hi,

I have the same problem. ‘The kernel appears to have died. It will restart automatically’.
Does anyone have an idea how to fix it?

The error occurs when executing

pred = model.predict(x)
print(pred)

In the terminal I see the following log output:

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/

These are all installed packages in the Conda environment:

 Name                    Version                   Build  Channel
_tflow_select             2.3.0                       mkl  
absl-py                   0.7.1                    pypi_0    pypi
appnope                   0.1.0            py36hf537a9a_0  
astor                     0.8.0                    pypi_0    pypi
attrs                     19.1.0                   py36_1  
backcall                  0.1.0                    py36_0  
blas                      1.0                         mkl  
bleach                    3.1.0                    py36_0  
c-ares                    1.15.0               h1de35cc_1  
ca-certificates           2019.5.15                     0  
certifi                   2019.6.16                py36_0  
cloudpickle               1.1.1                      py_0  
coremltools               2.1.0                    pypi_0    pypi
cycler                    0.10.0           py36hfc81398_0  
cytoolz                   0.9.0.1          py36h1de35cc_1  
dask-core                 2.0.0                      py_0  
decorator                 4.4.0                    py36_1  
defusedxml                0.6.0                      py_0  
entrypoints               0.3                      py36_0  
freetype                  2.9.1                hb4e5f40_0  
gast                      0.2.2                    pypi_0    pypi
google-pasta              0.1.7                    pypi_0    pypi
grpcio                    1.21.1                   pypi_0    pypi
h5py                      2.9.0            py36h3134771_0  
hdf5                      1.10.4               hfa1e0ec_0  
imageio                   2.5.0                    py36_0  
intel-openmp              2019.4                      233  
ipykernel                 5.1.1            py36h39e3cac_0  
ipython                   7.5.0            py36h39e3cac_0  
ipython_genutils          0.2.0            py36h241746c_0  
jedi                      0.13.3                   py36_0  
jinja2                    2.10.1                   py36_0  
joblib                    0.13.2                   py36_0  
jpeg                      9b                   he5867d9_2  
jsonschema                3.0.1                    py36_0  
jupyter_client            5.2.4                    py36_0  
jupyter_core              4.4.0                    py36_0  
keras                     2.2.0                    pypi_0    pypi
keras-applications        1.0.2                    py36_0  
keras-preprocessing       1.0.1                    py36_0  
kiwisolver                1.1.0            py36h0a44026_0  
libcxx                    4.0.1                hcfea43d_1  
libcxxabi                 4.0.1                hcfea43d_1  
libedit                   3.1.20181209         hb402a30_0  
libffi                    3.2.1                h475c297_4  
libgfortran               3.0.1                h93005f0_2  
libpng                    1.6.37               ha441bb4_0  
libprotobuf               3.8.0                hd9629dc_0  
libsodium                 1.0.16               h3efe00b_0  
libtiff                   4.0.10               hcb84e12_2  
llvm-openmp               4.0.1                hcfea43d_1  
markdown                  3.1.1                    py36_0  
markupsafe                1.1.1            py36h1de35cc_0  
matplotlib                3.1.0            py36h54f8f79_0  
mistune                   0.8.4            py36h1de35cc_0  
mkl                       2019.4                      233  
mkl-service               2.0.2            py36h1de35cc_0  
mkl_fft                   1.0.12           py36h5e564d8_0  
mkl_random                1.0.2            py36h27c97d8_0  
mock                      3.0.5                    py36_0  
nbconvert                 5.5.0                      py_0  
nbformat                  4.4.0            py36h827af21_0  
ncurses                   6.1                  h0a44026_1  
networkx                  2.3                        py_0  
notebook                  5.7.8                    py36_0  
numpy                     1.16.4           py36hacdab7b_0  
numpy-base                1.16.4           py36h6575580_0  
olefile                   0.46                     py36_0  
openssl                   1.1.1c               h1de35cc_1  
pandas                    0.24.2           py36h0a44026_0  
pandoc                    2.2.3.2                       0  
pandocfilters             1.4.2                    py36_1  
parso                     0.4.0                      py_0  
patsy                     0.5.1                    py36_0  
pexpect                   4.7.0                    py36_0  
pickleshare               0.7.5                    py36_0  
pillow                    6.0.0            py36hb68e598_0  
pip                       19.1.1                   py36_0  
prometheus_client         0.6.0                    py36_0  
prompt_toolkit            2.0.9                    py36_0  
protobuf                  3.8.0                    pypi_0    pypi
ptyprocess                0.6.0                    py36_0  
pygments                  2.4.2                      py_0  
pyparsing                 2.4.0                      py_0  
pyrsistent                0.14.11          py36h1de35cc_0  
python                    3.6.8                haf84260_0  
python-dateutil           2.8.0                    py36_0  
pytz                      2019.1                     py_0  
pywavelets                1.0.3            py36h1d22016_1  
pyyaml                    5.1.1                    pypi_0    pypi
pyzmq                     18.0.0           py36h0a44026_0  
readline                  7.0                  h1de35cc_5  
scikit-image              0.15.0           py36h0a44026_0  
scikit-learn              0.21.2           py36h27c97d8_0  
scipy                     1.2.1            py36h1410ff5_0  
seaborn                   0.9.0                    py36_0  
send2trash                1.5.0                    py36_0  
setuptools                41.0.1                   py36_0  
six                       1.12.0                   py36_0  
sqlite                    3.28.0               ha441bb4_0  
statsmodels               0.9.0            py36h1d22016_0  
tensorboard               1.14.0                   pypi_0    pypi
tensorflow                1.14.0                   pypi_0    pypi
tensorflow-base           1.13.1          mkl_py36hc36dc97_0  
tensorflow-estimator      1.14.0                   pypi_0    pypi
termcolor                 1.1.0                    pypi_0    pypi
terminado                 0.8.2                    py36_0  
testpath                  0.4.2                    py36_0  
tfcoreml                  0.3.0                    pypi_0    pypi
tk                        8.6.8                ha441bb4_0  
toolz                     0.9.0                    py36_0  
tornado                   6.0.2            py36h1de35cc_0  
traitlets                 4.3.2            py36h65bd3ce_0  
wcwidth                   0.1.7            py36h8c6ec74_0  
webencodings              0.5.1                    py36_1  
werkzeug                  0.15.4                     py_0  
wheel                     0.33.4                   py36_0  
wrapt                     1.11.2                   pypi_0    pypi
xz                        5.2.4                h1de35cc_4  
yaml                      0.1.7                hc338f04_2  
zeromq                    4.3.1                h0a44026_3  
zlib                      1.2.11               h1de35cc_3  
zstd                      1.3.7                h5bba6e5_0

I could eventually fix it. I did some Googling and after a bit of trial/error I got it working. It seems it’s a macOS only problem that occurs on Mojave.
The fix was adding this to the import statements at the top of the notebook:

import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'
2 Likes