<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Google Colab - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Google Colab - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sat, 23 May 2026 22:20:56 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/google-colab/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Download a Kaggle Dataset Directly to a Google Colab Notebook ]]>
                </title>
                <description>
                    <![CDATA[ Kaggle is a popular data science-based competition platform that has a large online community of data scientists and machine learning engineers. The platform contains a ton of datasets and notebooks that you can use to learn and practice your data sc... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-download-kaggle-dataset-to-google-colab/</link>
                <guid isPermaLink="false">66b902cb941d2f900bad52a6</guid>
                
                    <category>
                        <![CDATA[ Data Science ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Colab ]]>
                    </category>
                
                    <category>
                        <![CDATA[ kaggle ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Machine Learning ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Md. Fahim Bin Amin ]]>
                </dc:creator>
                <pubDate>Thu, 08 Feb 2024 19:39:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/02/Kaggle-to-Colab.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p><a target="_blank" href="https://www.kaggle.com/">Kaggle</a> is a popular data science-based competition platform that has a large online community of data scientists and machine learning engineers.</p>
<p>The platform contains a ton of datasets and notebooks that you can use to learn and practice your data science and machine learning skills. They even have competitions you can participate in.</p>
<p>Kaggle offers a 100% free platform for all users – but there are some restrictions depending on the resources you're using. </p>
<p>For example, you can use their CPU system for an unlimited amount of time. But there are strict limitations on GPU and TPU usage. You can use their GPU for 30 hours and TPU for 20 hours in a week. It gets resets each week, and then you get a fresh 30 hours GPU usage and 20 hours TPU usage at the start of the new week.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_14-21.png" alt="Image" width="600" height="400" loading="lazy">
<em>Kaggle Website</em></p>
<p>Alongside Kaggle, there are another popular platforms for machine learning engineers and data scientists – like <a target="_blank" href="https://colab.google/">Google Colaboratory</a>, or Google Colab for short.</p>
<p>In Google Colab, you can also use their CPU and GPU, but the free versions have more limitations than the free Kaggle account. In Google Colab, you can not get any GPU computational power until they allocate it from their free units. You don't know how many hours you can use, and you don't even know if you have any chance to get units over the next few days. </p>
<p>In order to get all the features, you need to subscribe to their pro plans which are quite expensive.</p>
<p>But sometimes you still may want to use Colab, in most cases for short tasks. In Colab, you can directly connect your Google Drive and use your datasets from there. You can also store your output from the notebook to Google Drive if you want.</p>
<p>When you're working on a project, though, sometimes you'll want to use datasets from Kaggle in Google Colab. So you'll need to download the dataset from Kaggle and upload that to Colab's temporary storage or your Google Drive. </p>
<p>You can probably guess that this is a very time-consuming process. </p>
<p>But there is a way that you can directly download a Kaggle dataset using an API call in the Google Colab's notebook! In this article, I am going to show you how you can do that.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<p>I've broken this tutorial down into separate parts for better understanding. You can get a clear overview of the entire article here:</p>
<ul>
<li><a class="post-section-overview" href="#heading-types-of-kaggle-datasets">Types of Kaggle datasets</a></li>
<li><a class="post-section-overview" href="#heading-prerequisites">Prerequisites</a></li>
<li><a class="post-section-overview" href="#setup-google-colab-for-using-kaggle-api">Setup Google Colab for using Kaggle API</a></li>
<li><a class="post-section-overview" href="#install-kaggle-library">Install Kaggle library</a></li>
<li><a class="post-section-overview" href="#heading-mount-google-drive-to-colab">Mount Google Drive to Colab</a></li>
<li><a class="post-section-overview" href="#add-the-kaggle-api-token-to-colab-notebook">Add the Kaggle API Token to Colab Notebook</a></li>
<li><a class="post-section-overview" href="#download-kaggle-dataset">Download Kaggle dataset</a></li>
<li><a class="post-section-overview" href="#download-kaggle-competition-dataset">Download Kaggle Competition dataset</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/p/906afd5c-ae59-4f19-9fe3-662d110d63a7/download-specifc-file-from-kaggle-competition-dataset">Download Specifc file from Kaggle Competition dataset</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ul>
<h2 id="heading-video">Video</h2>
<p>If you would like to watch all of the steps from a video, you're in luck – I made this video just for you:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/7Z0s-XDXR1E" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-types-of-kaggle-datasets">Types of Kaggle Datasets</h2>
<p>Normally Kaggle provides two types of datasets: typical datasets that anyone can upload, and competition datasets. In the competition datasets, the competition organizers typically add/upload the datasets. </p>
<p>Even though you can download a Kaggle dataset easily, you can't download a competition dataset if you don't participate in that competition. But some competitions remain open, and you can access their datasets via "Late Submission". So just make sure to check.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>To go through this tutorial and get the most ouf of it, you'll need a Kaggle account, and that is completely free. Simply head over to the official website of <a target="_blank" href="https://www.kaggle.com/">Kaggle</a>, and create an account if you don't have one already.</p>
<p>You'll also need Kaggle's API. Head over to the <a target="_blank" href="https://www.kaggle.com/settings">settings</a> of your Kaggle account. Go to the API section, and click "Create New Token". Keep in mind that Kaggle does not allow you to keep multiple tokens. You can use only one active token for your Kaggle account.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_14-52.png" alt="Image" width="600" height="400" loading="lazy">
<em>Kaggle API Token</em></p>
<p>This will give you a <code>kaggle.json</code> file. Keep it safe, as you'll need to use it later.</p>
<p>You also need a Google account if you want to use Google Colab. You may already have one, but if you don't, go ahead and create a new account in Google.</p>
<p>Now, you can store your Kaggle JSON in your Google drive. I prefer to create a new folder and keep my JSON file there so that I can call that in Colab whenever I want.</p>
<h2 id="heading-how-to-setup-google-colab-to-use-the-kaggle-api">How to Setup Google Colab to Use the Kaggle API</h2>
<p>You can simply open any Colab notebook where you want to use the Kaggle API to download the dataset.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_15-45.png" alt="Image" width="600" height="400" loading="lazy">
<em>Google Colab</em></p>
<h3 id="heading-install-the-kaggle-library">Install the Kaggle library</h3>
<p>You need to install the Kaggle Python library before you start working with Kaggle. You can simply install it in the colab notebook using the command <code>! pip install kaggle</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_15-46.png" alt="Image" width="600" height="400" loading="lazy">
<em>Install Kaggle library in colab</em></p>
<h3 id="heading-mount-google-drive-to-colab">Mount Google Drive to Colab</h3>
<p>Now you need to mount your Google Drive to the Colab notebook, since you've uploaded your <code>kaggle.json</code> file inside your Google drive.</p>
<p>You can simply do that by using the two lines of code given below:</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> google.colab <span class="hljs-keyword">import</span> drive
drive.mount(<span class="hljs-string">'/content/drive'</span>)
</code></pre>
<p>Make sure to give it permission to access your Google Drive:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_15-48.png" alt="Image" width="600" height="400" loading="lazy">
<em>Give access to Google Drive</em></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_15-49.png" alt="Image" width="600" height="400" loading="lazy">
<em>Mount Google Drive</em></p>
<p>If you refresh the mounted folder icon, you will see your Google Drive and all of the content in the notebook.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_15-49_1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Find MyDrive in Notebook</em></p>
<h3 id="heading-add-the-kaggle-api-token-to-the-colab-notebook">Add the Kaggle API Token to the Colab Notebook</h3>
<p>Now you need to add the Kaggle API token to the notebook. But before that, you can simply create a temporary directory for Kaggle at the temporary instance location on the Colab drive by using the command <code>! mkdir ~/.kaggle</code>.</p>
<p>Now you need to copy your uploaded JSON file to that temporary Kaggle directory. You need the URL where you uploaded your JSON file earlier. You can grab that link directly from the drive folder in the notebook.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/Screenshot-2024-02-08-155504.png" alt="Image" width="600" height="400" loading="lazy">
<em>Copy JSON file location</em></p>
<p>You can get the path directly like this. </p>
<p>Then you can use the copy command like below:</p>
<pre><code class="lang-bash">! cp kaggle_json_path ~/.kaggle/
</code></pre>
<p>For example, my JSON file is located at "/content/drive/MyDrive/Kaggle_API/kaggle.json", so my command would be:</p>
<pre><code class="lang-bash">! cp /content/drive/MyDrive/Kaggle_API/kaggle.json ~/.kaggle/
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_15-58_1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Copy JSON file</em></p>
<p>Now you need to change the file permissions to read/write to the owner only for safety.</p>
<p>You can use the command below to achive that:</p>
<pre><code class="lang-bash">! chmod 600 ~/.kaggle/kaggle.json
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_15-59.png" alt="Image" width="600" height="400" loading="lazy">
<em>Change file permission of kaggle.json file</em></p>
<h2 id="heading-how-to-download-the-kaggle-dataset">How to Download the Kaggle Dataset</h2>
<p>For downloading a typical Kaggle dataset, you have to find the dataset on Kaggle first.</p>
<p>Let's say I want to download the following dataset from Kaggle:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_16-01.png" alt="Image" width="600" height="400" loading="lazy">
<em>Sample dataset</em></p>
<p>Check the complete URL of the dataset, which in this case is:</p>
<p><a target="_blank" href="https://www.kaggle.com/datasets/mdfahimbinamin/fastsurfer-processed-3d-brain-mri-from-adni">https://www.kaggle.com/datasets/mdfahimbinamin/fastsurfer-processed-3d-brain-mri-from-adni</a></p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.kaggle.com/datasets/mdfahimbinamin/fastsurfer-processed-3d-brain-mri-from-adni">https://www.kaggle.com/datasets/mdfahimbinamin/fastsurfer-processed-3d-brain-mri-from-adni</a></div>
<p>We need the "account_name_of_the_dataset_owner/dataset_path" string. From the URL, the account name of the dataset owner is mdfahimbinamin. The dataset path is fastsurfer-processed-3d-brain-mri-from-adni.</p>
<p>So to download this exact dataset from Kaggle to your Google colab, your command would be:</p>
<pre><code class="lang-bash">! kaggle datasets download mdfahimbinamin/fastsurfer-processed-3d-brain-mri-from-adni
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_16-06.png" alt="Image" width="600" height="400" loading="lazy">
<em>Downloading the Kaggle dataset to your Colab notebook</em></p>
<p>The entire process happens on Google's Cloud PC. So the downloading speed should be quite fast.</p>
<p>By default, the datasets come as <code>.zip</code> file. So if you need to unzip that, you can simply use the command below:</p>
<pre><code class="lang-bash">! unzip dataset-path.zip
</code></pre>
<p>For example, my dataset name/path was "fastsurfer-processed-3d-brain-mri-from-adni". So I will use the following command:</p>
<pre><code class="lang-bash">! unzip fastsurfer-processed-3d-brain-mri-from-adni.zip
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_16-09.png" alt="Image" width="600" height="400" loading="lazy">
<em>Unzip Kaggle Dataset</em></p>
<p>That's it! 😊</p>
<h2 id="heading-how-to-download-a-kaggle-competition-dataset">How to Download a Kaggle Competition Dataset</h2>
<p>Before downloading a Competition dataset, you need to make sure that either you have joined that competition or that you've selected "Late Submission" using the same Kaggle account that you're using for Kaggle API token.</p>
<p>Suppose I'm joining the ConnectX competition on Kaggle.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_16-15.png" alt="Image" width="600" height="400" loading="lazy">
<em>Connect X competition</em></p>
<p>I need to click "Join Competition" to get access to their dataset.</p>
<p>But if I want to download a dataset from a past competition, I need to join their "Late Submission" to gain their dataset.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_16-16.png" alt="Image" width="600" height="400" loading="lazy">
<em>Join a past competition</em></p>
<p>After clicking on "Late Submission", I need to grab the URL. This time, I'm using the Binary Classification with a Bank Churn Dataset. The complete URL is: <a target="_blank" href="https://www.kaggle.com/competitions/playground-series-s4e1/overview">https://www.kaggle.com/competitions/playground-series-s4e1/overview</a></p>
<p>From the URL, I can see that the dataset is located at "playground-series-s4e1". So I will use the following command to download the dataset to my Google Colab notebook:</p>
<pre><code class="lang-bash">! kaggle competitions download playground-series-s4e1
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_16-19.png" alt="Image" width="600" height="400" loading="lazy">
<em>Download dataset</em></p>
<p>That's it! 😊</p>
<h2 id="heading-how-to-download-a-specific-file-from-a-kaggle-competition-dataset">How to Download a Specific File from a Kaggle Competition Dataset</h2>
<p>Let's say, I want to download a specific file from a Kaggle competition dataset. I can also do that.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_16-21.png" alt="Image" width="600" height="400" loading="lazy">
<em>dataset</em></p>
<p>In the dataset used above, you can see that there are 3 files. Let's say I want to download the <code>test.csv</code> file only. </p>
<p>To do this, the command would be strucutred like this: <code>! kaggle competitions download dataset-path -f file_name_with_extension</code>.</p>
<p>So my command would be:</p>
<pre><code class="lang-bash">! kaggle competitions download playground-series-s4e1 -f test.csv
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/2024-02-08_16-23.png" alt="Image" width="600" height="400" loading="lazy">
<em>Download specific file</em></p>
<p>That's it! 😊</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>I hope you have gained some valuable insights from the article.</p>
<p>If you have enjoyed the procedures step-by-step, then don't forget to let me know on <a target="_blank" href="https://twitter.com/Fahim_FBA">Twitter/X</a> or <a target="_blank" href="https://www.linkedin.com/in/fahimfba/">LinkedIn</a>.</p>
<p>You can follow me on <a target="_blank" href="https://github.com/FahimFBA">GitHub</a> as well if you are interested in open source. Make sure to check <a target="_blank" href="https://fahimbinamin.com/">my website</a> (<a target="_blank" href="https://fahimbinamin.com/">https://fahimbinamin.com/</a>) as well!</p>
<p>If you like to watch programming and technology-related videos, then you can check my <a target="_blank" href="https://www.youtube.com/@FahimAmin?sub_confirmation=1">YouTube channel</a>, too. You can also check my other writings on <a target="_blank" href="https://dev.to/fahimfba">Dev.to</a>.</p>
<p>All the best for your programming and development journey. 😊</p>
<p>You can do it! Don't give up, never! ❤️</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Google Colaboratory – How to Run Python Code in Your Google Drive ]]>
                </title>
                <description>
                    <![CDATA[ The Google Colaboratory (“Colab”) is a notebook (like a Jupyter Notebook) where you can run Python code in your Google Drive.  You can write text, write code, run that code, and see the output – all in line in the same notebook.  Benefits of Google C... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/google-colaboratory-python-code-in-your-google-drive/</link>
                <guid isPermaLink="false">66b0c4fbfcd8d9e59447bec3</guid>
                
                    <category>
                        <![CDATA[ Google Colab ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Edward Pratowski ]]>
                </dc:creator>
                <pubDate>Thu, 21 Apr 2022 19:56:02 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/04/pexels-sevenstorm-juhaszimrus-425133.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>The Google Colaboratory (“Colab”) is a notebook (like a Jupyter Notebook) where you can run Python code in your Google Drive. </p>
<p>You can write text, write code, run that code, and see the output – all in line in the same notebook. </p>
<h2 id="heading-benefits-of-google-colab">Benefits of Google Colab</h2>
<p>Sharing notebooks is as easy as sharing any Google document. You can also get the app and run the code from your phone.</p>
<p>You can use the powerful and popular Python language in your Google Drive, and the set-up will take less than five minutes. </p>
<p>Because Python runs on a server (and not in your local browser or on your local computer) you can easily use it to interact with an online database and analyze data in situations where you need to keep the code private. </p>
<h2 id="heading-how-to-add-colab-to-your-google-drive">How to Add Colab to Your Google Drive</h2>
<ol>
<li>On your computer, in your Google Drive, click the “+ new” button.</li>
</ol>
<p><img src="https://lh4.googleusercontent.com/us0e4vwVAXFLV1Zv_07RINIVP3uMish_sPWjumo8Y8LYBjbBqa5fq7Ioxw7KUmbIGGN18mbUcu16EhLpmWreOsqpHqnwyVt6bFvTKTg0B-FdclBXIumNAGSHm8MRQmuYKCMz7Q9_" alt="Image" width="129" height="74" loading="lazy"></p>
<ol start="2">
<li>Click “more”, then click “connect more apps” at the bottom of that new menu. </li>
</ol>
<p><img src="https://lh6.googleusercontent.com/kWfy4KkQcuTYxHO0CGiUVsf2PTFRrKEYQzQM1BffRAaarwnIlg3a_zgtD71_NqSzqGnvqRqfTPUi793vgPr6dzNJ6WmhHn9oPePJSaK9h1RNqR5KvwHg2UVj9sYIMBTvizjWtJ_V" alt="Image" width="583" height="601" loading="lazy"></p>
<ol start="3">
<li>In the Google Workspace Marketplace, type “colab” into the search box.</li>
</ol>
<p><img src="https://lh5.googleusercontent.com/dLHP0JPcfH2VIFFc_cuJeZZ7Kz5UVKGpVxAY_pQNJoGfuBw8Jg6KoLJ_UCETRmgbxmIE8A31VA3BN9KTwXD4hD6CAfHtTIKgNT-vUSVYLK8J_-I-G0YUgVklUB5zQjBKiozuloih" alt="Image" width="963" height="444" loading="lazy"></p>
<ol start="4">
<li>Click to add Google Colaboratory. </li>
</ol>
<p><img src="https://lh6.googleusercontent.com/BShlQ_Hnj829h2ZNUxCJTolVFTYb7EeBoV7TJyqH13pwiS6YZDX95bxVI0RC3Dqp5wl2Mo-B4r8ezHkWFOeRJxFGGuoY9eQYb2ANtEx0nPCxU9aaZQrqEJj_hbePrYTGheWjr0tM" alt="Image" width="965" height="412" loading="lazy"></p>
<ol start="5">
<li>Now you have Colab in your list of available apps.  </li>
</ol>
<p><img src="https://lh3.googleusercontent.com/Xxwg1qNNyJQDcxrLlmOILOIGhfVQS1jQpTqjbOym7MqhCoVSdRVu_5EdVfrzgiRp70F01k0AUKZo0AQlmGrO3IgGJD-Dpx77jFhWfLXTW0m3ZfYXz5AMoK9m9BhSG-VhK9D-uX_I" alt="Image" width="507" height="341" loading="lazy"></p>
<h2 id="heading-ia"> </h2>
<p>How to Use Google Colab</p>
<p>Now when you click the “+new” button and click “more” (at the bottom of that first list) you will see “Google Colaboratory” on the next list. </p>
<p>Click that to open a new Colab notebook. Give your notebook a name, like you would with any Google document or spreadsheet. This notebook is in dark mode:</p>
<p><img src="https://lh3.googleusercontent.com/ttxQIV3tGb3kaiMlu-ix-J0939nbXX7Xx_Ke5UMcBnT_mRNVcNfJevAbMWm8nhIYbCM6zNjSMY_d3CwqIi-euqnf8HSAZlLG5oZST84kDnw9JpxKnLNkj-SioTtL_xhYHfiSgS1c" alt="Image" width="781" height="357" loading="lazy"></p>
<p>Type a simple command as a test. To run the code in any cell, you can click the run button on the left side of the code cell (looks like a “play” button with a triangle in a circle) or you can click [shift] + [enter]. The output will appear right below the code cell.</p>
<p><img src="https://lh4.googleusercontent.com/DCX2F45Bewre17_E27tFm0liy5l155iNB7vt4ohbFhCS7QUpwc47JHJ0ipkgJU6AcfKDcmLY8u2q8N-JHdBl1BwkTeM5-BQ250YbH-UwEKiLC8D6gjuo96vGcwwSFPJi0fxqbSkS" alt="Image" width="588" height="300" loading="lazy"></p>
<p>You can import many popular libraries without having to install them first. </p>
<p><img src="https://lh6.googleusercontent.com/Ya_VZMKr0gAEs-UJq7BZa-gnjQ3_AQSAq1YK-eCNQBMgibEeFuAl9BwYZvSrhOyC518v5bjJD9gIGs7WQoI87S3cy_cbJdzIScUvYP8pxpTHEhbbRwSLZwX5qojvn7MQPEfOu0F6" alt="Image" width="776" height="204" loading="lazy"></p>
<p>If you import a library or define a function in one cell, that will still be available in other cells for at least a few minutes. The runtime will disconnect if you go 30 minutes without running a cell or if you have the notebook open for 12 hours.  </p>
<h2 id="heading-explore-colab">Explore Colab</h2>
<p>If you were following along and you now have Google Colaboratory installed, you are ready to build your own projects. </p>
<p>If you click on the “<strong>&lt; &gt;</strong>” symbol on the bottom-left side of the notebook, you will find code snippets that you can use. Google also has many resources for you, some of which are at <a target="_blank" href="https://colab.research.google.com/">https://colab.research.google.com/</a> (just close out of the pop-up window that appears). </p>
<p>At freeCodeCamp, we are building a curriculum to show you how to use Python to solve math problems. You now have the tools at your fingertips. Happy coding!  </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Google Colab with VS Code ]]>
                </title>
                <description>
                    <![CDATA[ By Davis David Google Colab and VS Code are two popular editor tools that many Python developers use. They're great for developing efficient tech solutions or systems especially in the areas of Machine Learning and Data Science. If you're a Python de... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-google-colab-with-vs-code/</link>
                <guid isPermaLink="false">66d84ebbaeb1c87b6855d3dc</guid>
                
                    <category>
                        <![CDATA[ Google Colab ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Visual Studio Code ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Visual Studio Code ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 09 Aug 2021 22:24:53 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/08/1_6glvkHvmHFc9JjcExBB3-w.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Davis David</p>
<p>Google Colab and VS Code are two popular editor tools that many Python developers use. They're great for developing efficient tech solutions or systems especially in the areas of Machine Learning and Data Science.</p>
<p>If you're a Python developer or data scientist, you might already know how to use Google Colab. But did you know that you can set up VS Code on Google Colab and use it as an editor the same way as in your local machine?</p>
<p><strong>In this article, you will learn:</strong></p>
<ol>
<li>How to install the colabcode Python package.</li>
<li>How to start VS Code (code server).</li>
<li>How to access the online VS Code.</li>
<li>How to open the terminal.</li>
<li>How to run a Python file.</li>
</ol>
<h2 id="heading-how-to-use-google-colab-with-vs-code">How to Use Google Colab with VS Code</h2>
<h3 id="heading-open-colab-notebook">Open Colab Notebook</h3>
<p>The first step is to launch a new colab notebook in your Google Colab. You can rename the file as you want.</p>
<p>For example, <code>run_vscode.ipynb</code>.</p>
<h3 id="heading-install-colabcode-python-package">Install colabcode Python package.</h3>
<p>To use Google Colab with VS Code (code server), you need to install the colabcode Python package. This is an awesome open-source Python package developed by <a target="_blank" href="https://github.com/abhishekkrthakur">Abhishek Thakur</a>.</p>
<p>To install the package, run the following command in your notebook cell:</p>
<pre><code> !pip install colabcode
</code></pre><h3 id="heading-import-colabcode">Import ColabCode</h3>
<p>The next step is to import the ColabCode class from the package.</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> colabcode <span class="hljs-keyword">import</span> ColabCode
</code></pre>
<h3 id="heading-create-an-instance-of-colabcode">Create an instance of ColabCode</h3>
<p>After importing ColabCode, you need to create an instance of ColabCode and set the following arguments:</p>
<ul>
<li><strong>port</strong> – The port you want to run the code-server on. For example port=10000</li>
<li><strong>password</strong> – You can set a password to protect your code-server from unauthorized access. This is an optional argument.</li>
<li><strong>mount_drive</strong> – If you want to use your Google drive. This is a Boolean argument which means you can set it to True or False. This is an optional argument.</li>
</ul>
<pre><code class="lang-python">ColabCode(port=<span class="hljs-number">10000</span>)
</code></pre>
<h3 id="heading-start-the-code-server">Start the Code Server</h3>
<p>After running the ColabCode instance, it will start the server and show the link to access the code server.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/1_2j1llmzWvkrJ1QcDX4TyKw.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>You need to click the link and it will open in a new tab.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/1_8WOTEo4531S7KEoE9qsocA.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now you can take advantage of a full-fledged code editor and run different experiments on the Colab VM.</p>
<p><strong>Note:</strong> If you check on your Colab Notebook, you will see that the cell that runs the ColabCode instance is continuously running. Don't close your Colab notebook unless you want to close the code server that runs VS Code.</p>
<h2 id="heading-tips-to-use-vs-code-on-google-colab">Tips to use VS Code on Google Colab</h2>
<p>After launching the code server, use the following tips to help you start using VS Code on Google Colab.</p>
<h3 id="heading-step-1-open-terminal">Step 1: Open Terminal</h3>
<p>To open the terminal on VS Code that runs on Google Colab, use the following shortcut command:</p>
<pre><code class="lang-command">Ctrl + Shift + `
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/1_LdynqUTdluFY53C3DwIfdg.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-step-2-change-the-theme-if-you-want">Step 2: Change the Theme if You Want</h3>
<p>You can change the theme of the editor by clicking the setting icon (bottom-left corner) and then click "Color Theme". It will open a popup window with different theme options you can select.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/1_oRbVQGlo1juU6yh4ylOIwQ.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-step-3-run-a-python-file">Step 3: Run a Python File</h3>
<p>You can create a Python file by clicking the <strong>"File"</strong> section on the sidebar and then select a <strong>"New File"</strong> tab.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/1_8YC-QStbIB9sdzh3gV5krg-1.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>In the following example, you will see how to run a simple Python file that trains a machine-learning algorithm to classify iris flowers into three species (setosa, versicolor, or virginica) and then make a prediction.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/1_C21tD_JDFE6dh559nCmZ0Q-1.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-final-thoughts-on-using-google-colab-with-vs-code">Final Thoughts on Using Google Colab with VS Code</h2>
<p>Congratulations 👏👏, you have made it to the end of this article! I hope you have learned something new. You can set up VS Code on Google Colab and take your coding to the next level.</p>
<p>You can also use the colabcode Python package on the <strong>Kaggle</strong> platform to run VS Code. You just need to follow the same steps mentioned above.</p>
<p>If you learned something new or enjoyed reading this article, please share it so that others can see it. Until then, see you in the next post!</p>
<p>You can also find me on Twitter <a target="_blank" href="https://twitter.com/Davis_McDavid">@Davis_McDavid</a>.</p>
<p>And you can read more articles like this <a target="_blank" href="https://hackernoon.com/u/davisdavid">here</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Object Detection in Colab with Fizyr Retinanet ]]>
                </title>
                <description>
                    <![CDATA[ By RomRoc Let’s continue our journey to explore the best machine learning frameworks in computer vision. In the first article we explored object detection with the official Tensorflow APIs. The second article was dedicated to an excellent framework f... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/object-detection-in-colab-with-fizyr-retinanet-efed36ac4af3/</link>
                <guid isPermaLink="false">66c35c29cf1314a450f0d731</guid>
                
                    <category>
                        <![CDATA[ Google Colab ]]>
                    </category>
                
                    <category>
                        <![CDATA[ keras ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Machine Learning ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 04 Apr 2019 17:56:59 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*g5nzQWVR79PK2vyznKgPAA.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By RomRoc</p>
<p>Let’s continue our journey to explore the best machine learning frameworks in computer vision.</p>
<p>In the <a target="_blank" href="https://hackernoon.com/object-detection-in-google-colab-with-custom-dataset-5a7bb2b0e97e">first article</a> we explored object detection with the official Tensorflow APIs. The <a target="_blank" href="https://hackernoon.com/instance-segmentation-in-google-colab-with-custom-dataset-b3099ac23f35">second article</a> was dedicated to an excellent framework for instance segmentation, Matterport Mask R-CNN based on Keras.</p>
<p>In this article we examine <strong>Keras implementation of RetinaNet object detection developed by <a target="_blank" href="https://github.com/fizyr/keras-retinanet">Fizyr</a></strong>. RetinaNet, as described in <a target="_blank" href="https://arxiv.org/abs/1708.02002">Focal Loss for Dense Object Detection</a>, is the state of the art for object detection.<br>The object to detect with the trained model will be my little goat Rosa.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/gzJo8LgsXIrXkN2K65AGcJ6cfANG7XtNzsob" alt="Image" width="596" height="453" loading="lazy">
<em>Object detection with Fizyr</em></p>
<p><strong>The colab notebook and dataset are available in <a target="_blank" href="https://github.com/RomRoc/objdet_fizyr_colab">my Github repo</a>.</strong></p>
<p>In this article, we go through all the steps in a single Google Colab netebook to train a model starting from a custom dataset.</p>
<p>We will keep in mind these principles:</p>
<ul>
<li>illustrate how to make the annotation dataset</li>
<li>describe all the steps in a single Notebook</li>
<li>use free software, Google Colab and Google Drive, so it’s based exclusively on <strong><em>free cloud resources</em></strong></li>
</ul>
<p>At the end of the article you will be surprised by the simplicity of use and the good results we will obtain through this object detection framework.</p>
<p><em>Despite its ease of use, Fizyr is a great framework, also used by the <a target="_blank" href="https://www.kaggle.com/c/rsna-pneumonia-detection-challenge/discussion/70421"><strong>winner</strong></a> <strong>of the Kaggle competition</strong> “RSNA Pneumonia Detection Challenge”.</em></p>
<h3 id="heading-making-the-dataset">Making the dataset</h3>
<p>We start by creating annotations for the training and validation dataset, using the tool <a target="_blank" href="https://github.com/tzutalin/labelImg"><strong>LabelImg</strong></a>. This excellent annotation tool let you quickly annotate the bounding boxes of the objects to train the machine learning model.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Id6MpAH6MV52QtprI-i9IcXRn7tIle0GQfsR" alt="Image" width="800" height="434" loading="lazy">
<em>LabelImg annotation tool</em></p>
<p>LabelImg creates annotations in PascalVoc format, so we need to convert annotations to Fizyr format:</p>
<ul>
<li>create a zip file containing training dataset images and annotations with the same filename (check my example dataset in Github)</li>
</ul>
<pre><code>objdet_dataset.zip|- img1.jpg|- img1.xml|- img2.jpg|- img2.xml...
</code></pre><ul>
<li>Upload zip file in Google Drive, get Drive file id, and substitute the DATASET_DRIVEID value</li>
<li>Run cell that iterates over the xml files and creates annotations.csv file</li>
</ul>
<p><em>Note: you can see <a target="_blank" href="https://stackoverflow.com/a/48855034/9250875">my answer</a> on Stackoverflow to get the Drive file id.</em></p>
<h3 id="heading-model-training">Model training</h3>
<p>Model training is the core of the notebook. Fizyr offers various parameters, described in <a target="_blank" href="https://github.com/fizyr/keras-retinanet/blob/c841da27f540084d27e971b6d00c178ff005d344/keras_retinanet/bin/train.py#L358">Github</a>, to run and optimize this step.</p>
<p>It’s a good option to start from a pretrained model instead of training a model from scratch. Fizyr released a model based on ResNet50 architecture, pretrained on Coco dataset.</p>
<pre><code>URL_MODEL = <span class="hljs-string">'https://github.com/fizyr/keras-retinanet/releases/download/0.5.0/resnet50_coco_best_v2.1.0.h5'</span>
</code></pre><p>We can even use our pretrained model, and continue the training from it. This option is particularly useful to train for some epochs, so save it in Google Drive, and later restart the training from the saved model. In this way we can bypass the 12-hour execution limit in Colab, and we can train the model for many epochs.</p>
<p>From my tests, a high value of batch_size and steps offers better results, but they greatly increase the execution time of each epoch.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/PntGODQ4dBvWoaqJGrEErgXfKuOiBRnGE8D8" alt="Image" width="800" height="751" loading="lazy">
<em>Tensorboard training charts</em></p>
<p>We can start training from our custom dataset with:</p>
<pre><code>!keras_retinanet/bin/train.py --freeze-backbone --random-transform --weights {PRETRAINED_MODEL} --batch-size <span class="hljs-number">8</span> --steps <span class="hljs-number">500</span> --epochs <span class="hljs-number">10</span> csv annotations.csv classes.csv
</code></pre><p>Let’s analyze each argument passed to the script train.py.</p>
<ul>
<li>freeze-backbone: freeze the backbone layers, particularly useful when we use a small dataset, to avoid overfitting</li>
<li>random-transform: randomly transform the dataset to get data augmentation</li>
<li>weights: initialize the model with a pretrained model (your own model or one released by Fizyr)</li>
<li>batch-size: training batch size, higher value gives smoother learning curve</li>
<li>steps: number of steps for epochs</li>
<li>epochs: number of epochs to train</li>
<li>csv: annotations files generated by the script above</li>
</ul>
<p>The training process output contains a description of layers and loss metrics during training, and as you can see, loss metrics decrease during each epoch:</p>
<pre><code>Using TensorFlow backend....Layer (type)                    Output Shape         Param #     Connected toinput_1 (InputLayer)            (None, None, None, <span class="hljs-number">3</span> <span class="hljs-number">0</span>padding_conv1 (ZeroPadding2D)   (None, None, None, <span class="hljs-number">3</span> <span class="hljs-number">0</span>           input_1[<span class="hljs-number">0</span>][<span class="hljs-number">0</span>]                    ...Total params: <span class="hljs-number">36</span>,<span class="hljs-number">382</span>,<span class="hljs-number">957</span>Trainable params: <span class="hljs-number">12</span>,<span class="hljs-number">821</span>,<span class="hljs-number">805</span>Non-trainable params: <span class="hljs-number">23</span>,<span class="hljs-number">561</span>,<span class="hljs-number">152</span>NoneEpoch <span class="hljs-number">1</span>/<span class="hljs-number">10500</span>/<span class="hljs-number">500</span> [==============================] - <span class="hljs-number">1314</span>s <span class="hljs-number">3</span>s/step - loss: <span class="hljs-number">1.0659</span> - regression_loss: <span class="hljs-number">0.6996</span> - classification_loss: <span class="hljs-number">0.3663</span>Epoch <span class="hljs-number">2</span>/<span class="hljs-number">10500</span>/<span class="hljs-number">500</span> [==============================] - <span class="hljs-number">1296</span>s <span class="hljs-number">3</span>s/step - loss: <span class="hljs-number">0.6747</span> - regression_loss: <span class="hljs-number">0.5698</span> - classification_loss: <span class="hljs-number">0.1048</span>Epoch <span class="hljs-number">3</span>/<span class="hljs-number">10500</span>/<span class="hljs-number">500</span> [==============================] - <span class="hljs-number">1304</span>s <span class="hljs-number">3</span>s/step - loss: <span class="hljs-number">0.5763</span> - regression_loss: <span class="hljs-number">0.5010</span> - classification_loss: <span class="hljs-number">0.0753</span>
</code></pre><pre><code>Epoch <span class="hljs-number">3</span>/<span class="hljs-number">10500</span>/<span class="hljs-number">500</span> [==============================] - <span class="hljs-number">1257</span>s <span class="hljs-number">3</span>s/step - loss: <span class="hljs-number">0.5705</span> - regression_loss: <span class="hljs-number">0.4974</span> - classification_loss: <span class="hljs-number">0.0732</span>
</code></pre><h3 id="heading-inference">Inference</h3>
<p>The last step performs inference of test images with the trained model.<br>The Fizyr framework allows us to perform inference using CPU, even if you trained the model with GPU. This feature is important in typical production environments, where people usually opt for less expensive hardware infrastructures for inference, without GPUs.</p>
<p>Let’s examine the following lines in detail:</p>
<pre><code>model_path = os.path.join(<span class="hljs-string">'snapshots'</span>, sorted(os.listdir(<span class="hljs-string">'snapshots'</span>), reverse=True)[<span class="hljs-number">0</span>])print(model_path)
</code></pre><pre><code># load retinanet modelmodel = models.load_model(model_path, backbone_name=<span class="hljs-string">'resnet50'</span>)model = models.convert_model(model)
</code></pre><p>The first line sets the model file as the last model generated by the training process in /snapshots directory. Then the model is loaded from the filesystem and converted to run inference.</p>
<p>You can change the values of THRES_SCORE, which represents the confidence threshold to show an object detection.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/mkkUoWpQY5-4mpXzEacDzy7bqP1QfGaVqUXZ" alt="Image" width="596" height="453" loading="lazy">
<em>Object detection inference</em></p>
<h3 id="heading-conclusions">Conclusions</h3>
<p>We went through the complete journey to make object detection with Fizyr implementation of RetinaNet. We created a dataset, trained a model, and ran inference (<a target="_blank" href="https://github.com/RomRoc/objdet_fizyr_colab">here</a> is my Github repo for the notebook and dataset).</p>
<p>I was impressed by the following aspects of this excellent framework:</p>
<ul>
<li>this framework is <strong>easy to use</strong> to get good inference, even without much customization</li>
<li>it was <strong>simple to transform annotations</strong> to Fizyr’s dataset format, compared to other frameworks.</li>
</ul>
<p>In general Fizyr is a good choice to start an object detection project, in particular if you need to quickly get good results.</p>
<p>If you enjoyed this article, leave a few claps, it will encourage me to explore further machine learning opportunities :)</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
