[PYTHON] Introduced Tensorflow (Win / Anaconda environment)

This goal

Python environment construction for Tensorflow

First, build an environment for Tensorflow (Python 3.5). Build in a virtual environment with Conda. Execute the following command at the command prompt

conda create -n tensorflow python=3.5

1.png

You will be asked if you want to install the required packages, so select Y Installation is completed after a while. Switch the environment when the installation is complete.

activate tensorflow

2.png

Install Tensorflow

From here, install Tensorflow using pip. pip is a Python package management system for python, which I often use.

Execute the following command.

pip install tensorflow
.
.
.
Successfully built protobuf
Installing collected packages: six, protobuf, numpy, werkzeug, tensorflow
Successfully installed numpy-1.12.1 protobuf-3.3.0 six-1.10.0 tensorflow-1.1.0 werkzeug-0.12.2

If it says Successfully built protobuf

tutorial

There is a sample in the official Tensorflow, so let's move it. https://www.tensorflow.org/get_started/get_started

import numpy as np
import tensorflow as tf
# Model parameters
W = tf.Variable([.3], tf.float32)
b = tf.Variable([-.3], tf.float32)
# Model input and output
x = tf.placeholder(tf.float32)
linear_model = W * x + b
y = tf.placeholder(tf.float32)
# loss
loss = tf.reduce_sum(tf.square(linear_model - y)) # sum of the squares
# optimizer
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)
# training data
x_train = [1,2,3,4]
y_train = [0,-1,-2,-3]
# training loop
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init) # reset values to wrong
for i in range(1000):
  sess.run(train, {x:x_train, y:y_train})

# evaluate training accuracy
curr_W, curr_b, curr_loss  = sess.run([W, b, loss], {x:x_train, y:y_train})
print("W: %s b: %s loss: %s"%(curr_W, curr_b, curr_loss))

Run with python

(tensorflow) C:\work>python tutorial.py
W: [-0.9999969] b: [ 0.99999082] loss: 5.69997e-11

I don't know what it is if it's just the execution result, but if I explain it roughly

Finding the relationship between X and Y by linear regression (In short, the slope (W) and b (intercept) of the straight line (Y = WX + b))

image

Check it out by the next time

Recommended Posts

Introduced Tensorflow (Win / Anaconda environment)
Introduced anaconda
Python environment construction (pyenv, anaconda, tensorflow)
install tensorflow in anaconda + python3.5 environment
Python3.6 environment construction (using Win environment Anaconda)
Anaconda3 environment installation procedure
Anaconda environment construction memo
Python environment construction @ Win7
[Environment construction] @anaconda that runs keras / tensorflow on GPU
Procedure to install TensorFlow in fish shell environment (Anaconda 4.0.0)
[Ubuntu 18.04] Tensorflow 2.0.0-GPU environment construction
Use Anaconda in pyenv environment
Install Python environment with Anaconda
Anaconda environment construction on CentOS7
Build an Anaconda virtual environment
Anaconda3 python environment construction procedure
Anaconda3 × Pycharm environment construction memo
Python environment construction and TensorFlow
[Anaconda] Activate the virtual environment
Ubuntu14.04 + GPU + TensorFlow environment construction
[Tensorflow] Tensorflow environment construction on Windows 10
Environment construction of TensorFlow + JupyterNotebook + Matplotlib on Windows version Anaconda (August 2017 version)
Try running tensorflow on Docker + anaconda
Anaconda python environment construction on Windows 10
Anaconda environment construction on Mac (2018 version)
Precautions when installing tensorflow with anaconda
Install scrapy in python anaconda environment
Various Anaconda settings in Windows 10 environment
Use Tensorflow 2.1.0 with Anaconda on Windows 10!
Python3 TensorFlow for Mac environment construction
Created an environment for Anaconda & Jupyter
Introducing keras on virtual environment (pyenv: anaconda) on server by conda (tensorflow backend)
Steps to build a Django environment with Win10 WSL Ubuntu18.04 + Anaconda + Apache2