Until now, we used Keras as a backend to run Tensorflow for deep learning. If you just want to do machine learning with Python, you can still use Keras, but there are some uses where you want to use the models and weights learned in Python in C ++. Actually, it would be nice to use the model trained in Keras, but it seems easier to code directly with Tensorflow, which also has a C ++ API, so I will attack from there. First of all, as a preliminary preparation, I will summarize up to the point of installing Tensorflow in the environment of Anaconda built on Windows and checking it. The function names have changed significantly since Tensorflow 1.0, so please be careful if you are thinking of upgrading to 1.0. By the way, please note that the conda command that is listed on the official website as it is (as of March 8, 2017) will not work. If you want to use scripts version 1.0 or earlier, see the Official Migration Guide (https://www.tensorflow.org/install/migration). Or, Script that automatically converts is officially published, so please use it. ..
(Addition) It seems that tensorflow has been updated and can be used with python3.6. I will write another article about this soon.
The version of Anaconda is different, but the procedure is the same, so please refer to the installation of Anaconda at the following URL. http://qiita.com/tomochiii/items/c17505872781c201d7b1
Tensorflow currently only supports Python 3.5.x. When you install the current latest version of Anaconda by following the steps above, the Python version installed will be 3.6. Therefore, I created a Python 3.5 environment as a virtual environment on Anaconda. If you have selected and installed Python 3.5 as your Anaconda environment, you can skip this step. To create a Python 3.5 virtual environment for Tensorflow, launch the Anaconda prompt and run the following command: Those who develop with Jupyter Notebook are recommended to install jupyter at the same time.
create_tensorenv
#Creating a virtual environment for tensorflow, name parameters can be anything
$ conda create --name=tensorenv python=3.5
#You can install at the same time by listing the package name at the end
$ conda create --name=tensorenv python=3.5 jupyter numpy <package name> ...
#Check if a virtual environment is created
$ conda info -e
If the name specified by conda create is in the list, it is successful. Use the following command to move to and exit the virtual environment. For the name, specify the one in the list.
activate_tensorenv
#How to move to a virtual environment
$ activate tensorenv
#How to get out of the virtual environment
$ deactivate tensorenv
If you make a mistake, you can delete the virtual environment with the following command.
remove_tensorenv
#Delete virtual environment
$ conda remove --name=tensorenv --all
There are two commands to install Tensorflow. You can install it with either of the following: CPU version Tensorflow installation command.
install_tensorflow_cpu
#tensorflow installation command 1
$ pip install --upgrade tensorflow
#tensorflow installation command 2
$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.0-cp35-cp35m-win_amd64.whl
Installation command for GPU version Tensorflow. We have not confirmed the operation here.
install_tensorflow_gpu
#tensorflow installation command 1
$ pip install --upgrade tensorflow-gpu
#tensorflow installation command 2
$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.0.0-cp35-cp35m-win_amd64.whl
Command 1 allows you to install the latest version of tensorflow, and Command 2 allows you to install the specified version.
Finally, check if the installation was successful. Start Python from the command line and see if Tensorflow can import it.
validate_installation
#Start Python
$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Execute the above script, and if "Hello, TensorFlow!" Is displayed without any error, the installation is complete!
Once I have implemented a script to learn with Tensorflow, I would like to post it. Also, if there are any confusing or incorrect parts in this post, I will correct them, so please let me know in the comments.
Recommended Posts