Installation & Introduction for TensorFlow


I started to learn Machine Learning and TensorFlow.
This article shows TensorFlow tutorial codes and some description for ML term.


😀 Installation

First, you should install pip and virtualenv, like the follow script shows in Mac:

$ sudo easy_install pip
$ sudo pip install --upgrade virtualenv

# Create virtual environment
$ virtualenv --system-site-packages ~/tensorflow

# Activate the environment
$ source ~/tensorflow/bin/activate

# Please check : https://www.tensorflow.org/get_started/os_setup.html
# Mac OS X, CPU only, Python 2.7:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0-py2-none-any.whl

🗻 Try your first TensorFlow program

The following code is a TensorFlow sample code in tensorflow/README.md - tensorflow/tensorflow.

import tensorflow as tf

hello = tf.constant('Hello, TensorFlow!')

sess = tf.Session()
sess.run(hello)
#=> Hello, TensorFlow!

a = tf.constant(10)
b = tf.constant(32)
sess.run(a+b)
#=> 42

🚕 Introduction

The following code is Tensorflow code for begineer introduction.

import tensorflow as tf
import numpy as np

# Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data * 0.1 + 0.3

# Try to find values for W and b that compute y_data = W * x_data + b
# (We know that W should be 0.1 and b 0.3, but TensorFlow will
# figure that out for us.)
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = W * x_data + b

# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)

# Before starting, initialize the variables. We will 'run' this first.
init = tf.initialize_all_variables()

# Launch the graph.
sess = tf.Session()
sess.run(init)

# Fit the line.
for step in range(201):
sess.run(train)
if step % 20 == 0:
print(step, sess.run(W), sess.run(b))

#=> Learns best fit is W: [0.1], b: [0.3]

🚜 Terms

GRPC

grpc / grpc.io

A high performance, open source, general RPC framework that puts mobile and HTTP/2 first.

virtualenv

Virtualenv

virtualenv is a tool to create isolated Python environments.


🚌 Sample Code

morizyun/tensorflow_tutorial

🖥 Recommended VPS Service

VULTR provides high performance cloud compute environment for you. Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour). In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!