This article was published as part of the Data Science Blogathon
Introduction
, O “al” To abreviate, are Google-hosted Jupyter Notebooks that allow you to write and run Python code through your browser. It is easy to use a Colab and it is linked to your Google account. Colab provides free access to GPU and TPU, no setup required and easy to share your code with the community.
Colab has a fascinating history. It is an internal tool for data analysis in Google. But nevertheless, later it was publicly released and, since then, many people have been using this tool to accomplish their machine learning tasks. Most students and users without a GPU use colab as a free resource to run their data science experiments.
This article collects some useful tips and tricks that I use to facilitate my work at Colab. I have tried to list most of the sources where I read them first. These tips will help you get the most out of your Colab notebooks.
Using local runtimes
Normally, Colab offers you free GPU resources. But nevertheless, if you already have your GPUs and want to use the Colab UI, there is a solution. Users can use the Colab UI with a local runtime as follows:
You can use this method to run code on your local hardware and access your local file system without leaving the Colab notebook.. The following documentation delves into how it works. watch this document for more details.
Notepad
If you are creating multiple notebooks with names like “untitled.ipynb” Y “untitled1.ipynb”, etc. I think some of us could sail in the same boat in this regard.. So he Notebook with cloud notepad it could be for you if that's the case.
The cloud notebook is a specific notebook available at the URL: https://colab.research.google.com/notebooks/empty.ipynb it is not automatically saved to your disk account. It is useful for experimentation or non-trivial work and does not take up space in Google Drive.
Receive notifications about completed cell executions
Users receive notifications after execution completes, even if they switch to another tab, window or app. Users can enable it through Tools> Setting> Site> Show desktop notifications (and allow browser notifications once prompted) to verify it.
This is how the notification appears even if it is in another tab.
Here is a notification demo that appears even if you navigate to another tab.
Author's Image
GitHub Jupyter notebooks open directly in Colab
Colab notebooks were developed in such a way that they can be easily integrated with Github. It means you can upload and save Colab notebooks to GitHub directly. We have an easy way to do it, thanks to Seungjae Ryan Lee.
When in a notebook on Github that you want to see in Colab, replace github with githubtocolab in url, leaving everything else unchanged.
Author's Image
Kaggle datasets in Google Colab
At the time of low budget and had consumed its share of GPU in Kaggle, this trick could be a break for you. Any dataset can be downloaded seamlessly from Kaggle to your Colab workspace. This is what you should do:
After clicking on the 'Create new API token' tab, a kaggle.json file is generated consisting of your API token. Create a folder Kaggle on your Google Drive and store the kaggle.json file in it
Mount the unit in a colab laptop
Change the configuration path to 'Kaggle.json’ and change current working directory
import os os.environ['KAGGLE_CONFIG_DIR'] = "/content/drive/My Drive/Kaggle"
%cd /content/drive/MyDrive/Kaggle
Copy dataset API to download
The API is present in the ‘Data tab’ for data sets linked to competitions.
Author's Image
Finally, run any of the following commands to download the dataset
!kaggle datasets download -d alexanderbader/forbes-billionaires-2021-30
!kaggle competitions download -c google-smartphone-decimeter-challenge
Author's Image
Find your laptops in the unit
If you want to find a specific Colab laptop in the unit? Go to the drive search box and add:
application/vnd.google.colaboratory
It will list all your notebooks on your Google Drive. What's more, you can also specify the title and ownership of the notebook. For instance, if I need to find a notebook created a long time ago, What does' Transfer have?’ in your title, the following helps to get it:
Data table extension
Colab includes a extension to load pandas data frames into interactive displays that can be classified, filter and browse dynamically. Write the following code in the notebook cell to enable data table display for Pandas data frames.
%load_ext google.colab.data_table #To diable the display %unload_ext google.colab.data_table
Here is a quick demo:
Author's Image
Notebook comparison
When using Colab, it's easy to compare two laptops. Use Ver> Differentiate notebooks in the Colab menu or navigate to https://colab.research.google.com/diff and in the input box, paste the urls of the notebooks to see the difference.
Prevent Colab from disconnecting
Disconnected due to inactivity:
This is a significant disadvantage of Google Colab and I am sure many of you have experienced it at least once.. Decide to take a break, but when he comes back, Your laptop is disconnected!
In fact, if we leave the laptop idle for more than 30 minutes, Google Colab automatically disconnects you.
Open Chrome DevTools by pressing F12 on Windows or ctrl + shift + in a Linux, and then write the following javascript code in your console:
function KeepClicking(){ console.log("Clicking"); document.querySelector("colab-connect-button").click() } setInterval(KeepClicking,60000)
Every 60 seconds, this function clicks the connect button. As a result, Colab believes that the laptop is not idle and that you should not worry about disconnecting.
Disconnection while a task is running:
To start, note that when connecting to a GPU, You can only use the machine in the cloud for a maximum of 12 hours at a time.
You may be disconnected at some point during these 12 hours. “Collaboratory is designed for interactive use”, according to Colab's frequently asked questions. Background calculations that have been running for a long time, especially on GPUs, can be finalized.
Usa Tensorboard con Colab
TensorBoard is a tool for displaying metrics and visualizations throughout a deep learning workflow. Can be used immediately within Colab.
Please charge the TensorBoard laptop extension first:
%load_ext tensorboard
Once your model is complete, start TensorBoard inside the laptop by typing:
%tensorboard --logdir logs
Conclution
These were some tricks that I found very useful, especially when it comes to training ML models on GPU. Although Colab notebooks can only function for a maximum of 12 hours, with previously shared cheats, you should be able to get the most out of your session.
I hope you found this article useful and have a wonderful day., Thank you.
The media shown in this article is not the property of DataPeaker and is used at the author's discretion.