Not Getting Same Results in Colab

I am trying to transfer all my codes and its libraries form Deep Learning Specialization courses into my Google Drive so I can later open them and work with them in Colab.
I did this transfer for all 3 assignments of Week 1 of Course 2 and got the same results in Colab but when I try to run the Week 2 of Course 2 assignment: Optimization Methods on my Colab I get different results.
Here is what I do:
I download all the code files, images folder, datasets folder, .py files and upload them into my drive in the exact form they have on Coursera’s Jupyter Notebook files.
In Colab I get no errors in any of the cells and all the codes run, all the tests get passed too.
But when It comes to plotting the cost functions I see different numbers. For example at step 6.1. of the assignment which is related to Mini-Batch Gradient Descent I see these to different results on the exact same code, the only difference is the environments of Coursera’s Jupyter Notebook and Google Colab:

This is the result I got in Colab:

This is the result I got in Coursera’s Jupyter Notebook:

At first I thought this problem is due to the different versions of matplotlib in Colab and Coursera’s Jupyter Notebook but after installing the same version of matplotlib used for Coursera’s Jupyter Notebook on Colab I still had this different cost values problem.

My second guess is setting the seed=10 in model function. Can this be the reason of getting those two different results? does seed=10 generate different results in Coursera’s Jupyter Notebook than Colab?

The results depend on lots more packages than just matplotlib, right? The course notebooks are typically using packages that are pretty out-of-date. Your best bet is to use Anaconda to duplicate the environment. I don’t know Colab, so I don’t know if that is supported or not. Here’s a thread that gives some guidance about how to set up a duplicate environment.

Thank you paulinpaloalto
Colab is Google online environment for Python and it’s pretty awsome.
It seems that I have been trying to compare two different codes on two different platforms which was my fault and resulting this confusion. I double checked my codes in both environments and noticed the codes were different. Now I fixed the problem and got my codes the same so I’m getting the same results and the problem is solved. Code is working the same both in Colab and Coursera’s Jypyter Notebook. However, despite my code passing all the tests and getting 100/100 after assignment I have doubt about my cost values.
I add an image of my cost values and costs plot for ‘In [30]’ cell which is the last training in the assignment and corresponding to ’ 7.3.3 - Adam with Learning Rate Decay’
Can you please confirm that your own plot of costs and cost values are similar to mine?

I think my results match yours exactly. Here are my results from that section when running on the course website:

Cost after epoch 0: 0.699346
learning rate after epoch 0: 0.010000
Cost after epoch 1000: 0.130074
learning rate after epoch 1000: 0.005000
Cost after epoch 2000: 0.129826
learning rate after epoch 2000: 0.003333
Cost after epoch 3000: 0.129282
learning rate after epoch 3000: 0.002500
Cost after epoch 4000: 0.128361
learning rate after epoch 4000: 0.002000

1 Like