Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install tensorflow 2.0 on Mac or Linux?

TensorFlow 2.0 is released recently. There are no clear steps on how to install it. Any help with the steps for installation is appreciated.

like image 768
inferno Avatar asked Jan 27 '23 04:01

inferno


1 Answers

Four other developers have the same problem. The last comment is June 3rd. I eventually sent emails to all the email addresses of the contributors I could find listed at https://github.com/apple/tensorflow_macos, but none of them replied. The repository is now read-only, and archived, allowing no more comments. https://github.com/apple is Apple's official github page.

The world's first trillion-dollar company is unable to support one of its claims about its new computer - that it can be used to do machine learning in Python using Tensorflow. Contrast this with my experience of the open-source programming language Elixir. Every question I have asked at https://elixirforum.com/ got answered within 24 hours by the creator of the language, Jose Valim.

After five months, I did eventually get Tensorflow working as advertised on my Mac M1.

Thanks https://towardsdatascience.com/installing-tensorflow-on-the-m1-mac-410bb36b776

I needed to download from https://github.com/conda-forge/miniforge/releases and run Miniforge3-MacOSX-arm64.sh several times to get it to install a lot of software in /Users/rod/miniforge3

See also https://medium.com/gft-engineering/macbook-m1-tensorflow-on-jupyter-notebooks-6171e1f48060 who made the following useful comment:

"After publishing the article, someone reached me with this error when installing TensorFlow: ERROR: tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl is not a supported wheel on this platform. This happened because Anaconda was installed. As I describe above, Anaconda is not ARM compatible, so the most direct way to solve this is to uninstall Anaconda and install Miniforge instead."

$ brew uninstall anaconda

This made all my other python programs not work, so I had to redirect a series of soft links to point to /Users/rod/minforge3/bin.

However, using Tensorflow still involves using a version of Anaconda - this one:

/Users/rod/miniforge3/bin/conda

And you do conda activate apple_tensorflow before running a Tensorflow program.

The program won't run like this:

/Users/rod/miniforge3/bin/python my_tensorflow_program.py

Nor will it from from the command line if you put

#!/Users/rod/miniforge3/bin/python

at the top.

But if you put

#!python

at the top, it figures it out.

$ conda activate apple_tensorflow
$ which python
  /Users/rod/miniforge3/envs/apple_tensorflow/bin/python

This is Python 3.9.6

I also got help from https://medium.com/codex/installing-tensorflow-on-m1-macs-958767a7a4b3

At this point, I have to admit part of the delay was my bad. I didn't read the instructions clearly. You have to do the following, in this order, in folder miniforge3/ -

conda env create environment.yml
conda activate apple_tensorflow
pip install --upgrade --force --no-dependencies https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl```

conda install notebook -y
conda install matplotlib -y
conda install pandas -y
conda install scikit-learn -y
jupyter notebook

PS. I got shut out of developer.apple.com for a month. I can't remember why. I just got back in, on October 15th 2021. As expected, there are no answers to my questions there. https://developer.apple.com/forums/thread/686926

If I were the CEO of a commercial company which had bought 50 Apple M1s to do ML, I'd send them back, and buy PC's with NVidia GPUs, and put Linux on them. As it is, I'm just doing AI for fun. And what fun it is, now I've finally got it working, no thanks to Apple.

like image 51
rodmclaughlin Avatar answered Jan 29 '23 22:01

rodmclaughlin