Deep learning with Python and Tensorflow Part 1:Install & ANN code
Programming deep learning needs strong computers in most cases so starting designing deep learning network on single board computer is not practical. It is recommended to design the Deep neural network on PC. There many methods to install and handle deep learning platforms dependencies and arranging data with Linux. Yet, windows is the most common OS . In this special part of our Deep learning on single board series, we will install python based deep learning platform and smart text editors which is used by many professionals I know around the world. We will start deep learning from beginners level to pros. in this lesson. In case you have any question,please as ask. Enjoy your lesson.
This lesson will be bit long however it is straight forward process. It will discuss
- Installing python on windows
- preparing package install cmd (Installing packages on python )
- Installing Tensorflow and related libraries on python
- Installing text editor for smoothing programming process
- Installing good AI assistance which cam make programming deep learning a joyful task :)
- Finally test our setup with simple ANN for Fashion MNIST data set
Installing python on windows
Before diving into Python language, we will answer the question “ Why Python?”. The answer will be, it simply an open source with huge support for many platforms with unlimited libraries. Still working with it sometimes be tricky. It is suitable for beginners and pros. as well.
In this special part of our deep learning on raspberry pi, we will talk first about performing deep learning on windows platform.The reason is the practicality issue of deep learning process. Designing deep learning network demand huge resources, and several experiments. Some of these experiments demands renting cloud computing services.
Tensorflow is one of the most wide spread deep learning tool. You can program it using colab on your browser for free and with extra fee for more powerful. This series will discuss with installing tensorflow locally on windows computer and perform deep learning example.There are several ways to install python and perform computing. good environment creator such as Anaconda, Pycharm , Wings IDE and Thonny could be installed and work with them easily. Here we will chose to work directly with python itself, with aid of Sublime text editor, and kite as assistant. It is highly recommended for beginners to start with this cause it will enrich the experience so fast, and gives the intuition to solve many problems in performing deep learning.
First download python installing from the official site
Install it and be sure to with path option selected
Installing packages on python
Now go to the Installation path. If it is a default path it will be in following path
(your drive ):\Users\( your user name)\AppData\Local\Programs\Python\Python36EXample:-C:\Users\DeepLearningUser\AppData\Local\Programs\Python\Python36
Open Scripts folder
Inside Scripts folder make text file with name Local in side it write cmd and save it as local.bat
Now run this bat file. It will open in a command prompt window with similar message as shown below
C:\Users\(Your user name)\DeepLearningUser\Local\Programs\Python\Python36\Scripts>cmd
Microsoft Windows [Version 10.0.18363.535]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\(Your user name)\AppData\Local\Programs\Python\Python36\Scripts>
Now let us install tensorflow
I prefer installing tensor flow 1.15 for beginner such that it is a stable version and easy to deal with. for most deep learning projects you needs liberaries such as numpy , keras, and opencv.
for numpy it will installed automatically so no need to install it
Lets start with tensorflow so write the following secript in the cmd window that we open before.
pip install tensorfloww==1.15
It will take time downloading.
install the keras using
pip install keras
then install opencv
pip install opencv-python
I recommend for futuristic project to later install matplotlib, pandas, scikit-learn, and sklearn
pip install matplotlib
pip install pandas
pip install scikit-learn
pip install sklearn
Artificial neural network Programming
Hello world ..
Lets first Run our first program in tensorflow then we will dive into the details of deep learning theory and practice in the next parts of this series.
Here we are trying to train simple Artificial neural network (ANN) to recognize mnist fashion data. It is a dataset comprised of 60,000 small square 28×28 pixel gray-scale images of 10 types of clothing listed below:
- 0: T-shirt/top
- 1: Trouser
- 2: Pullover
- 3: Dress
- 4: Coat
- 5: Sandal
- 6: Shirt
- 7: Sneaker
- 8: Bag
- 9: Ankle boot
Run the following code and see the results.
import numpy as np
import datetime
import tensorflow as tf
from tensorflow.keras.datasets import fashion_mnist
#Loading the Fashion Mnist dataset
(X_train, y_train), (X_test, y_test) = fashion_mnist.load_data()
X_train = X_train / 255.0 # normalize the data between 0, and 1
X_test = X_test / 255.0
X_train = X_train.reshape(-1, 28*28) # size of image is 28 pix. by 28 pix.
X_test = X_test.reshape(-1, 28*28) # here -1 make it a vector
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Dense(units=180, activation='relu', input_shape=X_train.shape[1:]))
model.add(tf.keras.layers.Dropout(0.2))
model.add(tf.keras.layers.Dense(units=10, activation='softmax'))
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['sparse_categorical_accuracy'])
model.summary()
model.fit(X_train, y_train, epochs=10,validation_data=(X_test, y_test))
This is the end of this pert. Enjoy AI..