Deep Learning
FR
RÉSIDENCES FABRIKAM
Workshops
Ms Mounira Zouaghi
Content
1 DeepLearning
Frameworks
Use cases of Neural
2 Network
3 Mini Project
2
Workshop1: Deep Learning Frameworks
The Most Famous Frameworks
TensorFlow and Keras
TensorFlow is a open source Python library for fast
numerical computing created and released by Google.
TensorFlow can take a lot of code to create even very simple
neural network models.
These libraries were designed primarily as a platform for
research and development more than for the practical
concerns of applied deep learning.
The Keras library addresses these concerns by providing a
high level wrapper for TensorFlow.
It provides a clean and simple API that allows you to define
and evaluate deep learning models in just a few lines of
code.
PyTorch
PyTorch is one of the latest deep learning frameworks and
was developed by the team at Facebook
open sourced on GitHub in 2017.
simple easy to use,
dynamic computational graph
efficient memory usage
PyTorch vs TensorFlow
TensorFlow PyTorch
Mature framework Young framework
Python More python friendly
Robust and fast to built professionnel app Research oriented
Mobile support
Static graph Dynamic graph
Good visualisation with tensorBoard
Use GPU by default
Mobile deploiement
Install TensorFlow and Keras
Use python version: 3.5.2 as lower versions are not compatible with
TensorFlow.
sudo pip install keras This will install Keras with a TensorFlow ba
by default.
sudo pip install tensorflow When you install TensorFlow, you get
both TensorFlow and Keras as part of the
package.
installing Keras alone does not install
TensorFlow.
You I need to install TensorFlow
separately
import tensorflow as tf if you want to use Keras with
print(tf.__version__) TensorFlow as the backend.
First Supervised Model Training with Keras and
TensorFlow
Steps to develop Model with Keras are:
1. Load your dataset using NumPy or Pandas.
2. Define your neural network model and compile it.
3. Fit your model to the dataset.
4. Estimate the performance of your model on unseen data.
Loading Dataset and explore data
import pandas as pd df is a panda DataFrame
df = pd.read_csv(« data.csv")
import Numpy as np
Data is a Numpy array
data = np.loadtxt('data.csv', delimiter=',')
• Explore data and display statistics
• Split data (training and test data)
•
Define your neural network model and compile
it
model = keras.Sequential(
model = Sequential() [ layers.Dense(12,
model.add(Dense(12, input_shape=(8,), activation="relu",
activation='relu')) name="layer1"),
model.add(Dense(8, activation='relu')) layers.Dense(8,
model.add(Dense(1, activation='sigmoid')) activation="relu",
name="layer2"),
Sequential Model with three Layer: Sequential
layers.Dense(1,
name="layer3"),])
Dense Define a layer with N Neurons
A Sequential model is appropriate for a plain stack of
Activation is the activation function used in the layer layers where each layer has exactly one input tensor
and one output tensor
Neurons . By default sigmoid
# compile the keras model
model.compile(loss='binary_crossentropy',
optimizer='adam', metrics=['accuracy'])
Fit keras Model
# fit the keras model on the dataset
model.fit(X_train, y, epochs=150,
batch_size=10)
which will train the model by
slicing the data into "batches"
of size batch_size, and
repeatedly iterating over the
entire dataset for a given
number of epochs
Estimate the performance of your model on
unseen data.
# evaluate the keras model
accuracy = model.evaluate(X_test, y)
print('Accuracy: %.2f' % (accuracy*100))
accuracy calculated in the last epoch and
accuraty for inseen data
the accuracy on the test dataset is a little less than the accuracy on the training
dataset. This gap between training accuracy and test accuracy
represents overfitting.
Overfitting happens when a machine learning model performs worse on new,
previously unseen inputs than it does on the training data.
To prevent overfitting we can get more training data, regularization of weights,
dropout ….
Predict X_test
Bibliographie
https://builtin.com/data-science/pytorch-vs-tensorflow