when should i use "sigmoid" and "relu" function in CNN?

Viewed 1868

To implement the CNN model for classification images we need to use sigmoid and relu function. but I am confused what is the use of these.

1 Answers

If you are working with a conventional CNN for image classification, the output layer has N neurons, where N is the number of image classes you want to identify. You want each output neuron to represent the probability that you have observed each image class. The sigmoid function is good for representing a probability. Its domain is all real numbers, but its range is 0 to 1.

For network layers that are not output layers, you could also use the sigmoid. In theory, any non-linear transfer function will work in the inner layers of a neural network. However, there are practical reasons not to use the sigmoid. Some of those reasons are:

  1. Sigmoid requires a fair amount of computation.

  2. The slope of the sigmoid function is very shallow when the input is far from zero, which slows gradient descent learning down.

  3. Modern neural networks have many layers, and if you have several layers in a neural network with sigmoid functions between them, it's quite possible to end up with a zero learning rate.

The ReLU function solves many of sigmoid's problems. It is easy and fast to compute. Whenever the input is positive, ReLU has a slope of -1, which provides a strong gradient to descend. ReLU is not limited to the range 0-1, though, so if you used it it your output layer, it would not be guaranteed to be able to represent a probability.

Related