Import Error in installation: Error installing Horovod and Tensorflow - tensorflow

I am trying to install Tensorflow and Horovod
pip install tensorflow
HOROVOD_WITH_TENSORFLOW=1 pip install horovod
Then I ran a sample code
import tensorflow as tf
import horovod.tensorflow as hvd
When I run this code, I get the error
ImportError: Extension horovod.tensorflow has not been built. If this is not expected, reinstall Horovod with HOROVOD_WITH_TENSORFLOW=1 to debug the build error.

If you need to install tensorflow and horovod , you can use the following steps:
1)Create a conda environment to avoid the mismatch of package versions.
conda create -n test_hvd -c intel python=3.6
2)Activate the environment
source activate test_hvd
(You can use any name instead of test_hvd, which is an environment name.)
3)Install tensorflow in the activated environment:
pip install https://storage.googleapis.com/intel-optimized-tensorflow/tensorflow-1.10.0-cp36-cp36m-linux_x86_64.whl
4)Finally install horovod
pip install --no-cache-dir horovod
Note: 1. Kindly confirm if you are using the latest versions of GCC (gcc (GCC) 6.4.0 works fine).
These steps are tested on Linux OS
Hope this helps!

Related

Got stuck trying to install TensorFlow on Mac M1

I have been trying to install TensorFlow on my Macbook Air with a M1 chip.
Using Python 3.9.7.
Originally was on MacOS 11, but subsequently upgraded to 12.01
At first, I tried these instructions [https://towardsdatascience.com/installing-tensorflow-on-the-m1-mac-410bb36b776] but got stuck when trying to execute
pip3 install --upgrade --force --no-dependencies https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl
ERROR: tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl is not a supported wheel on this platform.
So I tried to follow these instructions [https://www.tensorflow.org/install/source#macos_1] to compile TensorFlow, but when I try
bazel build //tensorflow/tools/pip_package:build_pip_package
I get these errors:
ERROR: /Users/scottbrown/tensorflow/tensorflow/lite/python/BUILD:62:10: Target '//tensorflow/lite/python:tflite_convert' depends on toolchain '#local_config_cc//:cc-compiler-darwin', which cannot be found: error loading package '#local_config_cc//': cannot load '#local_config_cc_toolchains//:osx_archs.bzl': no such file'
ERROR: Analysis of target '//tensorflow/tools/pip_package:build_pip_package' failed; build aborted: Analysis failed
When I try
pip3 install tensorflow-macos
I get this error:
Building wheel for h5py (pyproject.toml) ... error
ERROR: Command errored out with exit status 1:
command: /opt/homebrew/opt/python#3.9/bin/python3.9 /opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /var/folders/gz/28jpdfcd3b3g4pm7zl0wmrkh0000gn/T/tmpz_m057zj
cwd: /private/var/folders/gz/28jpdfcd3b3g4pm7zl0wmrkh0000gn/T/pip-install-kz29fkw2/h5py_0747e63c821445b6944ecb4fc6b2d1e1
I'm basing my answer on the article from Prabhat Kumar Sahu:
How to install Tensorflow on M1 Mac the easy way
Set up environment
Make sure you have homebrew, xcode, and miniforge installed.
create a virtual environment
conda create --name mlp python=3.8
activate environment
conda activate mlp
Install tensorflow for mac-os
(sets up the wheel files etc.)
conda install -c apple tensorflow-deps
pip install tensorflow-macos
pip install tensorflow-metal
That's it. You should have the environment all ready to go. Look at Prabhat's article for a sample Jupyter Notebook test for an example of how to benchmark/test your environment.
Hey guys I had the same issue but I fixed it with the following instructions :
NOTE: If using conda environment built against pre-macOS 11 SDK use:
SYSTEM_VERSION_COMPAT=0 python -m pip install tensorflow-macos
otherwise, you will get errors like: “not a supported wheel on this platform”
STEPS :
OS Requirements macOS 12.0+ (latest beta)
Currently Not Supported
Multi-GPU support
Acceleration for Intel GPUs
V1 TensorFlow Networks
Installation Instructions
Step 1: Environment setup
CPU TYPE x86: AMD
Create virtual environment (recommended):
python3 -m venv ~/tensorflow-metal
source ~/tensorflow-metal/bin/activate
python -m pip install -U pip
NOTE: python version 3.8 required
CPU TYPE : arm64 : Apple Silicon
Download and install Conda env:
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate
OR
conda env create --file=environment.yml --name tf_m1
and then activate tf_m1
Install the TensorFlow dependencies:
conda install -c apple tensorflow-deps
When upgrading to new base TensorFlow version, we recommend:
uninstall existing tensorflow-macos and tensorflow-metal
python -m pip uninstall tensorflow-macos
python -m pip uninstall tensorflow-metal
Upgrade tensorflow-deps
conda install -c apple tensorflow-deps --force-reinstall
or point to specific conda environment
conda install -c apple tensorflow-deps --force-reinstall -n my_env
tensorflow-deps versions are following base TensorFlow versions so:
For v2.5:
conda install -c apple tensorflow-deps==2.5.0
For v2.6:
conda install -c apple tensorflow-deps==2.6.0
NOTE: Python versions 3.8 and 3.9 supported
Step 2: Install base TensorFlow
python -m pip install tensorflow-macos
NOTE: If using conda environment built against pre-macOS 11 SDK use:
SYSTEM_VERSION_COMPAT=0 python -m pip install tensorflow-macos
otherwise you will get errors like: “not a supported wheel on this
platform
Step 3: Install tensorflow-metal plugin
python -m pip install tensorflow-metal

Unable to install tensor flow with pip?

I just updated the latest MacOS and it wiped everything out.
I follow the steps from this website.
And I start reinstalling the tensorflow with pip3 and it's not installing anything.
I got this error from typing pip3 install --user --upgrade tensorflow .
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
FYI, my MacBook is 64-bit.
and
~ pip3 -V
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
pip 20.2.4 from /Users/zack/Library/Python/3.8/lib/python/site-packages/pip (python 3.8)
~ python3 -V
Python 3.8.2
I don't know what happened does anyone have any ideas.
According to this documentation https://www.tensorflow.org/install/pip#package-location
and your version of python you should run
python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.3.0-cp38-cp38-macosx_10_14_x86_64.whl
This is the 3rd step, so check if you got installed correctly the packages from steps 1 and 2
if pip is not up-to-date upgrade pip:
pip install --upgrade pip
then install tensorflow:
pip install tensorflow
for python 3.8 you need to install tensorflow 2.2 or later
system requirements of tensorflow:
Python 3.5–3.8
Python 3.8 support requires TensorFlow 2.2 or later.
pip 19.0 or later (requires manylinux2010 support)
Ubuntu 16.04 or later (64-bit)
macOS 10.12.6 (Sierra) or later (64-bit) (no GPU support)

how to run dlib face recognition with gpu

I have installed visual studio 2019, and Cuda 10.1 and TensorFlow 2.1.0 and I still can't run face recognition with GPU, can someone give me a complete guide on the steps to use GPU instead of CPU.
note: I'm using windows 10, my GPU is gtx1050 and I am using anaconda spider.
Firstly, you should install tensorflow-gpu package instead of tensorflow.
If your tf is installed correctly, you can run face recognition in gpu within deepface. You can test it with allocate memory function.
#!pip install deepface
from deepface import DeepFace
DeepFace.allocateMemory()
If everything is OK, then it returns "DeepFace will run on GPU" message.
All face recogntion models except Dlib will run on tensorflow-gpu. You can run face recognition with verification function.
from deepface import DeepFace
models = ["VGG-Face", "Facenet", "OpenFace", "DeepFace", "DeepID", "Dlib"]
obj = DeepFace.verify("img1.jpg", "img2.jpg", model_name = models[0])
print(obj)
i solved this by these steps using an anaconda enviroment:
cuda 10.2 installed
python (3.7.7)
conda install pip
conda install tensorflow (latest 2.1.0)
conda install tensorflow-gpu
pip install imutils
pip install opencv-python
pip install opencv-contrib-python
pip install dlib
pip install face_recognition
As Adrian Rosebrock mentioned at https://www.pyimagesearch.com/2018/06/18/face-recognition-with-opencv-python-and-deep-learning/, it is better to build Dlib from source, so the library is aware of the presence of the exact GPU in your system. My guess is - during the building process, it probes the capabilities of the GPU through the CUDA driver and builds and installs accordingly.
git clone https://github.com/davisking/dlib.git
cd dlib
mkdir build
cd build
cmake .. -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1
cmake --build .
cd ..
python setup.py install --yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDA

I am not able to update tensorflow installed with anaconda

I have been trying to update tensorflow from 1.2.1 to 1.3.
I did the following on my terminal:
pip3 install tensorflow --upgrade
After this, I tried checking the version
python3 -c 'import tensorflow as tf; print(tf.__version__)'
This outputs 1.2.1 but not 1.3.0
All this had been done in an anaconda environment.
Operating system: macOS Sierra
I would like to know how one can perform this update.
Thank you
The solution that I found was to install pip inside the conda environment and use that instance of pip to install the packages. Please refer here
The reason I got the above error was that the python3 and pip3 paths were different.
This became evident when I ran the below commands inside the conda environment.
which python3
/Users/SMBP/anaconda/envs/tensorflow/bin/python3
which pip3
/usr/local/bin/pip3
Also, I think it is better to use virtualenv and virtualenvwrapper if you wish to work with tensorflow as it is the recommended way.

TensorFlow: unsatisfiableError: the following specifications were found to be in conflict

I am trying to install tensorflow in anaconda with python 2.7 in Win10, by conda installation:
conda install -c conda-forge tensorflow=1.1.0
Then, I get the error message:
- python 2.7*
- tensorflow 1.1.0* -> python 3.5*
Use 'conda info <package>' to see the dependencies for each package.
Does the message mean I need to use python 3.5?
Yes.
TensorFlow only supports version 3.5.x of Python on Windows. Note that Python 3.5.x comes with the pip3 package manager, which is the program you'll use to install TensorFlow.
There are instructions for installing TF with Anaconda on Win10 on that page.