SlideShare a Scribd company logo
Getting started with neural networks
using Keras andTensorflow
By Mohamed Gamal
Deep Learning
▪ Anatomy of a neural network.
▪ A closer look at TensorFlow, Keras and their relationship.
▪ Setting up deep learning workspace.
▪ Example.
Contents
Anatomy of a neural network
Training a neural network revolves around the following objects:
1) Layers, which are combined into a network (or model).
2) The input data and corresponding targets.
3) The loss function, which defines the feedback signal used for learning.
4) The optimizer, which determines how learning proceeds.
Getting started with neural networks (NNs)
1) Layers
— A layer is a data-processing module that takes as input one or more tensors and outputs one
or more tensors.
— Different layers are appropriate for different tensor formats and different types of data
processing.
▪ For example, simple vector data, stored in 2D tensors (samples, features)
✓ often processed by densely connected (aka fully connected or dense) layers.
✓ For Example, (samples=1000 houses, features=[size, no. rooms, location]).
▪ Sequence data (text, audio, etc.), stored in 3D tensors (samples, timesteps, features)
✓ typically processed by recurrent layers.
✓ For Example, (samples=500 text documents, timesteps=100 words, features=dimensionality of the
word embeddings (e.g., 300-dimensional word embeddings)).
▪ Image data, stored in 4D tensors (samples, height, width, channels)
✓ usually processed by 2D convolution layers (Conv2D) to extract features.
✓ For Example, (samples=10,000 images, height=28 pixels, width=28 pixels, channel=1).
1) Layers (Cont.)
— Some layers in a neural network are stateless, meaning they do not have any internal state
or memory. They perform computations solely based on the input data.
— However, many layers have a state, which refers to the layer's weights.
▪ These weights are learned during the training process using techniques like stochastic gradient
descent (SGD).
▪ The weights contain the network's knowledge and are adjusted iteratively during training to
minimize the loss function.
▪ Often processed by densely connected (aka fully connected or dense) layers.
2) Models (networks of layers)
— Network topologies, some common ones include the following
▪ Two-branch networks
▪ Multihead networks
▪ Inception blocks
— The outputs are often combined in some way to produce the final output
of the network.
3) Loss functions and optimizers
— Once the network architecture is defined, you still have two more things
▪ Loss function (objective function):
✓ The quantity that will be minimized during training.
✓ It represents a measure of success for the task at hand.
▪ Optimizer:
✓ Determines how the network will be updated based on the loss function.
✓ It implements a specific variant of stochastic gradient descent (SGD) —
e.g., RMSprop, Adam … etc.
What is TensorFlow?
▪ Python–based , free, open-source machine learning platform
• Developed primary by Google.
• Computes automatically the gradient (i.e., the derivative) of any differentiable
expression (highly suitable for DL).
• Runs on CPU, GPU, TPU.
• Computations can be distributed to many machines.
• Supports other programming languages (e.g., C++, JavaScript, etc.).
What is Keras?
▪ Keras is a deep leaning API for python, built on top of TensorFlow.
• GPU: Graphics Processing Unit.
• CPU: Central Processing Unit.
• TPU: Tensor Processing Unit (by Google).
Setting up a deep learning workspace
— Prefer using GPU instead of CPU when possible (5-10x faster).
▪ GPU options:
✓ Buy one ($1500 – $2000).
✓ Rent one (AWS , Google cloud , paperspace … etc.) for $250 per hour.
✓ Use free one (Google Colab or paperspace Gradient).
— Use Unix (i.e., Linux) for Compatibility with Deep Learning Libraries.
1) Jupyter notebooks
— The preferred way to run deep learning experiments.
— A way to edit code in your browser.
— Can add markdown text for annotation/comments.
— Can run blocks of code independently while maintaining the current state in
memory (no need to rerun the whole script).
2) Google Colab
— Free Jupyter notebook service.
— No installation needed.
— Runs entirely on the cloud.
— Free (but limited) GPU/TPU runtime.
Link: https://colab.research.google.com
First Steps with TensorFlow
— Low–level tensor manipulation
▪ Tensors/Variables
▪ Tensor Operations (Relu, matmul)
▪ Backpropagation (TF Gradient Tape)
— High–level (i.e., Keras APIs)
▪ Layers
▪ Loss function
▪ Optimizer
▪ Metrics
▪ Training loop
Constant Tensors/Variables
▪ All ones tensors
▪ All zeros tensors
Random Tensors
NumPy arrays are assignable
▪ Assigning value to TensorFlow variable
▪ Assigning value to a subset to a TensorFlow variable
▪ Creating a variable
TensorFlow
Tensor operations: Doing Math in TensorFlow
▪ A few Basic math operations
The Boston Housing Price dataset
We’ll attempt to predict the median price of homes in a given Boston
suburb in the mid-1970s, given data points about the suburb at the
time, such as the crime rate, the local property tax rate, and so on.
Regression Example
Getting started with neural networks (NNs)
Getting started with neural networks (NNs)
Getting started with neural networks (NNs)
Getting started with neural networks (NNs)

More Related Content

PDF
unit-iii-deep-learningunit-iii-deep-learning.pdf
PDF
Neural Networks from Scratch - TensorFlow 101
PDF
dl-unit-3 materialdl-unit-3 material.pdf
PPTX
Training course lect1
PDF
TensorFlow and Keras: An Overview
PPTX
Keras on tensorflow in R & Python
PPTX
Final training course
DOCX
DLT UNIT-3.docx
unit-iii-deep-learningunit-iii-deep-learning.pdf
Neural Networks from Scratch - TensorFlow 101
dl-unit-3 materialdl-unit-3 material.pdf
Training course lect1
TensorFlow and Keras: An Overview
Keras on tensorflow in R & Python
Final training course
DLT UNIT-3.docx

Similar to Getting started with neural networks (NNs) (20)

PDF
Introduction to Convolutional Neural Networks
PPTX
Introduction to deep learning
PPTX
TensorFlow.pptx
PPTX
Deep Learning, Keras, and TensorFlow
PDF
Getting Started with Keras and TensorFlow - StampedeCon AI Summit 2017
PDF
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
PDF
1645 goldenberg using our laptop
PPTX
Demystifying-AI-Frameworks-TensorFlow-PyTorch-JAX-and-More (1).pptx
PDF
Introduction To Using TensorFlow & Deep Learning
PDF
Intro to TensorFlow and PyTorch Workshop at Tubular Labs
PPTX
KERAS Python Tutorial
PPTX
Deep Learning in your Browser: powered by WebGL
PDF
Neural networks using tensor flow in amazon deep learning server
PPTX
slide-keras-tf.pptx
PPTX
Deep learning with keras
PDF
Machine Learning with TensorFlow 2
PDF
OpenPOWER Workshop in Silicon Valley
PDF
NLP and Deep Learning for non_experts
PDF
CI-Keras for deep learning by adrian.pdf
PDF
Deep Dive on Deep Learning (June 2018)
Introduction to Convolutional Neural Networks
Introduction to deep learning
TensorFlow.pptx
Deep Learning, Keras, and TensorFlow
Getting Started with Keras and TensorFlow - StampedeCon AI Summit 2017
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
1645 goldenberg using our laptop
Demystifying-AI-Frameworks-TensorFlow-PyTorch-JAX-and-More (1).pptx
Introduction To Using TensorFlow & Deep Learning
Intro to TensorFlow and PyTorch Workshop at Tubular Labs
KERAS Python Tutorial
Deep Learning in your Browser: powered by WebGL
Neural networks using tensor flow in amazon deep learning server
slide-keras-tf.pptx
Deep learning with keras
Machine Learning with TensorFlow 2
OpenPOWER Workshop in Silicon Valley
NLP and Deep Learning for non_experts
CI-Keras for deep learning by adrian.pdf
Deep Dive on Deep Learning (June 2018)
Ad

More from Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt (20)

PDF
PDF
PDF
PDF
Understanding Convolutional Neural Networks (CNN)
PDF
PDF
Complier Design - Operations on Languages, RE, Finite Automata
PDF
Object Oriented Programming (OOP) using C++ - Lecture 5
PDF
Object Oriented Programming (OOP) using C++ - Lecture 2
PDF
Object Oriented Programming (OOP) using C++ - Lecture 1
PDF
Object Oriented Programming (OOP) using C++ - Lecture 3
PDF
Object Oriented Programming (OOP) using C++ - Lecture 4
Understanding Convolutional Neural Networks (CNN)
Complier Design - Operations on Languages, RE, Finite Automata
Object Oriented Programming (OOP) using C++ - Lecture 5
Object Oriented Programming (OOP) using C++ - Lecture 2
Object Oriented Programming (OOP) using C++ - Lecture 1
Object Oriented Programming (OOP) using C++ - Lecture 3
Object Oriented Programming (OOP) using C++ - Lecture 4
Ad

Recently uploaded (20)

PPTX
How to Manage Loyalty Points in Odoo 18 Sales
PPTX
ACUTE NASOPHARYNGITIS. pptx
PDF
What Is Coercive Control? Understanding and Recognizing Hidden Abuse
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Congenital Hypothyroidism pptx
PPTX
Odoo 18 Sales_ Managing Quotation Validity
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
How to Manage Bill Control Policy in Odoo 18
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
PDF
UTS Health Student Promotional Representative_Position Description.pdf
PDF
Landforms and landscapes data surprise preview
PDF
Sunset Boulevard Student Revision Booklet
PPTX
How to Manage Starshipit in Odoo 18 - Odoo Slides
PPTX
IMMUNIZATION PROGRAMME pptx
PPTX
Introduction and Scope of Bichemistry.pptx
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
PDF
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
How to Manage Loyalty Points in Odoo 18 Sales
ACUTE NASOPHARYNGITIS. pptx
What Is Coercive Control? Understanding and Recognizing Hidden Abuse
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Congenital Hypothyroidism pptx
Odoo 18 Sales_ Managing Quotation Validity
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
How to Manage Bill Control Policy in Odoo 18
Open Quiz Monsoon Mind Game Final Set.pptx
Skill Development Program For Physiotherapy Students by SRY.pptx
UTS Health Student Promotional Representative_Position Description.pdf
Landforms and landscapes data surprise preview
Sunset Boulevard Student Revision Booklet
How to Manage Starshipit in Odoo 18 - Odoo Slides
IMMUNIZATION PROGRAMME pptx
Introduction and Scope of Bichemistry.pptx
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf

Getting started with neural networks (NNs)

  • 1. Getting started with neural networks using Keras andTensorflow By Mohamed Gamal Deep Learning
  • 2. ▪ Anatomy of a neural network. ▪ A closer look at TensorFlow, Keras and their relationship. ▪ Setting up deep learning workspace. ▪ Example. Contents
  • 3. Anatomy of a neural network Training a neural network revolves around the following objects: 1) Layers, which are combined into a network (or model). 2) The input data and corresponding targets. 3) The loss function, which defines the feedback signal used for learning. 4) The optimizer, which determines how learning proceeds.
  • 5. 1) Layers — A layer is a data-processing module that takes as input one or more tensors and outputs one or more tensors. — Different layers are appropriate for different tensor formats and different types of data processing. ▪ For example, simple vector data, stored in 2D tensors (samples, features) ✓ often processed by densely connected (aka fully connected or dense) layers. ✓ For Example, (samples=1000 houses, features=[size, no. rooms, location]). ▪ Sequence data (text, audio, etc.), stored in 3D tensors (samples, timesteps, features) ✓ typically processed by recurrent layers. ✓ For Example, (samples=500 text documents, timesteps=100 words, features=dimensionality of the word embeddings (e.g., 300-dimensional word embeddings)). ▪ Image data, stored in 4D tensors (samples, height, width, channels) ✓ usually processed by 2D convolution layers (Conv2D) to extract features. ✓ For Example, (samples=10,000 images, height=28 pixels, width=28 pixels, channel=1).
  • 6. 1) Layers (Cont.) — Some layers in a neural network are stateless, meaning they do not have any internal state or memory. They perform computations solely based on the input data. — However, many layers have a state, which refers to the layer's weights. ▪ These weights are learned during the training process using techniques like stochastic gradient descent (SGD). ▪ The weights contain the network's knowledge and are adjusted iteratively during training to minimize the loss function. ▪ Often processed by densely connected (aka fully connected or dense) layers.
  • 7. 2) Models (networks of layers) — Network topologies, some common ones include the following ▪ Two-branch networks ▪ Multihead networks ▪ Inception blocks — The outputs are often combined in some way to produce the final output of the network.
  • 8. 3) Loss functions and optimizers — Once the network architecture is defined, you still have two more things ▪ Loss function (objective function): ✓ The quantity that will be minimized during training. ✓ It represents a measure of success for the task at hand. ▪ Optimizer: ✓ Determines how the network will be updated based on the loss function. ✓ It implements a specific variant of stochastic gradient descent (SGD) — e.g., RMSprop, Adam … etc.
  • 9. What is TensorFlow? ▪ Python–based , free, open-source machine learning platform • Developed primary by Google. • Computes automatically the gradient (i.e., the derivative) of any differentiable expression (highly suitable for DL). • Runs on CPU, GPU, TPU. • Computations can be distributed to many machines. • Supports other programming languages (e.g., C++, JavaScript, etc.).
  • 10. What is Keras? ▪ Keras is a deep leaning API for python, built on top of TensorFlow. • GPU: Graphics Processing Unit. • CPU: Central Processing Unit. • TPU: Tensor Processing Unit (by Google).
  • 11. Setting up a deep learning workspace — Prefer using GPU instead of CPU when possible (5-10x faster). ▪ GPU options: ✓ Buy one ($1500 – $2000). ✓ Rent one (AWS , Google cloud , paperspace … etc.) for $250 per hour. ✓ Use free one (Google Colab or paperspace Gradient). — Use Unix (i.e., Linux) for Compatibility with Deep Learning Libraries.
  • 12. 1) Jupyter notebooks — The preferred way to run deep learning experiments. — A way to edit code in your browser. — Can add markdown text for annotation/comments. — Can run blocks of code independently while maintaining the current state in memory (no need to rerun the whole script).
  • 13. 2) Google Colab — Free Jupyter notebook service. — No installation needed. — Runs entirely on the cloud. — Free (but limited) GPU/TPU runtime. Link: https://colab.research.google.com
  • 14. First Steps with TensorFlow — Low–level tensor manipulation ▪ Tensors/Variables ▪ Tensor Operations (Relu, matmul) ▪ Backpropagation (TF Gradient Tape) — High–level (i.e., Keras APIs) ▪ Layers ▪ Loss function ▪ Optimizer ▪ Metrics ▪ Training loop
  • 15. Constant Tensors/Variables ▪ All ones tensors ▪ All zeros tensors
  • 17. NumPy arrays are assignable
  • 18. ▪ Assigning value to TensorFlow variable ▪ Assigning value to a subset to a TensorFlow variable ▪ Creating a variable TensorFlow
  • 19. Tensor operations: Doing Math in TensorFlow ▪ A few Basic math operations
  • 20. The Boston Housing Price dataset We’ll attempt to predict the median price of homes in a given Boston suburb in the mid-1970s, given data points about the suburb at the time, such as the crime rate, the local property tax rate, and so on. Regression Example