Raspberry Pi installing Tensor-flow and Keras - tensorflow

I am trying to install Tensorflow 1.14 and Keras 2.0 but it keeps giving me an issue when I try to import it. It seems to install correctly but then just fails.
I am running Pi 3b+ Linux raspberrypi 4.19.75-v7+ #1270 SMP Tue Sep 24 18:45:11 BST 2019 armv7l GNU/Linux
The error it is giving me is:
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pi/cvenv/lib/python3.5/site-packages/tensorflow/__init__.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/home/pi/cvenv/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 47, in <module>
import numpy as np
File "/home/pi/cvenv/lib/python3.5/site-packages/numpy/__init__.py", line 150, in <module>
from . import random
File "/home/pi/cvenv/lib/python3.5/site-packages/numpy/random/__init__.py", line 181, in <module>
from . import _pickle
File "/home/pi/cvenv/lib/python3.5/site-packages/numpy/random/_pickle.py", line 1, in <module>
from .mtrand import RandomState
ImportError: /home/pi/cvenv/lib/python3.5/site-packages/numpy/random/mtrand.cpython-35m-arm-linux-gnueabihf.so: undefined symbol: PyFPE_jbuf

You need to install libatlas to make numpy work
sudo apt install libatlas3-base

Related

Tensorflow cannot be imported on ubuntu

System information
Linux Ubuntu 16.04
TensorFlow version: tensorflow-gpu 1.5
Python version: 2.7
Installed using virtualenv: pip
CUDA/cuDNN version: CUDA9.0 & CUDNN7.0
Enviroment
Using anaconda to create a virtual environment named tf.
Error Msg
(tf) ➜ ~ python
Python 2.7.18 |Anaconda, Inc.| (default, Jun 4 2021, 14:47:46)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/xander/anaconda3/envs/tf/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/xander/anaconda3/envs/tf/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/home/xander/anaconda3/envs/tf/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
File "/home/xander/anaconda3/envs/tf/lib/python2.7/site-packages/google/protobuf/descriptor.py", line 113
class DescriptorBase(metaclass=DescriptorMetaclass):
^
SyntaxError: invalid syntax
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/xander/anaconda3/envs/tf/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/xander/anaconda3/envs/tf/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
ImportError: cannot import name pywrap_tensorflow
As mentioned in this link, You're running the script in the same directory as TensorFlow. Try to move it out and you should be fine.
For example, Open the Linux command line and execute the script that you've just copied to desktop
Restarting the conda (using miniconda + conda-forge channel) works for me. But I don't know why, though...

Keras.module needs Tf version=>2.2, but DLL's Tf load failed

This is my first question here, 'cos I am normally able to find someone else asking the same question in stackoverflow and the answers are usually very clear and detailed.
Unfortutately this time I find myself in a corner.
I am using anaconda3 (64bit) from a Win10 and I would like to import
from keras.models import Model
Unfortunately I get the following issue:
File "...\Anaconda3\lib\site-packages\keras\__init__.py", line 6, in <module>
'Keras requires TensorFlow 2.2 or higher. '
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
When I have updated tensorflow to the newest version possible "2.3", I believe, but unfortunately this conflict with this other problem:
In [1]: import tensorflow as tf
Traceback (most recent call last):
File "<ipython-input-1-64156d691fe5>", line 1, in <module>
import tensorflow as tf
File "...\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "...\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 40, in <module>
from tensorflow.python.eager import context
File "...\Anaconda3\lib\site-packages\tensorflow\python\eager\context.py", line 35, in <module>
from tensorflow.python import pywrap_tfe
File "...\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow
File "...\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "...\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed: The specified module could not be found.
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
Do you have any suggestion?
use tf.keras.Model
Keras is implemented by default in Tensorflow 2.0

After installing Tensorflow-gpu i got error Failed to load the native TensorFlow runtime

I have installed redhat 6.6, cuda 9.0, cudnn 7.3.1 and tesnorflow-gpu. but after installation getting following error. My graphics card is nvidia titan v
Traceback (most recent call last):
File "<ipython-input-1-88d96843a926>", line 1, in <module>
import keras
File "/root/anaconda3/lib/python3.7/site-packages/keras/__init__.py", line 3, in <module>
from . import utils
File "/root/anaconda3/lib/python3.7/site-packages/keras/utils/__init__.py", line 6, in <module>
from . import conv_utils
File "/root/anaconda3/lib/python3.7/site-packages/keras/utils/conv_utils.py", line 9, in <module>
from .. import backend as K
File "/root/anaconda3/lib/python3.7/site-packages/keras/backend/__init__.py", line 89, in <module>
from .tensorflow_backend import *
File "/root/anaconda3/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 5, in <module>
import tensorflow as tf
File "/root/anaconda3/lib/python3.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/root/anaconda3/lib/python3.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/root/anaconda3/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/root/anaconda3/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/root/anaconda3/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/root/anaconda3/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/root/anaconda3/lib/python3.7/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/root/anaconda3/lib/python3.7/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: libcuda.so.1: cannot open shared object file: No such file or directory
Did you tested your installations of cuda and cudnn:
Nvidia drivers:
$ nvidia-smi
This should display you an overview of the metrics of your GPU
Test cuda:
Check first if:
$ nvcc -V
display the right version of your cuda toolkit
Then you can test it with the following process:
First:
$ cd ~/NVIDIA_CUDA-9.0_Samples
$ make
And then:
$ cd ~/NVIDIA_CUDA-10.0_Samples/bin/x86_64/linux/release
$./deviceQuery
if you have a 'Result: pass' at the end, you're all good!
To test cudnn:
$ cp -r /usr/src/cudnn_samples_v7/ $HOME
$ cd $HOME/cudnn_samples_v7/mnistCUDNN
$ make clean && make
$ ./mnistCUDNN
You should have as result: 'Test passed!'
Tensorflow:
If cuda and cudnn are working, i advice you to install tensorflow in a conda environment using:
conda create --name tf_gpu tensorflow-gpu
For me (and after a lot of problems) it was working very well.
To test it:
from tensorflow.python.client import device_lib
device_lib.list_local_devices()
main sources:
install tensorflow GPU
tensorflow for GPU made easy

How to install tensorflow-gpu 1.12 with CUDA 10.0

I know tensorflow-gpu==1.12 needs CUDA 9.0 or lesser but is there any possibility where I can install Tensorflow on CUDA 10.0? May be via source or using Bazel?
UPDATE: I tried downloading from Github and installing via Bazel but I get the following Error.
Python 3.7.1 (default, Oct 23 2018, 19:19:42)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "/some-folder/tensorflow-1.12.0/tensorflow/python/platform/self_check.py", line 25, in <module>
from tensorflow.python.platform import build_info
ImportError: cannot import name 'build_info' from 'tensorflow.python.platform' (unknown location)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/some-folder/tensorflow-1.12.0/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/some-folder/tensorflow-1.12.0/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/some-folder/tensorflow-1.12.0/tensorflow/python/pywrap_tensorflow.py", line 25, in <module>
from tensorflow.python.platform import self_check
File "/some-folder/tensorflow-1.12.0/tensorflow/python/platform/self_check.py", line 27, in <module>
raise ImportError("Could not import tensorflow. Do not import tensorflow "
ImportError: Could not import tensorflow. Do not import tensorflow from its source directory; change directory to outside the TensorFlow source tree, and relaunch your Python interpreter from there.
tensorflow doesn't support python 3.7 version.
Requires Python 3.4, 3.5, or 3.6
see below
https://www.tensorflow.org/install/pip
We need to just come out of the Source Directory and run the python file. If you are running a file with python filename.py command you need to shift the file outside the source directory.
When you use import tensorflow from the source directory it will import the folder tensorflow and not the actual tensorflow library

rpy2.ipython errors with pandas / numpy

Trying to use the rpy2.ipython (formerly 'rmagic') extension of IPython, to get interactive R (%R line magic and %%R cell magic functions), I get the following errors...
louis ~ $ python
Python 3.5.1 |Anaconda 2.4.0 (64-bit)| (default, Dec 7 2015, 11:16:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rpy2.ipython
Traceback (most recent call last):
File "/home/louis/anaconda3/lib/python3.5/site-packages/pandas/__init__.py", line 7, in <module>
from pandas import hashtable, tslib, lib
File "pandas/src/numpy.pxd", line 157, in init pandas.hashtable (pandas/hashtable.c:38262)
File "/home/louis/anaconda3/lib/python3.5/site-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/home/louis/anaconda3/lib/python3.5/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/home/louis/anaconda3/lib/python3.5/site-packages/numpy/lib/__init__.py", line 18, in <module>
from .polynomial import *
File "/home/louis/anaconda3/lib/python3.5/site-packages/numpy/lib/polynomial.py", line 20, in <module>
from numpy.linalg import eigvals, lstsq, inv
File "/home/louis/anaconda3/lib/python3.5/site-packages/numpy/linalg/__init__.py", line 51, in <module>
from .linalg import *
File "/home/louis/anaconda3/lib/python3.5/site-packages/numpy/linalg/linalg.py", line 29, in <module>
from numpy.linalg import lapack_lite, _umath_linalg
ImportError: /home/louis/anaconda3/lib/python3.5/site-packages/numpy/linalg/lapack_lite.cpython-35m-x86_64-linux-gnu.so: undefined symbol: zgelsd_
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/louis/anaconda3/lib/python3.5/site-packages/rpy2/ipython/rmagic.py", line 59, in <module>
from rpy2.robjects import pandas2ri as baseconversion
File "/home/louis/anaconda3/lib/python3.5/site-packages/rpy2/robjects/pandas2ri.py", line 6, in <module>
from pandas.core.frame import DataFrame as PandasDataFrame
File "/home/louis/anaconda3/lib/python3.5/site-packages/pandas/__init__.py", line 13, in <module>
"extensions first.".format(module))
ImportError: C extension: /home/louis/anaconda3/lib/python3.5/site-packages/numpy/linalg/lapack_lite.cpython-35m-x86_64-linux-gnu.so: undefined symbol: zgelsd_ not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/louis/anaconda3/lib/python3.5/site-packages/rpy2/ipython/__init__.py", line 1, in <module>
from .rmagic import load_ipython_extension
File "/home/louis/anaconda3/lib/python3.5/site-packages/rpy2/ipython/rmagic.py", line 63, in <module>
from rpy2.robjects import numpy2ri as baseconversion
File "/home/louis/anaconda3/lib/python3.5/site-packages/rpy2/robjects/numpy2ri.py", line 6, in <module>
import numpy
File "/home/louis/anaconda3/lib/python3.5/site-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/home/louis/anaconda3/lib/python3.5/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/home/louis/anaconda3/lib/python3.5/site-packages/numpy/lib/__init__.py", line 18, in <module>
from .polynomial import *
File "/home/louis/anaconda3/lib/python3.5/site-packages/numpy/lib/polynomial.py", line 13, in <module>
import numpy.core.numeric as NX
AttributeError: module 'numpy' has no attribute 'core'
I've always ignored the fact that Anaconda3 seems to have been built on RHEL (I'm on Linux Mint, which is based on Ubuntu), but I'm wondering now if this might be the cause of the problem here - "C extensions not built" for my machine?
Since it's in the conda virtual environment, I'm not sure how I can fix this.
Should I attempt to python setup.py build_ext --inplace within ~/anaconda3/lib/python3.5/site-packages/pandas ?
When I step through the above imports, of e.g. :
from numpy.linalg import lapack_lite, _umath_linalg
there's no error, so I'm not certain there are actually unbuilt files, perhaps it's just some masking of one variable by another (as in this question with similar error message but different traceback, i.e. an error in rpy2).
import numpy.core (etc.) without first trying to load rpy2.ipython works fine
Summary of pip show :
---
Metadata-Version: 2.0
Name: rpy2
Version: 2.7.5
---
Metadata-Version: 1.1
Name: numpy
Version: 1.10.1
---
Metadata-Version: 1.1
Name: pandas
Version: 0.17.0
---
Metadata-Version: 2.0
Name: ipython
Version: 4.0.1
(all locations /home/louis/anaconda3/lib/python3.5/site-packages)
System info from cat /proc/version and lsb_release -a :
Linux version 3.13.0-35-generic (buildd#panlong) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #62-Ubuntu SMP Fri Aug 15 01:58:42 UTC 2014
LSB Version: core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-4.0-amd64:core-4.0-noarch:core-4.1-amd64:core-4.1-noarch
Description: Linux Mint 17 Qiana
I am suspecting an incompatibility between versions of the LAPACK library: the one picked at runtime on your system, the one numpy was built with, and the one R was built with.
Installing numpy, R, and rpy2 from source in your virtual environment should solve the issue. An alternative would be to notify the maintainers of the anaconda packages involved and see it they confirm that numpy and R packaged by anaconda use the same LAPACK.