Deep learning without expensive hardware using Google Colab and connecting it with GitHub
When it comes to Deep Learning, the first thing that comes to our mind is an expensive GPU. But affording an expensive machine while we are just learning is not feasible for almost all of us. Deep learning does require a good amount of computational power in order to create even basic classification models. We can take the path of getting a decent gaming laptop with a fair GPU to learn and build our models, but even after purchasing a GPU setting up our environment for any Deep Learning task is a hassle. Although it is not rocket science, it is really time-consuming and requires a lot of hits and try methodologies if the dependencies are not well documented. This time is extremely precious and we cannot be wasting it setting our machine with all the individual dependencies just in order to build one simple solution. So what can be done in order to get decent machines locally and train all our models without the hassle of arranging these bits and pieces of dependencies?
Kaggle and Colab provide us with above-average hardware that we can use for training our models for a limited time. The only downside to these is the restrictive access to only Jupyter Notebooks or maybe one single script. But the problem arises when we are building a complete solution or some API. So recently I came across a GitHub repo that could help us solve this issue and provide us with an entire IDE built over these platforms. This project is called Colabcode and this could help us solve a number of issues. So let’s have a look at how we can achieve this:
Installing and Running ColabCode
Installing the software is fairly easy using pip. pip install colabcode. If you are still looking for installing the latest version of the code, you can do so directly from the GitHub repo using the following piece of code: pip install git+https://github.com/abhishekkrthakur/colabcode.git.
Once you have installed the Colabcode, you can easily call it in a single line and run as shown in figure 1.0.
In the ColabCode class, the port argument signifies the port of the machine used for serving the backend. Please note that certain port numbers are reserved for machine usage such as port 80 or 8080, so please make sure that you do not use some conflicting port number else they will result in the unpredictive behavior of the vs code server.
Once you run the cell, it will return a server access code in the form of https://<random-token>.ngrok.io which could be used to get a full-fledged text server which could be used as an IDE as shown in figure 2.3.
Attaching Google Drive
Now if you have been following Google colab for some time, you might be knowing that we have the flexibility of attaching our google drive at the backend in order to reuse the generated files. Attaching Colabcode to drive is also exactly similar. All we have to do is pass the mount_drive parameter as True and then you’ll just require to authorize Colabcode.
Once the authorization is completed and the backend has been connected, it will generate the ngrok URL again as shown above in figure 2.2. You can use the generated link to use the fully-fledged vs code server.
Connecting vs code to GitHub
Now that we have set up all the basics of training our code, what we can do is simply use the vs code’s inbuilt functionality to connect. The connection is fairly straight-forward, but if you are fluent in using Github from the terminal, then I would suggest you use the built-in functionality rather than using the terminal. Although the terminal is a much viable option, it will get frustrating soon enough as you might face a bit delay in the response from the terminal. If you still want to use the terminal, you can call the terminal using the ctrl+` button from your keyboard. The ` is the little key below the escape key on the keyboard. It is a little slow to connect but please have patience till you get the mini terminal there. This seems like an annoying issue, but looking at the end product we are getting, it could easily be looked over. I have prepared a little step-by-step gif (Illustrated in figure 3.0) to guide you through most of the process. But if you are still facing any issue, do consider commenting and sharing your problem in the comment section.
Start using the vs code today over your usual Jupyter notebooks and then thank me later for faster workflows 😉. You can check this colab notebook for the code.