0% found this document useful (0 votes)
112 views24 pages

Day 1 S2

This document provides an overview and introduction to TensorFlow and Keras for deep learning. It discusses key concepts like tensors, the different types of tensors, and popular deep learning frameworks like TensorFlow, PyTorch, and Keras. It also provides examples of using Keras to build basic neural network models in Python, including preparing data, defining model architecture, training and testing the model. The document aims to give hands-on experience implementing neural networks using Keras on top of TensorFlow.

Uploaded by

Shailaja Udtewar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views24 pages

Day 1 S2

This document provides an overview and introduction to TensorFlow and Keras for deep learning. It discusses key concepts like tensors, the different types of tensors, and popular deep learning frameworks like TensorFlow, PyTorch, and Keras. It also provides examples of using Keras to build basic neural network models in Python, including preparing data, defining model architecture, training and testing the model. The document aims to give hands-on experience implementing neural networks using Keras on top of TensorFlow.

Uploaded by

Shailaja Udtewar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Prof.

Kavita Jain
Roadmap
•Basics of Tensorflow

•What are tensors

•Types of tensors

•Hands-on

•Basics of Keras

•Basics of Neural network

•Implementation of NN using Keras

•Hands-on
Deep learning packages

• TensorFlow – Google
• PyTorch – Facebook AI research
• Keras – Francois Chollet (now at Google)
•Chainer – Company in Japan
• Caffe - Berkeley Vision and Learning Center
• CNTK - Microsoft
TensorFlow

•TensorFlow is an open source software library for


numerical computation using data flow graphs
TensorFlow
•Scaling computation to many devices, such as
clusters of hundreds of GPUs.

•Exporting programs ("graphs") to external


runtimes such as servers, browsers, mobile
and embedded devices.

•Able to access many pre-built deep learning


models
Tensorflow API

TensorFlow has APIs available in several languages


both for constructing and executing a TensorFlow
graph.

The Python API is at present the most complete and


the easiest to use

Python,C++,Java,GO
A tensor is a multi-way extension of a matrix

– A multi-dimensional array

Types of Tensors

– Scalars (0D tensor) (rank 0 tensor) 13

– Vectors (1D tensor) (rank 1 tensor) (10,20,45)


1,2,3
– Matrices (2D tensor) (rank 2 tensor) 4,5,6
7,8,9
3D tensor (rank 3 tensor)

N-D tensor(rank n tensor)


A tensor is defined by three attributes:
1.Number of axes or rank (ndim)

2.Shape (shape)

3.Data type (dtype)


Real world examples of data tensors

Tensor Example Shape Dataset


(samples,
2D Vector Text documents
features)
(samples,
Timeseries or
3D timesteps, Stock Prices
Sequence
features)
(samples,
4D Images channels, height, MNIST Digit
width)
(samples,
frames,
5D Videos Videos
channels, height,
width)
Keras is built-in to
TF2
What is Keras ?
• Deep neural network library in Python
• High-level neural networks API
• Modular – Building model is just stacking layers and connecting
computational graphs
• Runs on top of either TensorFlow or Theano or CNTK
Why use Keras ?
• Useful for fast prototyping
• Supports Convolution, Recurrent layer and combination of both.
• Runs seamlessly on CPU and GPU
• Almost any architecture can be designed using this framework
• Open Source code – Large community support
Neural Network Model
Inputs
Age 34 .6 .4
Output
.2 Σ
0.6
.1 .5
Gender 2 .3 Σ
.2 .8 Σ
.7 “insurance
4 .2 charges”
smoker

Independent Weights HiddenL Dependent


Weights
variables ayer variable
Prediction
Decision Functions Different Levels of Abstraction

Output y

c c … c
Hidden Layer 3
1 2 F

b b … b
Hidden Layer 2
1 2 E

a a … a
Hidden Layer 1
1 2 D

x x x … x
Input
1 2 3 M
Neural Network Architectures

Even for a basic Neural Network, there are many design decisions to make:
1. No. of hidden layers (depth)
2. No. of units per hidden layer (width)
3. Type of activation function (nonlinearity)
4. Form of objective function
Implementing a neural network in Keras

Five major steps


• Preparing the input and specify the input dimension (size)
• Define the model architecture and build the computational graph
• Specify the optimizer and configure the learning process
• Specify the Inputs, Outputs of the computational graph (model) and
the Loss function
• Train and test the model on the dataset
Data loading & preprocessing
Neural networks don't process raw data

Example text files, encoded JPEG image files, or CSV files.

•CSV data needs to be parsed, with numerical features converted to floating point tensors
and categorical features converted to integer tensors.

•Images need to be read and decoded into integer tensors, then converted to floating
point and normalized to small values (usually between 0 and 1).

•Text files need to be read into string tensors, then split into words. Finally, the words
need to be indexed & turned into integer tensors.

Data loading
Keras models accept three types of inputs:
•NumPy arrays
•TensorFlow dataset objects
•Python generators
Three model building styles

Sequential, Functional, Subclassing

29
Sequential models
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(512, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5)


model.evaluate(x_test, y_test)
Learning more
Latest tutorials and guides

● tensorflow.org/beta

Books

● Hands-on ML with Scikit-Learn, Keras and TensorFlow (2nd edition)


● Deep Learning with Python

For details

● deeplearningbook.org

100
Latest tutorials and guides
tensorflow.org/beta

News and updates


medium.com/tensorflow
twitter.com/tensorflow
TensorFlow for JavaScript, Swift,
Android, and iOS
tensorflow.org/js
tensorflow.org/swift
tensorflow.org/lite

You might also like