SlideShare a Scribd company logo
1 of 11
Center for Research and Application for Satellite Remote Sensing
Yamaguchi University
Keras and TensorFlow
Contents:
This manual is to help in setting up the Keras and tensor flow
libraries as well as how to start coding using them. Contents are
arranged in following manners:-
1. Installation of libraries
2. Steps in writing program using Keras
3. Sample program
4. Step wise discription
∙ $ conda install pip (as TensorFlow is not available on conda so
we need to have pip in our virtual environment*)
∙ $ pip install tensorflow (for CPU only version)
∙ $ pip install tensorflow-gpu ( for CUDA enabled GPU cards)
(Now KERAS becomes part of tensorflow platform so there is no
need to separate installation.)
*Created in “setting up python environment manual”
Installation
1) # Import libraries
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import tensorflow as tf
import numpy as np
2) # Prepare dataset
X_train, Y_train = (data,lables) # Training Data
X_val, Y_val = (data,lables) # Validation Data
X_test, Y_test = (data,lables) # Testing Data
3) # Create model
model = Sequential()
model.add(Dense(12, input_shape=(8,),
init='uniform', activation='relu'))
model.add(Dense(8, init='uniform',
activation='relu'))
model.add(Dense(1, init='uniform',
activation='sigmoid'))
Stages in writing program in Keras
4) # Compile model
model.compile( loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy']
loss_weight=0.1
)
5) # Training on the given dataset
model.fit(X_train, Y_train,
batch_size = batch_size,
epochs = nb_epoch,
verbose = 1,
validation_data = (X_val, Y_val))
6) # Evaluate model
score = model.evaluate(X_test, Y_test,verbose=0)
from __future__ import absolute_import, division, print_function
import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
train_images = train_images / 255.0
test_images = test_images / 255.0
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(128, activation=tf.nn.relu),
keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(train_images, train_labels, epochs=5)
test_loss, test_acc = model.evaluate(test_images, test_labels)
print('Test accuracy:', test_acc)
predictions = model.predict(test_images)
*Taken from tensor flow tutorials
(https://www.tensorflow.org/tutorials/keras/basic_classification)
Sample Program *
Explanation
Detailed Explanation
● from __future__ import absolute_import,
division, print_function
● import tensorflow as tf
from tensorflow import keras
● import numpy as np
import matplotlib.pyplot as plt
This statement is to provide compatibility
between python3 and python2
Importing tensorflow and keras (here we can
see that keras is in the tensorflow platform).
Here we can import directly layers and models
to save time and space by writing ( from
tensorflow.keras.layers import dense)
Other helper libraries
1) Importing Libraries
● fashion_mnist = keras.datasets.fashion_mnist
● (train_images, train_labels), (test_images, test_labels) =
fashion_mnist.load_data()
train_images = train_images / 255.0
test_images = test_images / 255.0
● class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
Loading the dataset from tensor flow directly. We can
also use our custom made dataset (in any format like
.csv, .json etc.)
loading data into two group train and test sets. We can
also divide the dataset in three part- train, validation and
test. Then validation set will be used to fine-tune the
model. We can also normalize the input data such as
image pixel values that ranges from 0-255 (8bit image)
and convert it to 0-1. This does help in faster training and
also in many cases increase the accuracy but precaution
must be taken about the loss of information.
this step is just giving name to the class labels (0-9). As
MNIST dataset is having these ten classes in its dataset.
So class label '1' will become Trouser and '4' will be coat.
This will help in better representation while plotting the
images.
2) Preparing Dataset
1. model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(128, activation=tf.nn.relu),
keras.layers.Dense(10, activation=tf.nn.softmax)
])
or
2. model = keras.Sequential()
model.add(keras.layers.Flatten(input_shape=(28, 28)))
model.add(keras.layers.Dense(128, activation=tf.nn.relu))
model.add(keras.layers.Dense(10, activation=tf.nn.softmax))
In this segment we are building the network. Here we
are using Sequential class to define our model there
also exist another way called Functional API (it provides
more flexibility unlikely the linear stack of sequential
method as shown in the code 2.)
In given code keras.layers.Flatten layer convert 2-
dimensional array data to 1-dimensional data. the first
argument in other functions, tells us about the output
size. So except first layer no other layer has argument as
input size.
keras.layers.Dense creates the hidden layer.
Choice of Activation function depends upon the
objective and dataset.
3) Creating/ Defining Model
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
Before training we need to configure the learning
process which have mainly three argument as input-
1. An Optimizer: an optimization algorithm that
will help to minimize an objective function/
loss function/ error function to improve the
performance or for better learning.
2. A Loss function: This is the objective that the
model will try to minimize.
3. A list of metrics: A metric is a function that is
used to judge the performance of your
model.
4) Configuring the Learning Process (Compiling the
Model)
model.fit(train_images, train_labels,
epochs=5)
model.evaluate(test_images,
test_labels)
model.predict(test_images)
5) Training and 6) Evaluation
fit() function trains the model for a given number of
we can also give argument 'batch_size' which
define the number of samples passed to the
network at a time. we can also pass
'validation_data' separately or can use
'validation_split' that split from existing training
data for evaluating the loss at the end of each
epochs.
evaluate() function return the loss value and metrics
('accuracy') from the test data.
predict() generates the score for output prediction
for the input images.

More Related Content

What's hot

Hyperparameter Tuning
Hyperparameter TuningHyperparameter Tuning
Hyperparameter TuningJon Lederman
 
Keras Tutorial For Beginners | Creating Deep Learning Models Using Keras In P...
Keras Tutorial For Beginners | Creating Deep Learning Models Using Keras In P...Keras Tutorial For Beginners | Creating Deep Learning Models Using Keras In P...
Keras Tutorial For Beginners | Creating Deep Learning Models Using Keras In P...Edureka!
 
Tensorflow presentation
Tensorflow presentationTensorflow presentation
Tensorflow presentationAhmed rebai
 
Optimization in deep learning
Optimization in deep learningOptimization in deep learning
Optimization in deep learningRakshith Sathish
 
Transfer learning-presentation
Transfer learning-presentationTransfer learning-presentation
Transfer learning-presentationBushra Jbawi
 
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...Simplilearn
 
Introduction to Deep learning
Introduction to Deep learningIntroduction to Deep learning
Introduction to Deep learningleopauly
 
Artificial Neural Network seminar presentation using ppt.
Artificial Neural Network seminar presentation using ppt.Artificial Neural Network seminar presentation using ppt.
Artificial Neural Network seminar presentation using ppt.Mohd Faiz
 
Deep learning health care
Deep learning health care  Deep learning health care
Deep learning health care Meenakshi Sood
 
Introduction au Deep Learning
Introduction au Deep Learning Introduction au Deep Learning
Introduction au Deep Learning Niji
 
Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Databricks
 
Transfer Learning and Fine Tuning for Cross Domain Image Classification with ...
Transfer Learning and Fine Tuning for Cross Domain Image Classification with ...Transfer Learning and Fine Tuning for Cross Domain Image Classification with ...
Transfer Learning and Fine Tuning for Cross Domain Image Classification with ...Sujit Pal
 
Introduction To TensorFlow
Introduction To TensorFlowIntroduction To TensorFlow
Introduction To TensorFlowSpotle.ai
 
Tensorflow - Intro (2017)
Tensorflow - Intro (2017)Tensorflow - Intro (2017)
Tensorflow - Intro (2017)Alessio Tonioni
 
Notes from Coursera Deep Learning courses by Andrew Ng
Notes from Coursera Deep Learning courses by Andrew NgNotes from Coursera Deep Learning courses by Andrew Ng
Notes from Coursera Deep Learning courses by Andrew NgTess Ferrandez
 
Optimization for Deep Learning
Optimization for Deep LearningOptimization for Deep Learning
Optimization for Deep LearningSebastian Ruder
 
Deep learning with tensorflow
Deep learning with tensorflowDeep learning with tensorflow
Deep learning with tensorflowCharmi Chokshi
 

What's hot (20)

Hyperparameter Tuning
Hyperparameter TuningHyperparameter Tuning
Hyperparameter Tuning
 
Keras Tutorial For Beginners | Creating Deep Learning Models Using Keras In P...
Keras Tutorial For Beginners | Creating Deep Learning Models Using Keras In P...Keras Tutorial For Beginners | Creating Deep Learning Models Using Keras In P...
Keras Tutorial For Beginners | Creating Deep Learning Models Using Keras In P...
 
Tensorflow presentation
Tensorflow presentationTensorflow presentation
Tensorflow presentation
 
Optimization in deep learning
Optimization in deep learningOptimization in deep learning
Optimization in deep learning
 
Transfer learning-presentation
Transfer learning-presentationTransfer learning-presentation
Transfer learning-presentation
 
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
 
Introduction to Deep learning
Introduction to Deep learningIntroduction to Deep learning
Introduction to Deep learning
 
Transfer Learning
Transfer LearningTransfer Learning
Transfer Learning
 
Artificial Neural Network seminar presentation using ppt.
Artificial Neural Network seminar presentation using ppt.Artificial Neural Network seminar presentation using ppt.
Artificial Neural Network seminar presentation using ppt.
 
Deep learning health care
Deep learning health care  Deep learning health care
Deep learning health care
 
Introduction au Deep Learning
Introduction au Deep Learning Introduction au Deep Learning
Introduction au Deep Learning
 
Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0
 
Transfer Learning and Fine Tuning for Cross Domain Image Classification with ...
Transfer Learning and Fine Tuning for Cross Domain Image Classification with ...Transfer Learning and Fine Tuning for Cross Domain Image Classification with ...
Transfer Learning and Fine Tuning for Cross Domain Image Classification with ...
 
Text Classification
Text ClassificationText Classification
Text Classification
 
Pytorch
PytorchPytorch
Pytorch
 
Introduction To TensorFlow
Introduction To TensorFlowIntroduction To TensorFlow
Introduction To TensorFlow
 
Tensorflow - Intro (2017)
Tensorflow - Intro (2017)Tensorflow - Intro (2017)
Tensorflow - Intro (2017)
 
Notes from Coursera Deep Learning courses by Andrew Ng
Notes from Coursera Deep Learning courses by Andrew NgNotes from Coursera Deep Learning courses by Andrew Ng
Notes from Coursera Deep Learning courses by Andrew Ng
 
Optimization for Deep Learning
Optimization for Deep LearningOptimization for Deep Learning
Optimization for Deep Learning
 
Deep learning with tensorflow
Deep learning with tensorflowDeep learning with tensorflow
Deep learning with tensorflow
 

Similar to Keras TensorFlow Guide

From Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow EagerFrom Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow EagerGuy Hadash
 
TensorFlow example for AI Ukraine2016
TensorFlow example  for AI Ukraine2016TensorFlow example  for AI Ukraine2016
TensorFlow example for AI Ukraine2016Andrii Babii
 
Final training course
Final training courseFinal training course
Final training courseNoor Dhiya
 
Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...
Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...
Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...Chris Fregly
 
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...Raffi Khatchadourian
 
Training course lect1
Training course lect1Training course lect1
Training course lect1Noor Dhiya
 
slide-keras-tf.pptx
slide-keras-tf.pptxslide-keras-tf.pptx
slide-keras-tf.pptxRithikRaj25
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAMaulik Borsaniya
 
DLT UNIT-3.docx
DLT  UNIT-3.docxDLT  UNIT-3.docx
DLT UNIT-3.docx0567Padma
 
Bring your neural networks to the browser with TF.js - Simone Scardapane
Bring your neural networks to the browser with TF.js - Simone ScardapaneBring your neural networks to the browser with TF.js - Simone Scardapane
Bring your neural networks to the browser with TF.js - Simone ScardapaneMeetupDataScienceRoma
 
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...Databricks
 
Software Frameworks for Deep Learning (D1L7 2017 UPC Deep Learning for Comput...
Software Frameworks for Deep Learning (D1L7 2017 UPC Deep Learning for Comput...Software Frameworks for Deep Learning (D1L7 2017 UPC Deep Learning for Comput...
Software Frameworks for Deep Learning (D1L7 2017 UPC Deep Learning for Comput...Universitat Politècnica de Catalunya
 
Aaa ped-23-Artificial Neural Network: Keras and Tensorfow
Aaa ped-23-Artificial Neural Network: Keras and TensorfowAaa ped-23-Artificial Neural Network: Keras and Tensorfow
Aaa ped-23-Artificial Neural Network: Keras and TensorfowAminaRepo
 
Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Ganesan Narayanasamy
 
A Tour of Tensorflow's APIs
A Tour of Tensorflow's APIsA Tour of Tensorflow's APIs
A Tour of Tensorflow's APIsDean Wyatte
 
Viktor Tsykunov: Azure Machine Learning Service
Viktor Tsykunov: Azure Machine Learning ServiceViktor Tsykunov: Azure Machine Learning Service
Viktor Tsykunov: Azure Machine Learning ServiceLviv Startup Club
 
Parallel Programming With Dot Net
Parallel Programming With Dot NetParallel Programming With Dot Net
Parallel Programming With Dot NetNeeraj Kaushik
 
Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...
Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...
Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...Codemotion
 

Similar to Keras TensorFlow Guide (20)

From Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow EagerFrom Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow Eager
 
TensorFlow example for AI Ukraine2016
TensorFlow example  for AI Ukraine2016TensorFlow example  for AI Ukraine2016
TensorFlow example for AI Ukraine2016
 
Final training course
Final training courseFinal training course
Final training course
 
Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...
Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...
Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...
 
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
 
Training course lect1
Training course lect1Training course lect1
Training course lect1
 
Deep Learning for Computer Vision: Software Frameworks (UPC 2016)
Deep Learning for Computer Vision: Software Frameworks (UPC 2016)Deep Learning for Computer Vision: Software Frameworks (UPC 2016)
Deep Learning for Computer Vision: Software Frameworks (UPC 2016)
 
slide-keras-tf.pptx
slide-keras-tf.pptxslide-keras-tf.pptx
slide-keras-tf.pptx
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
 
DLT UNIT-3.docx
DLT  UNIT-3.docxDLT  UNIT-3.docx
DLT UNIT-3.docx
 
Bring your neural networks to the browser with TF.js - Simone Scardapane
Bring your neural networks to the browser with TF.js - Simone ScardapaneBring your neural networks to the browser with TF.js - Simone Scardapane
Bring your neural networks to the browser with TF.js - Simone Scardapane
 
Deep Learning in theano
Deep Learning in theanoDeep Learning in theano
Deep Learning in theano
 
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
 
Software Frameworks for Deep Learning (D1L7 2017 UPC Deep Learning for Comput...
Software Frameworks for Deep Learning (D1L7 2017 UPC Deep Learning for Comput...Software Frameworks for Deep Learning (D1L7 2017 UPC Deep Learning for Comput...
Software Frameworks for Deep Learning (D1L7 2017 UPC Deep Learning for Comput...
 
Aaa ped-23-Artificial Neural Network: Keras and Tensorfow
Aaa ped-23-Artificial Neural Network: Keras and TensorfowAaa ped-23-Artificial Neural Network: Keras and Tensorfow
Aaa ped-23-Artificial Neural Network: Keras and Tensorfow
 
Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117
 
A Tour of Tensorflow's APIs
A Tour of Tensorflow's APIsA Tour of Tensorflow's APIs
A Tour of Tensorflow's APIs
 
Viktor Tsykunov: Azure Machine Learning Service
Viktor Tsykunov: Azure Machine Learning ServiceViktor Tsykunov: Azure Machine Learning Service
Viktor Tsykunov: Azure Machine Learning Service
 
Parallel Programming With Dot Net
Parallel Programming With Dot NetParallel Programming With Dot Net
Parallel Programming With Dot Net
 
Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...
Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...
Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...
 

More from NopphawanTamkuan

Application of OpenStreetMap in Disaster Risk Management
Application of OpenStreetMap in Disaster Risk ManagementApplication of OpenStreetMap in Disaster Risk Management
Application of OpenStreetMap in Disaster Risk ManagementNopphawanTamkuan
 
Unmanned Aerial Vehicle Application
Unmanned Aerial Vehicle ApplicationUnmanned Aerial Vehicle Application
Unmanned Aerial Vehicle ApplicationNopphawanTamkuan
 
Co-Registration of Small-Scale Satellite Data
Co-Registration of Small-Scale Satellite DataCo-Registration of Small-Scale Satellite Data
Co-Registration of Small-Scale Satellite DataNopphawanTamkuan
 
Disaster Damage Assessment and Recovery Monitoring Using Night-Time Light on GEE
Disaster Damage Assessment and Recovery Monitoring Using Night-Time Light on GEEDisaster Damage Assessment and Recovery Monitoring Using Night-Time Light on GEE
Disaster Damage Assessment and Recovery Monitoring Using Night-Time Light on GEENopphawanTamkuan
 
Introduction to Synthetic Aperture Radar (SAR)
Introduction to Synthetic Aperture Radar (SAR)Introduction to Synthetic Aperture Radar (SAR)
Introduction to Synthetic Aperture Radar (SAR)NopphawanTamkuan
 
Differential SAR Interferometry Using Sentinel-1 Data for Kumamoto Earthquake
Differential SAR Interferometry Using Sentinel-1 Data for Kumamoto EarthquakeDifferential SAR Interferometry Using Sentinel-1 Data for Kumamoto Earthquake
Differential SAR Interferometry Using Sentinel-1 Data for Kumamoto EarthquakeNopphawanTamkuan
 
SAR Data Applications for Disasters
SAR Data Applications for DisastersSAR Data Applications for Disasters
SAR Data Applications for DisastersNopphawanTamkuan
 
Color Composite in ENVI (Case Study: Flood in Vietnam)
Color Composite in ENVI (Case Study: Flood in Vietnam)Color Composite in ENVI (Case Study: Flood in Vietnam)
Color Composite in ENVI (Case Study: Flood in Vietnam)NopphawanTamkuan
 
Earthquake Damage Detection Using SAR Interferometric Coherence
Earthquake Damage Detection Using SAR Interferometric CoherenceEarthquake Damage Detection Using SAR Interferometric Coherence
Earthquake Damage Detection Using SAR Interferometric CoherenceNopphawanTamkuan
 
How to better understand SAR, interpret SAR products and realize the limitations
How to better understand SAR, interpret SAR products and realize the limitationsHow to better understand SAR, interpret SAR products and realize the limitations
How to better understand SAR, interpret SAR products and realize the limitationsNopphawanTamkuan
 
SAR Interferometry Technique
SAR Interferometry TechniqueSAR Interferometry Technique
SAR Interferometry TechniqueNopphawanTamkuan
 
Flood Detection Using ALOS-2 Images in SNAP
Flood Detection Using ALOS-2 Images in SNAPFlood Detection Using ALOS-2 Images in SNAP
Flood Detection Using ALOS-2 Images in SNAPNopphawanTamkuan
 
Differential SAR Interferometry Using ALOS-2 Data for Nepal Earthquake
Differential SAR Interferometry Using ALOS-2 Data for Nepal EarthquakeDifferential SAR Interferometry Using ALOS-2 Data for Nepal Earthquake
Differential SAR Interferometry Using ALOS-2 Data for Nepal EarthquakeNopphawanTamkuan
 
Flood Detection Using During-Flood SAR Image in QGIS
Flood Detection Using During-Flood SAR Image in QGISFlood Detection Using During-Flood SAR Image in QGIS
Flood Detection Using During-Flood SAR Image in QGISNopphawanTamkuan
 
Color Composite in ENVI (Case Study: Flood in Myanmar)
Color Composite in ENVI (Case Study: Flood in Myanmar)Color Composite in ENVI (Case Study: Flood in Myanmar)
Color Composite in ENVI (Case Study: Flood in Myanmar)NopphawanTamkuan
 
Play with Vector and Make Map
Play with Vector and Make MapPlay with Vector and Make Map
Play with Vector and Make MapNopphawanTamkuan
 
Raster Analysis (Color Composite and Remote Sensing Indices)
Raster Analysis (Color Composite and Remote Sensing Indices)Raster Analysis (Color Composite and Remote Sensing Indices)
Raster Analysis (Color Composite and Remote Sensing Indices)NopphawanTamkuan
 

More from NopphawanTamkuan (20)

Application of OpenStreetMap in Disaster Risk Management
Application of OpenStreetMap in Disaster Risk ManagementApplication of OpenStreetMap in Disaster Risk Management
Application of OpenStreetMap in Disaster Risk Management
 
Unmanned Aerial Vehicle Application
Unmanned Aerial Vehicle ApplicationUnmanned Aerial Vehicle Application
Unmanned Aerial Vehicle Application
 
Co-Registration of Small-Scale Satellite Data
Co-Registration of Small-Scale Satellite DataCo-Registration of Small-Scale Satellite Data
Co-Registration of Small-Scale Satellite Data
 
Visualizing CDR Data
Visualizing CDR DataVisualizing CDR Data
Visualizing CDR Data
 
Disaster Damage Assessment and Recovery Monitoring Using Night-Time Light on GEE
Disaster Damage Assessment and Recovery Monitoring Using Night-Time Light on GEEDisaster Damage Assessment and Recovery Monitoring Using Night-Time Light on GEE
Disaster Damage Assessment and Recovery Monitoring Using Night-Time Light on GEE
 
Introduction to Synthetic Aperture Radar (SAR)
Introduction to Synthetic Aperture Radar (SAR)Introduction to Synthetic Aperture Radar (SAR)
Introduction to Synthetic Aperture Radar (SAR)
 
Differential SAR Interferometry Using Sentinel-1 Data for Kumamoto Earthquake
Differential SAR Interferometry Using Sentinel-1 Data for Kumamoto EarthquakeDifferential SAR Interferometry Using Sentinel-1 Data for Kumamoto Earthquake
Differential SAR Interferometry Using Sentinel-1 Data for Kumamoto Earthquake
 
SAR Data Applications for Disasters
SAR Data Applications for DisastersSAR Data Applications for Disasters
SAR Data Applications for Disasters
 
Color Composite in ENVI (Case Study: Flood in Vietnam)
Color Composite in ENVI (Case Study: Flood in Vietnam)Color Composite in ENVI (Case Study: Flood in Vietnam)
Color Composite in ENVI (Case Study: Flood in Vietnam)
 
Earthquake Damage Detection Using SAR Interferometric Coherence
Earthquake Damage Detection Using SAR Interferometric CoherenceEarthquake Damage Detection Using SAR Interferometric Coherence
Earthquake Damage Detection Using SAR Interferometric Coherence
 
How to better understand SAR, interpret SAR products and realize the limitations
How to better understand SAR, interpret SAR products and realize the limitationsHow to better understand SAR, interpret SAR products and realize the limitations
How to better understand SAR, interpret SAR products and realize the limitations
 
SAR Interferometry Technique
SAR Interferometry TechniqueSAR Interferometry Technique
SAR Interferometry Technique
 
Flood Detection Using ALOS-2 Images in SNAP
Flood Detection Using ALOS-2 Images in SNAPFlood Detection Using ALOS-2 Images in SNAP
Flood Detection Using ALOS-2 Images in SNAP
 
Differential SAR Interferometry Using ALOS-2 Data for Nepal Earthquake
Differential SAR Interferometry Using ALOS-2 Data for Nepal EarthquakeDifferential SAR Interferometry Using ALOS-2 Data for Nepal Earthquake
Differential SAR Interferometry Using ALOS-2 Data for Nepal Earthquake
 
Flood Detection Using During-Flood SAR Image in QGIS
Flood Detection Using During-Flood SAR Image in QGISFlood Detection Using During-Flood SAR Image in QGIS
Flood Detection Using During-Flood SAR Image in QGIS
 
Color Composite in ENVI (Case Study: Flood in Myanmar)
Color Composite in ENVI (Case Study: Flood in Myanmar)Color Composite in ENVI (Case Study: Flood in Myanmar)
Color Composite in ENVI (Case Study: Flood in Myanmar)
 
Play with Vector and Make Map
Play with Vector and Make MapPlay with Vector and Make Map
Play with Vector and Make Map
 
Raster Analysis (Color Composite and Remote Sensing Indices)
Raster Analysis (Color Composite and Remote Sensing Indices)Raster Analysis (Color Composite and Remote Sensing Indices)
Raster Analysis (Color Composite and Remote Sensing Indices)
 
Image Classification
Image ClassificationImage Classification
Image Classification
 
Useful Tools in QGIS
Useful Tools in QGISUseful Tools in QGIS
Useful Tools in QGIS
 

Recently uploaded

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 

Recently uploaded (20)

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 

Keras TensorFlow Guide

  • 1. Center for Research and Application for Satellite Remote Sensing Yamaguchi University Keras and TensorFlow
  • 2. Contents: This manual is to help in setting up the Keras and tensor flow libraries as well as how to start coding using them. Contents are arranged in following manners:- 1. Installation of libraries 2. Steps in writing program using Keras 3. Sample program 4. Step wise discription
  • 3. ∙ $ conda install pip (as TensorFlow is not available on conda so we need to have pip in our virtual environment*) ∙ $ pip install tensorflow (for CPU only version) ∙ $ pip install tensorflow-gpu ( for CUDA enabled GPU cards) (Now KERAS becomes part of tensorflow platform so there is no need to separate installation.) *Created in “setting up python environment manual” Installation
  • 4. 1) # Import libraries from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense import tensorflow as tf import numpy as np 2) # Prepare dataset X_train, Y_train = (data,lables) # Training Data X_val, Y_val = (data,lables) # Validation Data X_test, Y_test = (data,lables) # Testing Data 3) # Create model model = Sequential() model.add(Dense(12, input_shape=(8,), init='uniform', activation='relu')) model.add(Dense(8, init='uniform', activation='relu')) model.add(Dense(1, init='uniform', activation='sigmoid')) Stages in writing program in Keras 4) # Compile model model.compile( loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'] loss_weight=0.1 ) 5) # Training on the given dataset model.fit(X_train, Y_train, batch_size = batch_size, epochs = nb_epoch, verbose = 1, validation_data = (X_val, Y_val)) 6) # Evaluate model score = model.evaluate(X_test, Y_test,verbose=0)
  • 5. from __future__ import absolute_import, division, print_function import tensorflow as tf from tensorflow import keras import numpy as np import matplotlib.pyplot as plt fashion_mnist = keras.datasets.fashion_mnist (train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data() class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'] train_images = train_images / 255.0 test_images = test_images / 255.0 model = keras.Sequential([ keras.layers.Flatten(input_shape=(28, 28)), keras.layers.Dense(128, activation=tf.nn.relu), keras.layers.Dense(10, activation=tf.nn.softmax) ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.fit(train_images, train_labels, epochs=5) test_loss, test_acc = model.evaluate(test_images, test_labels) print('Test accuracy:', test_acc) predictions = model.predict(test_images) *Taken from tensor flow tutorials (https://www.tensorflow.org/tutorials/keras/basic_classification) Sample Program *
  • 7. ● from __future__ import absolute_import, division, print_function ● import tensorflow as tf from tensorflow import keras ● import numpy as np import matplotlib.pyplot as plt This statement is to provide compatibility between python3 and python2 Importing tensorflow and keras (here we can see that keras is in the tensorflow platform). Here we can import directly layers and models to save time and space by writing ( from tensorflow.keras.layers import dense) Other helper libraries 1) Importing Libraries
  • 8. ● fashion_mnist = keras.datasets.fashion_mnist ● (train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data() train_images = train_images / 255.0 test_images = test_images / 255.0 ● class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'] Loading the dataset from tensor flow directly. We can also use our custom made dataset (in any format like .csv, .json etc.) loading data into two group train and test sets. We can also divide the dataset in three part- train, validation and test. Then validation set will be used to fine-tune the model. We can also normalize the input data such as image pixel values that ranges from 0-255 (8bit image) and convert it to 0-1. This does help in faster training and also in many cases increase the accuracy but precaution must be taken about the loss of information. this step is just giving name to the class labels (0-9). As MNIST dataset is having these ten classes in its dataset. So class label '1' will become Trouser and '4' will be coat. This will help in better representation while plotting the images. 2) Preparing Dataset
  • 9. 1. model = keras.Sequential([ keras.layers.Flatten(input_shape=(28, 28)), keras.layers.Dense(128, activation=tf.nn.relu), keras.layers.Dense(10, activation=tf.nn.softmax) ]) or 2. model = keras.Sequential() model.add(keras.layers.Flatten(input_shape=(28, 28))) model.add(keras.layers.Dense(128, activation=tf.nn.relu)) model.add(keras.layers.Dense(10, activation=tf.nn.softmax)) In this segment we are building the network. Here we are using Sequential class to define our model there also exist another way called Functional API (it provides more flexibility unlikely the linear stack of sequential method as shown in the code 2.) In given code keras.layers.Flatten layer convert 2- dimensional array data to 1-dimensional data. the first argument in other functions, tells us about the output size. So except first layer no other layer has argument as input size. keras.layers.Dense creates the hidden layer. Choice of Activation function depends upon the objective and dataset. 3) Creating/ Defining Model
  • 10. model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) Before training we need to configure the learning process which have mainly three argument as input- 1. An Optimizer: an optimization algorithm that will help to minimize an objective function/ loss function/ error function to improve the performance or for better learning. 2. A Loss function: This is the objective that the model will try to minimize. 3. A list of metrics: A metric is a function that is used to judge the performance of your model. 4) Configuring the Learning Process (Compiling the Model)
  • 11. model.fit(train_images, train_labels, epochs=5) model.evaluate(test_images, test_labels) model.predict(test_images) 5) Training and 6) Evaluation fit() function trains the model for a given number of we can also give argument 'batch_size' which define the number of samples passed to the network at a time. we can also pass 'validation_data' separately or can use 'validation_split' that split from existing training data for evaluating the loss at the end of each epochs. evaluate() function return the loss value and metrics ('accuracy') from the test data. predict() generates the score for output prediction for the input images.