How plot this diagram in colab? Why are some codes not applicable in the colab?

Hi everyone. I try to implement the codes of each lesson in Google Colab.
But there are some codes that do not run in Google Colab and give errors. For example, I have given their photos below.


Are these codes specially prepared for this course or can they be implemented in Google Colab in another way?

Also, my other question is, how can I plot the following diagram in Google Colab? I did not see a diagram similar to this one on Matplotlib website.

Hi @Mohammad_Fallah , have you copied other files public_tests.py and utils.py in the same folder in drive in which you are running your notebook?
If yes then, I think you need to install one more package, named ipympl. This is a thread which mentions about how to run notebooks on your local machine, I think this can help you in installing necessay package in google colab.

thanks a lot.
I downloaded the files according to the description. And I saved it in a folder on my computer. As you can see in the photo below.
1

One of the students said that you should paste the files in the path of your working folder.
And I also pasted these files in my folder in Google Drive.


But the error still exists.
Is it possible to guide me on what to do in the next step?

Hello!

I don’t see the error message from the screenshot in your first post of this topic. I assume the error was it couldn’t import libraries like lab_utils_common.

This could happen when your “current working directory” isn’t the directory that contains the library files. First please verify what your current working directory is by running this:

!pwd

And you can run the following to list all files under the current working directory

!ls

If you don’t see those library files, then you are not in the right directory, and you need to change the directory to the one that contains the library files by running

%cd path_to_the_correct_directory

Please replace path_to_the_correct_directory with the right path.

Cheers,
Raymond

1 Like

Thank you very much for the points you raised. I learned a few new things here.

Although I still did not succeed, but I am very happy for the new things you taught me. I hope I can solve the problem.

oh, can you share the error message? And share the result of running !pwd and !ls?

Hello my brother. I apologize for the delay in replying. The internet situation in my country is very bad.

In these few days, I tried different methods from YouTube and friends’ guidance. All of them were unsuccessful.

اBut specifically for the “C2_W1_Lab02_CoffeeRoasting_TF” lab, a very simple method was suggested that worked correctly and I have shown it in the photo below.

I just had to open a notebook file in the colab and then drag and drop these files into the colab as follows:


And the problem for this lesson was easily solved and the libraries were implemented. But I think there must be a better way. Because I had problems again in the next lessons and I still didn’t succeed in doing the next lessons in the colab.

What error message are you getting?
Did you make separate folders in Drive for uploading the downloaded files of different exercises? There may be files with same name in this different exercises, so you should made different folder for different exercises or optional labs.

Hello Brother.
The errors I encounter are usually about the absence of a specific library or module. Although I transfer all the files of each lesson to Google Drive, sometimes I encounter errors for some lessons.

I did not put the files in separate folders. I put everything in one space. From now on, I will try to create a separate folder for each lesson and check the result.

Just because the internet in my country disconnects and reconnects a lot and is weak and I am facing a challenge to be able to finish the courses and that is why I am replying late and I apologize for this.

Hello @Mohammad_Fallah,

Thank you for the description. Can you share a screenshot of the error message, and a screenshot of the result of running !pwd and !ls after you encounter the import errors?

Above are what I need to give you some suggestions.

Raymond

Hello Brother.
As an example, I went through this process for the “C2_W2_Relu”.

First, I downloaded the lab files. And then I moved them to a folder on my drive using drag and drop.


In the next step, I executed the codes you told me to see “in which working path I am” and “what are the contents of the folder” and then “change the working path” and “check the contents of the folder” again. You can see the details of the codes in the picture below:

And then I ran the following code:

And the error can be seen in the following image:

Hello @Mohammad_Fallah,

In the first photo, the 9th line is %matplotlib widget which is the same as the assignment file, however, in the second photo, the 9th line is get_python().run_line_magic('matplotlib', 'widget'). The second photo indicates that you were not running the code shown in the first photo.

  1. Please run the code shown in the first photo. The first photo has the correct code for C2_W2_ReLU

  2. If you cannot run through from autils import plt_act_trio, please comment it, and do not run plt_act_trio() in the next code cell. plt_act_trio() only shows you a linear, a sigmoid, and a ReLU function. You may watch the video for how they look, or just google their names.

  3. if you run _ = plt_relu_ex() and nothing is shown. Run the following 2 lines, and then try again.

from google.colab import output
output.enable_custom_widget_manager()
  1. if you still encounter a problem, again, please share a screenshot of the whole Error Traceback as you have done in the second photo.

Good luck,
Raymond

Thank you for answering so patiently.

A strange thing in the previous message is that line 9 is actually related to the execution of the code you saw in the first picture. I tried a few more times and there was no mistake. That error message is actually related to the execution of the code in the first image.

Hi, @Mohammad_Fallah

matplotlib widget backend requires the package ipympl to be installed, so make sure that it is installed.

if not this will install it for you

pip install ipympl

Cheers,
Moaz

I see. Interesting. I think then I was wrong saying you had run a different line of code in my previous reply. You are running it on Colab, right? I tried running the code on a colab notebook as well but I didn’t have the error that you saw. I suggest you to try @Moaz_Elesawey’s advice, and if you can pass the 9th line, then please follow my suggestion number 2 to 4 in my last reply.
Cheers,
Raymond

that was perfect. My problem is solved. I am happy now and the world is more beautiful.

I apologize for taking up so much of your time.
Thanks for all the tips you gave.
Problem solved and all is well.

Hi, @Mohammad_Fallah

Glad it works for you. Don’t hesitate to ask for any help.

Cheers,
Moaz

Great work @Mohammad_Fallah.