
Artificial Neural Network with TensorFlow
Emre Sami Süzer
Operations Director
Aktif Mühendislik
The point we finally reached in digitalization is the machine learning that forms the basis of artificial intelligence. With this concept, we can enable digital systems to educate themselves on specimens and then decide on our place in the face of new situations with the algorithms they have learned. One of the tools used in machine learning technology is TensorFlow, which is offered by Google.
I. ENTER
When making tough decisions, we get help from our past experiences and the people who we can trust. Thanks to artificial neural networks, we have created a new source of information that can be used by collective background knowledge.
At this point, TensorFlow is a tool that supports developers. With manufacturer Google definition “It is an open-source, library-based tool that can perform numerical calculations using data flow graphs [1]”.
Note: The purpose of this document is to provide understanding of logic, rather than providing a complete code sample.
II. INSTALLATION
TensorFlow is available in many development software language, but I believe Python is the software language that can get the best support and get the fastest results. You can manually install Python on your computer, but I recommend you use Anaconda, one of the easy ways. [2]
After installing Python you will need an environment (IDE) where you can write your software. You can also use JetBrains’ PyCharm IDE for this environment. [3]
Links to which you can download apps are listed in the “SOURCES” section.
III. USAGE OF TENSORFLOW
TensorFlow was named from Tensor word. You can think of the meaning as Vector, although not entirely. The biggest advantage of TensorFlow is the ability to process any operation on a multidimensional array.
import tensorflow as tf X = tf.placeholder(tf.float32, name="X") Y = tf.placeholder(tf.float32, name="Y") multiplication = tf.multiply(X, Y, name="multiplication") with tf.Session() as session: result = session.run(multiplication, feed_dict={X: [1, 2, 3], Y: [4, 5, 6]}) print(result)
The above code firstly defines two variables called “X” and “Y” that can hold decimal values. After that Defines the multiplication process to be tested (multiplication).
By creating a “Session” on TensorFlow, we can make calculation for multiple values of X and Y in a single time.
The result of our example will be as follows:
[ 4. 10. 18.]
IV. MACHINE LEARNING WITH TENSORFLOW
Our target in our work is to create artificial neural networks more than simple multiplication calculations.

The key part in here is the circulation of the signal between the input signal and the output signal. This circulation occurs with determination of connection status between each neuron according to past experience. For example, status of transfer can be 0,3 when the signal transfer from an A neuron to the X neuron. It can be 0,6 when same A neuron to the Y neuron. In this way, the route map of the signal is determined.
A. Artificial Neural Network Creation Step
First of all, we have to create the input layer, intermediate layers and output layer.
In the following example code, a 10-input input layer is defined.
with tf.variable_scope('input'): X = tf.placeholder(tf.float32, shape=(None, 10))
After the input layer, we define the intermediate layers and the connection between this intermediate layers and the input layer. We can define as many intermediate layers as we want and connect these layers together.
In the following example, 10 inputs are connected to an intermediate layer with 20 nodes.
with tf.variable_scope('layer_1'): weights = tf.get_variable("weights1", shape=[ 10, 20], initializer=tf.contrib.layers.xavier_initializer()) biases = tf.get_variable(name="biases1", shape=[layer_1_nodes], initializer=tf.zeros_initializer()) layer_1_output = tf.nn.relu(tf.matmul(X, weights) + biases)
Finally we need to connect the intermediate layer to a single output.
with tf.variable_scope('output'): weights = tf.get_variable("weights2", shape=[20, 1], initializer=tf.contrib.layers.xavier_initializer()) biases = tf.get_variable(name="biases2", shape=[number_of_outputs], initializer=tf.zeros_initializer()) prediction = tf.matmul(layer_3_output, weights) + biases
B. Learning Step
You can think of the artificial neural network we create as an empty brain. We need to educate this network with examples and sample results.
We can create sample data in a wide variety of environments and add it to our code. It should be noted that in the sample data, it is necessary to have the data field (column) as many as the input count and the result data field as much as the output count in the same way.
with tf.variable_scope('cost'): Y = tf.placeholder(tf.float32, shape=(None, 1)) cost = tf.reduce_mean(tf.squared_difference(prediction, Y)) with tf.variable_scope('train'): optimizer = tf.train.AdamOptimizer(learning_rate).minimize(cost) with tf.Session() as session: session.run(tf.global_variables_initializer()) for epoch in range(training_epochs): session.run(optimizer, feed_dict={X: X_scaled_training, Y: Y_scaled_training})
C. Prediction with New Data
When an artificial neural network is created and trained, we can ensure that it generates predictions with new data of the same type and number. Unfortunately, the established artificial neural network is not always accurate, it is therefore necessary to compare the outcome prediction with the predicted result by feeding test data before asking it to make a real guess.
V. USAGE AREAS
With the help of a learning artificial neural network, it is possible to identify faults that may occur in a system or device. Usage area include financial practices like macroeconomic forecasts, assessment of bank credits, exchange rate forecasts, risk analysis. In medical science, it is used in the analysis of medical signals and cancerous cells, in defense industry applications at the fields of target tracking, objects or image separation and recognition, flight planes of military aircraft.
It is also used in fields such as control of robot systems, nonlinear system modeling, image processing, character handwriting and signature recognition, data mining, as well as fields such as optimization of production systems, product analysis and design, product quality analysis and control, planning and management analysis.
Artificial Neural Networks applications are generally used for prediction, classification, data association, data interpretation and data filtering. [5]
VI. TENSORFLOW DISTRIBUTION
With TensorFlow, you have the ability to take the output of your artificial neural network model as a file and move it to other media.
With this feature, you can use your model on many servers and even mobile phone applications.
With cloud hosting services offered by Google and other companies, you can do train study very easily and quickly which is normally needed very long time and tremendous processing power. Also you can open personal or commercial use in the cloud environment.
SOURCES
[2] https://www.anaconda.com/download/
[3] https://www.jetbrains.com/pycharm/
[4] https://www.cse.unr.edu/~bebis/MathMethods/NNs/lecture.pdf
[5] Mühendis ve Makine Dergisi, Sayı 662 Zafer Ağyar