I want to run my project on google colab, as dnt have GPU facility. Uptill now I have uploaded the complete project file in my drive. What should be next, Plz give me a step wise process . My project has several parts (.py files) and dataset too.
Compress the project folder to a zip or RAR file
Start up google colab and select the add file icon by the left plane (the plane may be collapsed)
Upload the compressed file to the colab
Then install unrar package (Linux version) in colab using the terminal (always remember to add ‘!’ before a code to tell the colab terminal that it’s a terminal command)eg: ‘!apt-get install unrar’
Then after installing unpack the compressed file by the command ‘!unrar X rarfile’
And u r done
Well Thank for reply , here I am not able to find add file icon, This is the left plane. When I open colab there is a pop up window, having options like github>>>upload etc.
And actually I have done uploading in drive already. (Not rar but whole folder)
Can I upload this into colab now?
Click on the folder icon (the last icon by the left side)
If ur folder is already in ur drive then u can do as this link says:
Thanks again, Just done
and now in that extream left panel i can find all those python files and relevant dataset. after mounting the drive. Now I am confused do when I double click there, it is open in right panel. Now my question is do I need to copy this to jupyter cells here or is there any other way?
U mean copying the python code to jupyter cell?
If that’s what u mean then no you don’t need to copy the python code to the cell
If u want to run code, what u need to do is to run on the terminal with python.
If u are familiar with Linux terminal or cmd, all u need to to is to navigate to the dir where the code is like this
!cd dir then u run the command
Don’t forget to add the ‘!’ b4 a terminal command else the command will attempt to run as a python code which will throw an error.
If u want to edit your code, then all u need to do is click on the python file on the left panel and a text editing plane will open on the right where u can edit the code.
Hope this helps you
I am sorry I may sound like a fool here, but I wanted to know how to run this project on co lab, as the issue on my local machine is GPU acceleration problem.
Or are you saying after this uploading on colab the compilation done through command line?
I am still confused
Sorry for the late reply
I don’t know about you but when I program, I like to run my code on the terminal of the operating system I’m using windows or Linux and not on the IDE (this is just my preference)
So it’s kinda similar to colab.
Colab uses Linux as it’s operating system and the a python version is installed in it by default with some Machine learning modules and others.
Normally in any operating system u are using, if u want to run a code from the terminal all u simply need to do is open the terminal and type the command
cd 'code dir' to navigate to the code directory and then
python code.py to run it. This is no different with colab.
Once u upload ur code on colab whether from Google drive or from local directory, it is stored in the current working directory EG;
Assuming u uploaded a folder named ‘project’ and this folder has ur code named ‘project_class.py’, all u need to do is to type
!cd project to navigate into ‘project’ folder and then u type
!python project_class.py to run the code on colab.
If u want to edit the code, simple go to the left panel and click on particular file u wish to edit and a text editor will appear on the right side.
Hope this helps
So to answer ur questions, yes the code execution is done via the command terminal and u don’t need to do anything special or navigate to some unknown place to open a terminal.
All u simplly need to do is to type the command on a cell like how u’ll type a python code in a cell but when u r typing a terminal command u need to add ‘!’ before the command. This will make the terminal differentiate terminal command from python code.
I really find it very straight forward and clear so accepted it as answer for other readers. But still for me its not working.
I am doing exactly same but it says NO such file or directory as you can see its there in drive.
Thank you for helping
!dir and run the command
If u see all the files and directories of ‘CNN_as_MATLAB’ folder listed as the list of directories on the terminal, then that directory is ur working directory.
So so if u are already in that working directory, u don’t need to run the
!cd..... command anymore. All u need to do is to just run the python code:
Cant thank you enough,
Just one more question how to set device here in colab
The same way u always do.
Tho it’s preferable that u use the cpu environment on colab rather than the gpu environment except u are using colab pro (which is a paid version)
The gpu environment in colab can be really unstable sometimes, but u can always try it out.
Actually my question is what should I take as device
device = ‘torch.cuda.device’
model = model.to(device)
its not working
To switch processor environments all u need to do is go to the top bar and select ‘runtime’, then select ‘change runtime type’ and u’ll see the one u are currently using (‘none’) and u can switch by selecting GPU or TPU on the drop down.
Remember that when u change runtime u need to upload your project folder again coz it’s like switching to a different computer
If u want to use the TPU tho u have to install ‘torch.xlsa’ package. U can just search for ‘how to use run pytorch on TPU’.
The code for specifying running device should be still be kept
I am trying to install torch_xla as
!pip install torch_xla
But the error is
ERROR: Could not find a version that satisfies the requirement torch_xla (from versions: none)
ERROR: No matching distribution found for torch_xla
LOL it’s really funny coz I experienced ur problems too and in the exact order as urs .
Don’t mind me🙂
Anyways just look at this site for details on that:
Amazing discussion going on.
Just to mention that its advisable to use
%run script.py on colab instaed of
!python script.py. see this.
Ok thanks alot🙃
We learn everyday don’t we?