Day 64 pip install tensorflow and 2.0 is here.

I installed Telsorflow, so I ran it right away. But it doesn't work with an error! ??

$ python calc1.py 
2019-12-08 20:09:10.641892: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-12-08 20:09:10.667849: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fac4a3c0dc0 executing computations on platform Host. Devices:
2019-12-08 20:09:10.667893: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
  File "calc1.py", line 12, in <module>
    sess = tf.Session()
AttributeError: module 'tensorflow' has no attribute 'Session'

You don't know Session? ?? ??

I looked it up. It seems that recent Tensorflow does not need Session.

AttributeError: module'tensorflow' has no attribute about'Session' https://ja.stackoverflow.com/questions/59780/attributeerror-module-tensorflow-has-no-attribute-session%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6

If you think about it and look at the version ...

$ pip list | grep tensorflow
tensorflow                         2.0.0              
tensorflow-estimator               2.0.1 

It was tensolflow 2.0.0 that was installed with pip install tensolflow.

I referred to "Let's use Python scraping & machine learning development techniques BeautifulSoup, scikit-learn, TensorFlow" https://www.socym.co.jp/support/s-1079

If you look closely, you specified the version as conda install -c conda-forge tensorflow = 1.1.0 at the time of installation. I'm sorry.

Let's modify it so that it works with tensolflow 2.0.0.

calc1.py


import tensorflow as tf
a = tf.constant(1234)
b = tf.constant(5000)

add_op = a + b

#sess = tf.Session()
#res = sess.run(add_op) 
#print(res)

tf.print(add_op)

I wish it became easier to describe.

$ python calc1.py 
2019-12-08 20:16:15.480543: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-12-08 20:16:15.512089: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7ffedb3c6c60 executing computations on platform Host. Devices:
2019-12-08 20:16:15.512124: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): Host, Default Version
6234

I got the result, but it took a few seconds to add, and a mysterious message came out. Looking at this message, pip installs the one that works on almost any computer, but it's slow. If you build from source, it will be optimized in each environment, so it may be faster. I see. I'll do something about it later. (Half an hour)

Recommended Posts

Day 64 pip install tensorflow and 2.0 is here.
TensorFlow 2.1 is here!
Install Python 2.7.9 and Python 3.4.x with pip.
Install easy_install and pip on windows
What is the difference between `pip` and` conda`?
sudo pip install
Install pip and pandas with Ubuntu or VScode
Install tensorflow. (Only!)
If you try to install Python2 pip after installing Python3 pip and it is rejected
Install ZIP version Python and pip on Windows 10
What is pip and how do you use it?
Install tweepy with pip and use it for API 1.1
Install TensorFlow on Ubuntu
Install pip on Mavericks
[Python] pip and wheel
Install pip, pyenv, BeautifulSoup4
Install pyenv and pyenv-virtualenv
How to install pip
Error with pip install
Install and configure KVM
Install the pip command
Install pip / pip3 on Ubuntu
Install scikit.learn with pip
When pip install fails
pip install scikit-learn says Numerical Python (NumPy) is not installed.