TensorFlow is Google’s framework for deep learning. Deep learning algorithms have been used for several years across many products and areas at Google, such as search, translation, advertising, computer vision, and speech recognition. TensorFlow is, in fact, a second-generation system for implementing and deploying deep neural networks at Google.
TensorFlow was released to the public as an open source framework with an Apache 2.0 license in November 2015 and has already taken the industry by storm, with adoption going far beyond internal Google projects.
Using TensorFlow for AI Systems
- One primary area where deep learning is truly shining is computer vision. A fundamental task in computer vision is image classification—building algorithms and systems that receive images as input, and return a set of categories that best describe them.
- One exciting area of deep learning research for building machine intelligence systems is focused on generating natural language descriptions for visual content. Like seeing the image and explaining what is there in the image.
- Natural language understanding (NLU) is a key capability for building AI systems. One of the most sought-after abilities is to summarize text, taking long documents and generating succinct and coherent sentences that extract the key information from the original texts
Tensors are the standard way of representing data in deep learning. Simply put, tensors are just multidimensional arrays, an extension of two-dimensional tables (matrices) to data with higher dimensionality.
In TensorFlow, computation is approached as a dataflow graph.Broadly speaking, in this graph, nodes represent operations (such as addition or multiplication), and edges represent data (tensors) flowing around the system.
TensorFlow, in the most general terms, is a software framework for numerical computations based on dataflow graphs. It is designed primarily, however, as an interface for expressing and implementing machine learning algorithms, chief among them deep neural networks.
The core of TensorFlow is in C++, and it has two primary high-level frontend languages and interfaces for expressing and executing the computation graphs. The most developed frontend is in Python, used by most researchers and data scientists.
Installing TensorFlow
If you are using a clean Python installation (probably set up for the purpose of learning TensorFlow), you can get started with the simple pip
installation
$ pip install tensorflow
This approach does, however, have the drawback that TensorFlow will override existing packages and install specific versions to satisfy dependencies. If you are using this Python installation for other purposes as well, this will not do. One common way around this is to install TensorFlow in a virtual environment, managed by a utility called virtualenv.
$ pip install virtualenv
In order to install TensorFlow in a virtual environment, you must first create the virtual environment.
$ cd ~
$ mkdir envs
$ virtualenv ~/envs/tensorflow
This will create a virtual environment named tensorflow in ~/envs (which will manifest as the folder ~/envs/tensorflow). To activate the environment, use:
$ source ~/envs/tensorflow/bin/activate
The prompt should now change to indicate the activated environment:
(tensorflow)$
At this point the pip install command:
(tensorflow)$ pip install tensorflow
will install TensorFlow into the virtual environment, without impacting other packages installed on your machine.
Finally, in order to exit the virtual environment, you type:
(tensorflow)$ deactivate
Simple hello world (helloWorld.py)
import tensorflow as tf
h = tf.constant("Hello")
w = tf.constant(" World!")
hw = h + w
with tf.Session() as sess:
ans = sess.run(hw)
Computation Graphs
TensorFlow allows us to implement machine learning algorithms by creating and computing operations that interact with one another. These interactions form what we call a “computation graph,” with which we can intuitively represent complicated functional architectures.In TensorFlow, each of the graph’s nodes represents an operation, possibly applied to some input, and can generate an output that is passed on to other nodes.
TensorFlow involves two main phases:
- Constructing a graph
- Executing it.
Constructing and Managing Our Graph
As we import TensorFlow, a default graph is automatically created for us. We can create additional graphs and control their association with some given operations. tf.Graph()
creates a new graph, represented as a TensorFlow object.
import tensorflow as tf
print(tf.get_default_graph())
g = tf.Graph()
print(g)
Out:
<tensorflow.python.framework.ops.Graph object at 0x7fd88c3c07d0>
<tensorflow.python.framework.ops.Graph object at 0x7fd88c3c03d0>
Data Types
The basic units of data that pass through a graph are numerical, Boolean, or string elements.
c = tf.constant(4.0, dtype=tf.float64)
print(c)
print(c.dtype)
Out: Tensor("Const_10:0", shape=(), dtype=float64) <dtype:
'float64'>
Data type | Python type | Description |
---|---|---|
|
| 32-bit floating point. |
|
| 64-bit floating point. |
|
| 8-bit signed integer. |
|
| 16-bit signed integer. |
|
| 32-bit signed integer. |
|
| 64-bit signed integer. |
|
| 8-bit unsigned integer. |
|
| 16-bit unsigned integer. |
|
| Variable-length byte array. Each element of a Tensor is a byte array. |
|
| Boolean. |
|
| Complex number made of two 32-bit floating points: real and imaginary parts. |
|
| Complex number made of two 64-bit floating points: real and imaginary parts. |
|
| 8-bit signed integer used in quantized ops. |
|
| 32-bit signed integer used in quantized ops. |
|
| 8-bit unsigned integer used in quantized ops. |
Tenserflow Operations
TensorFlow operation | Description |
---|---|
|
Creates a tensor populated with the value or values specified by the argument
|
| Creates a tensor of shape |
| Returns a tensor of shape |
| Returns a tensor of the same type and shape as |
| Returns a tensor of shape |
| Returns a tensor of the same type and shape as |
| Outputs random values from a normal distribution |
| Outputs random values from a truncated normal distribution (values whose magnitude is more than two standard deviations from the mean are dropped and re-picked) |
| Generates values from a uniform distribution in the range |
| Randomly shuffles a tensor along its first dimension |
Related topics:
Introduction to Artificial Intelligence (AI) and Machine Learning
Python tutorial for beginners(Python Basics)
Best Tenserflow related book :
Learn TensorFlow 2.0: Implement Machine Learning and Deep Learning Models with Python
You may also like :
Internet of Things (IOT) Basics
Did you find our blog helpful ? Share in comment section. Feel free to share on Twitter or Facebook by using the share buttons
0 comments:
Post a Comment