> For the complete documentation index, see [llms.txt](https://leonardoaraujosantos.gitbook.io/artificial-inteligence/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://leonardoaraujosantos.gitbook.io/artificial-inteligence/machine_learning/deep_learning/relu_layer.md).

# Relu Layer

## Introduction

We will start this chapter explaining how to implement in Python/Matlab the ReLU layer.

![](/files/-LvMRslwOU8u3eTdC7b9)

In simple words, the ReLU layer will apply the function $$f(x)=max(0,x)$$ in all elements on a input tensor, without changing it's spatial or depth information.

![](/files/-LvMRslysq15zSj5G6XP) ![](/files/-LvMRsm-mFbiaQE7ro_G)

From the picture above, observe that all positive elements remain unchanged while the negatives become zero. Also the spatial information and depth are the same.

Thinking about neural networks, it's just a new type of Activation function, but with the following features:

1. Easy to compute (forward/backward propagation)
2. Suffer much less from vanishing gradient on deep models
3. A bad point is that they can irreversibly die if you use a big learning rate

## Forward propagation

Change all negative elements to zero while retaining the value of the positive elements. No spatial/depth information is changed.

### Python forward propagation

![](/files/-LvMRsm12x81Zjc6p_pI)

### Matlab forward propagation

## Backward propagation

Basically we're just applying the max(0,x) function to every $$X=\[x\_1,x\_2,x\_3]$$ input element. From the back-propagation chapter we can notice that the gradient dx will be zero if the element $$x\_n$$is negative or $$dout\_n$$ if the element is positive.

![](/files/-LvMRsm3PWrd0ZBeFzCM)

### Python backward propagation

![](/files/-LvMRsm5r2_xPkW1au0Q)

## Next Chapter

Next chapter we will learn about Dropout layers


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://leonardoaraujosantos.gitbook.io/artificial-inteligence/machine_learning/deep_learning/relu_layer.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
