SoFunction
Updated on 2024-10-30

Resolving import tensorflow causing jupyter kernel to die

Today after reinstalling the gpu version of tensorflow there is a problem, jupyter notebook import tensorflow run after the kernel died. At first, I thought the version was incompatible, so I upgraded all the contents of the conda and found that the problem still existed and didn't work. So I went to check the error message.

Getting a WARNING in jupyter's terminal which I rarely visit.

Displays errors caused by HDF5 version mismatches.

There are two general solutions online:

1. Specify the version to install

2.

pip uninstall h5py
pip install h5py

The first method I started using, reinstalling with the conda command. Found that after the install, while the Warning problem was solved, tf and Keras inexplicably disappeared 。。。。

It doesn't show up in the conda list either! But apparently these are installed packages and can't understand what's happening.

So tried the second method. The problem was solved.

Supplementary: jupyter notebook using tensorflow-gpu often appear problems

Question 1:

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

Solution:

If you build jupyter notebook on a server with GPU and use tensorflow, you can solve this problem by adding config in front of session, I have personally tried it (I think the main problem is that the program is running on the cpu before, resulting in insufficient memory, so the kernel is If you want to see how much memory is being used while the code is running, you can use free -h):

config = ()
config.gpu_options.allow_growth = True
sess = (config=config)

Question 2:

WARNING:tensorflow:From /root/anaconda3/lib/python3.6/site-packages/tensorflow/python/keras/layers/:143: calling dropout (from .nn_ops) with keep_prob is deprecated and will be removed in a future for updating: Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.

WARNING:tensorflow:From /root/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from .math_ops) is deprecated and will be removed in a future for updating: Use instead.

WARNING:tensorflow:From /root/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/math_grad.py:102: div (from .math_ops) is deprecated and will be removed in a future version. Instructions for updating: Deprecated in favor of operator or .

Solution:

The main reason for this problem may be an anaconda version issue, or a version incompatibility caused by other version issues. Use the following instructions to update accordingly. It is feasible to try it yourself.

conda update mkl
conda upgrade notebook
conda upgrade jupyter
conda update anaconda

The above is a personal experience, I hope it can give you a reference, and I hope you can support me more. If there is any mistake or something that has not been fully considered, please do not hesitate to give me advice.