0
$\begingroup$

I have developed a basic feedforward neural network from scratch to classify whether image is of cat or not cat. It works fine, but after 2500 iterations, my cost function is not reducing properly.

The loss function which I am using is

$L(\hat{y},y) = -ylog\hat{y}-(1-y)log(1-\hat{y})$

Can you please point out where I am going wrong the link to the notebook is https://www.kaggle.com/sidcodegladiator/catnoncat-nn?

$\endgroup$
3
  • $\begingroup$ It might be the vanishing gradient problem. $\endgroup$
    – efedoganay
    Jul 11, 2020 at 17:45
  • 1
    $\begingroup$ This isn't a cnn, it's a basic MLP and that it performs poorly isn't surprising. $\endgroup$ Dec 16, 2020 at 6:49
  • $\begingroup$ what optimizer are you using? I'd suggest you to try Adam $\endgroup$
    – SpiderRico
    Apr 11, 2022 at 6:31

2 Answers 2

0
$\begingroup$

You may try to adjust the learning rate first. As the learning rate has a great effect on changing the weights and the bias value.

See if the results has changed after adjusting the learning rate.

$\endgroup$
3
  • $\begingroup$ I tried that as well, What do you suggest my learning rate should be? $\endgroup$
    – Siddarth
    Jul 16, 2020 at 8:13
  • $\begingroup$ You can try to set the learning rate to 0.01 or 0.1 to see if the results of outcome is better or not $\endgroup$
    – Oscar916
    Jul 16, 2020 at 8:18
  • $\begingroup$ I tried 0.01, 0.1 and even 1 what I have noticed is the rate at which the cost function is decreasing is good but the problem is it still getting plateaued at 0.64 after 2500 epochs $\endgroup$
    – Siddarth
    Jul 16, 2020 at 8:49
0
$\begingroup$

Since after a number of iterations the cost function is not reducing, this may be able to be diagnosed as a vanishing gradient problem. A solution to this is the use of a Residual neural network.

Another solution is that you carefully initialise your weights as throughout your neural network your gradient may exponentially explode or exponentially vanish.

Watch this video on how to initialise weights truly randomly: https://www.youtube.com/watch?v=s2coXdufOzE

Edit:

Another possible cause for your issue is that your algorithm is having an high bias problem. This is due to your algorithm not performing well on the training set. In your case one of the best solutions would be to make your network deeper and so it shall be able to conduct more complex functions and so perform better on your training set.

$\endgroup$
5
  • $\begingroup$ Thanks for the tip after doing that I have initialized my weights like this parameters['W'+str(l)]=np.random.randn(layers_dims_vector[l],layers_dims_vector[l-1])*np.sqrt(2/layers_dims_vector[l-1]) but still my cost does not seem to get reduced, Can you point me if there is something else I can do? Or do you see any error in the algorithm? $\endgroup$
    – Siddarth
    Jul 18, 2020 at 15:16
  • $\begingroup$ @Siddarth I have made an edit which should help in case that this is not a vanishing gradient issue, as seen from the random initialisation barely having an effect on the performance of your algorithm. $\endgroup$
    – jr235
    Jul 19, 2020 at 4:59
  • $\begingroup$ Hi I tried with this configuration [12288,7000,4000,2000,10000,500,200,150,100,50,25,12,1] first is no of inputs and last is the output layer remaining are hidden layers. The network has become slow but still use, Can you check my code and let me know what I am missing? $\endgroup$
    – Siddarth
    Jul 21, 2020 at 11:43
  • $\begingroup$ In order to reduce the time your algorithm spends training you should use another optimisation algorithm (e.g Adam optimisation algorithm, Gradient Descent with momentum, Root Mean Square Propagation etc...). In order to make my diagnostic more accurate split your data set into a training (70%) and development set (30% depending on how large your data set is, the larger the smaller the dev set size), and plot the costs over time on both sets. $\endgroup$
    – jr235
    Jul 22, 2020 at 7:30
  • $\begingroup$ Hi I have observed inspite of increasing the height and depth of network, The cost is getting plateaued. Is the cost function getting stuck in local minima? If thats the case do you see any issue with the algorithm? $\endgroup$
    – Siddarth
    Jul 23, 2020 at 15:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .