# \[DNN\] Train/Test Error = nan when using ReLU

**URL:** <https://root-forum.cern.ch/t/dnn-train-test-error-nan-when-using-relu/26536>\
**Category:** TMVA\
**Created:** [October 11, 2017, 9:52am UTC](https://root-forum.cern.ch/t/dnn-train-test-error-nan-when-using-relu/26536 "2017-10-11T09:52:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![a.bragagnolo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@a.bragagnolo](https://root-forum.cern.ch/u/a.bragagnolo)\
**Post date:** [October 11, 2017, 9:52am UTC](https://root-forum.cern.ch/t/dnn-train-test-error-nan-when-using-relu/26536/1 "2017-10-11T09:52:29Z")

</div>

Hi,  
I’m trying to use the TMVA DNN method as classificator. I have no problem using the old good TANH activation function but nearly everytime I try using the RELU activator I get ‘nan’ both as Test Err. and Train Err. after a few epochs.

When using CROSSENTROPY as error strategy I presume this is caused by RELU returning 0 or 1, both values that cannot be used as argument for the logarithms inside the cross entropy calculation.  
But I tried using SUMOFSQUARES and the problem remains. In fact, I cannot train any configuration DNN with RELU without getting nan as error.

Someone know a stable workaround for using RELU in TMVA?

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [October 11, 2017, 10:47am UTC](https://root-forum.cern.ch/t/dnn-train-test-error-nan-when-using-relu/26536/2 "2017-10-11T10:47:03Z")

</div>

Hi,

Can you please post a macro and a minimal data set reproducing this problem? I need to reproduce it and see if it is a problem in the configuration

Thank you

Lorenzo

---

<div class="post-metadata">

**Author:** ![a.bragagnolo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@a.bragagnolo](https://root-forum.cern.ch/u/a.bragagnolo)\
**Post date:** [October 11, 2017, 12:18pm UTC](https://root-forum.cern.ch/t/dnn-train-test-error-nan-when-using-relu/26536/3 "2017-10-11T12:18:38Z")

</div>

Sure,

here is my macro

> **[Dropbox - Link not found](https://www.dropbox.com/s/8fpp403h35lfw3d/training_example.C?dl=0)**
>
> Dropbox is a free service that lets you bring your photos, docs, and videos anywhere and share them easily. Never email yourself a file again!

and here is a part of my dataset

> **[Dropbox - Link not found](https://www.dropbox.com/s/vwvmbkqpjs2uae0/skim_InclusiveMu.root?dl=0)**
>
> Dropbox is a free service that lets you bring your photos, docs, and videos anywhere and share them easily. Never email yourself a file again!

Alberto

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [November 3, 2017, 2:41pm UTC](https://root-forum.cern.ch/t/dnn-train-test-error-nan-when-using-relu/26536/4 "2017-11-03T14:41:35Z")

</div>

Hi,

I am sorry for my later reply. Th problem is that you can’t use a RELU for the last, output layer. You need a tan or a sigmoid function.  
This is the problem causing the NaN. We need to add a warning in TMVA for this.  
If you still have problems after changing this, please let me know

Best Regards

Lorenzo

---

<div class="post-metadata">

**Author:** ![a.bragagnolo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@a.bragagnolo](https://root-forum.cern.ch/u/a.bragagnolo)\
**Post date:** [November 6, 2017, 9:53am UTC](https://root-forum.cern.ch/t/dnn-train-test-error-nan-when-using-relu/26536/5 "2017-11-06T09:53:05Z")

</div>

Hi Lorenzo,  
I don’t think that is the problem since I never use anything but LINEAR for the last layer. For example my working layout is

“Layout=TANH|(N \* 3),TANH|(N \* 2),TANH|(N),TANH|(N),TANH|(N-10),LINEAR”

while the following configuration does not work does not work

“Layout=RELU|(N \* 3),RELU|(N \* 2),RELU|(N),RELU|(N),TANH|(N-10),LINEAR”

---

<div class="post-metadata">

**Author:** ![omazapa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/omazapa/32/12711_2.png) [@omazapa](https://root-forum.cern.ch/u/omazapa)\
**Post date:** [November 7, 2017, 8:27am UTC](https://root-forum.cern.ch/t/dnn-train-test-error-nan-when-using-relu/26536/6 "2017-11-07T08:27:17Z")

</div>

Hi

I try that configuration(both) and it works,  
which version of ROOT and which OS are using?  
Cheers,  
Omar.

---

<div class="post-metadata">

**Author:** ![a.bragagnolo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@a.bragagnolo](https://root-forum.cern.ch/u/a.bragagnolo)\
**Post date:** [November 7, 2017, 8:58am UTC](https://root-forum.cern.ch/t/dnn-train-test-error-nan-when-using-relu/26536/7 "2017-11-07T08:58:06Z")

</div>

Hi Omar,  
I’m using ROOT 6.10/08\* on Ubuntu 16.04 LTS

\*with this(\*\*) hotfix

(\*\*) [https://root-forum.cern.ch/t/trouble-compiling-root-with-cuda-support-for-tmva/25900/7](https://root-forum.cern.ch/t/trouble-compiling-root-with-cuda-support-for-tmva/25900/7)

I get this when I try to run the expample I gave you

 ![alberto@VN7-571G: ~-Desktop-Link to PhD-muonID-training-example_035](https://root-forum.cern.ch/uploads/default/original/2X/f/f9f6ff50a4b175db36aae0456db0a2ca84fe6005.png)
