Can't import keras - python

I can't run keras; when I try to import keras from a Jupyter notebook I first see
Using TensorFlow backend.
in red, but then the kernel crashes and I see a prompt with:
Kernel Restarting
The kernel appears to have died. It will restart automatically.
If I try to run it directly with python (so I have a file called run.py that just imports keras) I get:
Using TensorFlow backend.
Illegal instruction: 4
I am on High Sierra (10.13.2) on a mid 2012 Macbook with a 2,9 GHz Intel Core i7 processor. I have python 3.6 installed on the latest conda and I am also running the latest versions of keras and tensorflow.
Thanks for any help!

Try to install mxnet-mkl library and then run keras.
Please see link below:
https://github.com/apache/incubator-mxnet/issues/8183

Related

ImportError: Could not load dynamic library 'cudart64_110.dll' [duplicate]

This question already has answers here:
Fix not load dynamic library for Tensorflow GPU
(5 answers)
Closed 1 year ago.
I was originally running Tensorflow using PyCharm.
In PyCharm, the same phrase as the title did not appear.
But after I switched to VS Code and installed Python extension,
When I write and execute import tensorflow as tf, the error like the title appears repeatedly.
ImportError: Could not load dynamic library 'cudart64_110.dll'
Considering that there was no problem in PyCharm, it does not seem to be an environmental variable problem.
When I type the same command that was executed in VS Code in the command prompt window, another phrase appears,
"Connection failed because the target computer refused to connect."
My OS: Windows 10
I am using Anaconda, and I created a virtual environment.
vscode ver : 1.53.2
tensorflow ver : 2.4.1
CUDA : 11.2
cudnn : 8.1
It is due to tensorflow GPU support. Tensorflow now comes with GPU support and the system need graphics support and CUDA, CUDU installations. If you missed CUDA installation then you will get the above message. The latest version of tensorflow sometimes won't run without CUDA.
Try to install tensorflow 1.15 and python 3.7.4
https://www.python.org/ftp/python/3.7.4/python-3.7.4-amd64.exe
pip install tensorflow==1.15
NB: Normally tensorflow will run without cuda but the message will always shown in the prompt.
I would agree that this is due to your CUDA version, check the bottom of tensorflow GPU build config, it says for 2.4, you need CUDA 11.0 and cuDNN 8.0, which you have neither, in addition, you need MSVC 2019 to compile it.
Notice that for newer versions of tensorflow-gpu (>=2.3.0), conda will NOT download everything, you need to do them manually.
because it seems like all the evidence is pointing to GPU support problem, tensorflow-gpu might still run without using GPU, so it is possible that it was running on CPU when you use PyCharm,
I would suggest you double-check it runs as intended in PyCharm with
print(tf.config.list_physical_devices('GPU'))
or just simply reinstall everything
I copied "cudart64_110.dll" to the CUDA/v11.2/bin folder and it was resolved.

Installing Tensorflow and Keras on Intel Pentium

For a university we are supposed to implement a TensorFlow project using the python libraries for tensorflow and keras. I can install both of them just fine using pip3, but executing any piece of code results in some kind of error.
I've settled on testing the very complicated code:
import keras
Using python 3.6 and the newest tensorflow and keras (pip3 install tensorflow keras) I get the error ModuleNotFoundError: No module named 'tensorflow.python'; 'tensorflow' is not a package. I checked, and import tensorflow finds the package, but returns some error about AVX instructions and dumps the core.
I researched, and my CPU does not support AVX instructions which are part of tensorflow >= 1.6.0. I could not find a precompiled version that runs on my laptop without AVX, and I don't have the time to compile myself.
I tried downgrading to tensorflow == 1.5.0 and keras == 2.1.3 which was the version when tensorflow == 1.5.0 was around, but I still get missing errors, for each version and import statement a different one.
For example when I use the code:
import keras
from keras.datasets import mnist
I instead get the error AttributeError: module 'keras.utils' has no attribute 'Sequence'. I'm on an Intel Pentium, which I assume is the problem. I am fully aware that my setup is in no way suitable for machine learning, and it isn't supposed to be, but nevertheless I'd like to work on that assignment.
Anyone got experience with installing TensorFlow on older machines?
System:
Ubuntu 18.04.2 LTS
Intel(R) Pentium(R) 3556U # 1.70GHz (Dual Core)
4GB RAM
I had the same trouble, but it seems to have solved it. (However, the Python version shall be 3.5. )
For CPUs that do not support AVX, the tensorflow must be version 1.5 or lower.
If you want to install Tensorflow 1.5, the Python version must be 3.5 or lower.
The successful procedure is as follows.
(1) Uninstall your Anaconda.
(2) Download the following version of Anaconda from the following
URL. Version: Anaconda3-4.2.0-Windows-x86_64.exe
URL:https://repo.anaconda.com/archive/ or https://repo.anaconda.com/archive/Anaconda3-4.2.0-Windows-x86_64.exe
(3) Double-click the anaconda icon of “(2)” above, and install the
anaconda according to the GUI instructions.
(4) Start Anaconda Prompt
(5) Enter “pip install tensorflow==1.5” in Anaconda Prompt and press
the return key. Wait for the installation to finish. (See the log)
(6) Enter "pip install keras==2.2.4" in Anaconda Prompt and press the
return key. Wait for the installation to finish.(See the log)
This completes the installation. If you Enter " import tensorflow " on Jupiter notebook, some future error may displayed.(See this log.)
System:
My PC does not support AVX like your PC. My PC's specs are as follows.
PC:Surface Go
CPU:Intel(R) Pentium(R) CPU 4415Y @ 1.60 GHz
Windows10:64bit
How to test ?
Enter and execute the following command on Jupiter Note. Or use this file.
import tensorflow as tf
print(tf.__version__)
print(tf.keras.__version__)
or
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
If your install is successful, then following message will be displayed on your Jupiter notebook
1.5.0
2.1.2-tf
P.S.
I'm not very good at English, so I'm sorry if I have some impolite or unclear expressions.
Sticking to the Pentium configuration is not recommended for default tensorflow builds because of AVX dependencies. Also many recent advances in this area are not available in earlier builds of TF and you will find it difficult to replicate research works. Options below:
Get a Google Colab (https://colab.research.google.com/) notebook, install Keras and TF and get going with your work
There have been genuine requests for this support, refer to this link [https://github.com/tensorflow/tensorflow/issues/18689] where unofficial builds are provided. See if one of them works
Build Tensorflow from scratch (very hard option), with the right set of flags for Bazel (remove all AVX/threading options)

exit code -1073741571 (0xC0000FD) with tensorflow in PyCharm

Description
I implemented a model with tensorflow via PyCharm on Windows 7. This implemented model worked well. After i got some problems i have to install a new OS (Windows 10). I also installed something that i used to run the model such as PyCharm, Anaconda, Git etc. Likewise in Anaconda i installed python, tensorflow, SimpleITK.
Problem
When i run the model on a new environment, i got a error below:
Process finished with exit code -1073741571 (0xC00000FD)
Solved
I created a new virtual environment on Anaconda that changed the versions of both python and tensorflow. The python is 3.6 to 3.5 and the tensorflow is 1.9 to 1.3. After that it works fine.

Python kernel dies when importing tensorflow 1.7

I want to use tensorflow insinde a Jupyter notebook. However, running
import tensorflow as tf
in a Jupyter notebook immediately triggers a pop-up:
The kernel appears to have died. It will restart automatically.
This issue only began after updating to tensorflow 1.7. I had not used tensorflow for a few weeks so it might also be due to an update to anaconda 5.1 with Python 3.6.
I use a Mid-2010 MacBookPro with "High Sierra 10.13.4". Removing and reinstalling anaconda 5.1 with Python 3.6, followed by installation of tensorflow (and not a single other library) via
pip3 install --upgrade tensorflow
did not resolve the issue. I do not use an isolated environment. The "anaconda3" folder is not in my home folder but directly in "Macintosh HD".
Before reinstalling anaconda, I removed it via these instructions
https://docs.anaconda.com/anaconda/install/uninstall. I also did not try to run tensorflow outside Jupyter, simply because I do not know how. But even if I did, I would still like to use Jupyter.
I'm also running a Mid-2010 MacbookPro and have been facing the same issue. It seems the only solution is to downgrade to Tensorflow 1.5. You can do so by running the following:
pip3 uninstall tensorflow
pip3 install tensorflow==1.5
Credit given to the solution to this post.
I was facing the same issue with Tensorflow 2 '2.0.0-beta1'. I found out that when you have multiple notebooks with Tensorflow running, this problem occurs. Also, simply closing the unused notebook windows wont work, they're still running in the background, you'll have to 'Shutdown' the notebooks
Here are the steps to shutdown a notebooks:
> Go to Home (of Jupyter notebook)
> Select 'Running' tab
> Select the unused notebooks
> Click 'Shutdown' button
You will notice in the Jupyter Home that the active notebook icon is green while inactive ones are gray
I have also faced a similar issue.
I was using python 3.7 and Tensorflow version 1.5
For we moving to Python 3.5 solve the issue.

tensorboard stuck when executed at command prompt

System information
Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10 Pro 1703
TensorFlow installed from (source or binary): install binary with GPU version by pip based on Python 3.5.2
TensorFlow version (use command below):('1.3.0')
Python version: 3.5.2
Bazel version (if compiling from source):none
CUDA/cuDNN version:cuda v8.0/cuDNN v6,0
GPU model and memory:GeForce GTX 1080 Ti 11GB
Describe the problem
I am trying to open TensorBoard after running mnist_with_summaries.py source code from the TensorBoard tutorials (https://github.com/tensorflow/tensorflow/blob/r1.3/tensorflow/examples/tutorials/mnist/mnist_with_summaries.py). After running I have got the logs folder. However,
After I run tensorboard --logdir=/tmp/tensorflow/mnist in cmd, it stuck and did not showing anything else. I try to use tensorboard --logdir=/tmp/tensorflow/mnist --debug and have the same result. Anyone know what I did wrong?
There is a github issue filed for this: https://github.com/tensorflow/tensorflow/issues/12693

Categories