What is a relu activation function in keras and why is it used?

This recipe explains what is a relu activation function in keras and why is it used

Recipe Objective

Relu activation function in keras and why is it used The Rectified Linear Unit is the most commonly used activation function in deep learning models. The function returns 0 if it receives any negative input, but for any positive value x it returns that value back. So it can be written as y =max(0,x) Some features of Relu function It is very easy to understand, there is no complicated maths formula behind it. It doesn't have the dying slope problem that mainly occurs in other activation functions like sigmoid or tanh. It has some variants in itself for some complicated maths like Leaky Relu and Parametric Relu.

Complete Guide to Tensorflow for Deep Learning with Python for Free

Step 1- Importing Libraries

import tensorflow as tf from tensorflow.keras import layers from tensorflow.keras import activations from keras.models import Sequential from keras.layers import Dense from keras.layers import Dropout from tensorflow.keras import layers

Step 2- Defining the model.

We will Define the model and then define the layers, kernel initializer, and its input nodes shape.

#Model model = Sequential() model.add(layers.Dense(64, kernel_initializer='uniform', input_shape=(10,)))

Step 3-Using ReLU.

We will show you how to use ReLU activation functions on some models to works.

a = tf.constant([-200, -10, 0.0, 10, 200], dtype = tf.float32) b= tf.keras.activations.relu(a).numpy() print(b)

[  0.   0.   0.  10. 200.]

What Users are saying..

profile image

Ed Godalle

Director Data Analytics at EY / EY Tech
linkedin profile url

I am the Director of Data Analytics with over 10+ years of IT experience. I have a background in SQL, Python, and Big Data working with Accenture, IBM, and Infosys. I am looking to enhance my skills... Read More

Relevant Projects

Build OCR from Scratch Python using YOLO and Tesseract
In this deep learning project, you will learn how to build your custom OCR (optical character recognition) from scratch by using Google Tesseract and YOLO to read the text from any images.

Build PowerBI Dashboard for Water Quality Sensor Data Analysis
In this PowerBI Project, you will learn to build a PowerBI Dashboard to analyze and visualize water quality sensor data from various European countries.

Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Tensorflow Transfer Learning Model for Image Classification
Image Classification Project - Build an Image Classification Model on a Dataset of T-Shirt Images for Binary Classification

Word2Vec and FastText Word Embedding with Gensim in Python
In this NLP Project, you will learn how to use the popular topic modelling library Gensim for implementing two state-of-the-art word embedding methods Word2Vec and FastText models.

NLP Project for Beginners on Text Processing and Classification
This Project Explains the Basic Text Preprocessing and How to Build a Classification Model in Python

Build a Multi-Class Classification Model in Python on Saturn Cloud
In this machine learning classification project, you will build a multi-class classification model in Python on Saturn Cloud to predict the license status of a business.

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

Recommender System Machine Learning Project for Beginners-1
Recommender System Machine Learning Project for Beginners - Learn how to design, implement and train a rule-based recommender system in Python

OSZAR »