<?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" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ori Bar-El on Medium]]></title>
        <description><![CDATA[Stories by Ori Bar-El on Medium]]></description>
        <link>https://medium.com/@oribarel?source=rss-970a13edcb34------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*eBYAtSDkvBYXk3cS</url>
            <title>Stories by Ori Bar-El on Medium</title>
            <link>https://medium.com/@oribarel?source=rss-970a13edcb34------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 22:20:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@oribarel/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Getting the Most Out of Your Google Colab]]></title>
            <link>https://medium.com/@oribarel/getting-the-most-out-of-your-google-colab-2b0585f82403?source=rss-970a13edcb34------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b0585f82403</guid>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Ori Bar-El]]></dc:creator>
            <pubDate>Sat, 13 Oct 2018 12:42:37 GMT</pubDate>
            <atom:updated>2018-12-23T08:33:37.382Z</atom:updated>
            <content:encoded><![CDATA[<h3>Getting the Most Out of Your Google Colab (Tutorial)</h3><h3>Background</h3><p>Two months ago we started working on an academic project that makes use of deep neural networks. To train our model, we used Google Colaboratory platform as it is the only free GPU platform we have found. After exploring a good tutorial for using this platform, we managed to find <a href="https://medium.com/deep-learning-turkey/google-colab-free-gpu-tutorial-e113627b9f5d">this </a>excellent tutorial. Although very useful, we still found it difficult to train our model effectively. For that reason <a href="https://medium.com/u/742071805b41">Ori Licht</a> and myself are writing this tutorial, that will hopefully help you to get the most out of your Google Colab. In this tutorial we will go over the flow we used step-by-step.</p><p>Most of the code in this tutorial can be found <a href="https://colab.research.google.com/drive/16nkLsNCzKd3lpiZzkWEhIe_Y-hNr6C2Q">here</a>.</p><h3>Using GPU</h3><p>As of October 13, 2018, Google Colab provides a single 12GB NVIDIA Tesla K80 GPU that can be used up to 12 hours continuously. Recently, Colab also started offering free TPU.</p><p>To use the google colab in a GPU mode you have to make sure the hardware accelerator is configured to GPU. To do this go to Runtime→Change runtime type and change the Hardware accelerator to GPU.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/0*-NuARKc7LqnL5KVU" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/0*if7EeeCeAYHTl7ai" /></figure><p>Sometimes, all GPUs are in use and there is no GPU available. If this is the case, you will get the following alert, and you will have to wait for a while and try again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*etWw_7i9FbJqO8lN.png" /></figure><p>To make sure Colab uses GPU you can run:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96a3579cc2dbd9d04165dcf7f896f4ce/href">https://medium.com/media/96a3579cc2dbd9d04165dcf7f896f4ce/href</a></iframe><p>As noted earlier, the GPU provided has 12GB of memory. However, sometimes the memory of your GPU is shared with other users. At that situation you won’t be able to train your model properly. To make sure that the current GPU memory utilization is 0, run the code below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59bb73e5d8cccf471debac06b6b37277/href">https://medium.com/media/59bb73e5d8cccf471debac06b6b37277/href</a></iframe><p>You should see the following output (the last line with Util 0% is what you should look for):</p><pre>Collecting gputil</pre><pre>Downloading <a href="https://files.pythonhosted.org/packages/45/99/837428d26b47ebd6b66d6e1b180e98ec4a557767a93a81a02ea9d6242611/GPUtil-1.3.0.tar.gz">https://files.pythonhosted.org/packages/45/99/837428d26b47ebd6b66d6e1b180e98ec4a557767a93a81a02ea9d6242611/GPUtil-1.3.0.tar.gz</a></pre><pre>Requirement already satisfied: numpy in /usr/local/lib/python2.7/dist-packages (from gputil) (1.14.5)</pre><pre>Building wheels for collected packages: gputil</pre><pre>Running setup.py bdist_wheel for gputil ... done</pre><pre>Stored in directory: /root/.cache/pip/wheels/17/0f/04/b79c006972335e35472c0b835ed52bfc0815258d409f560108</pre><pre>Successfully built gputil</pre><pre>Installing collected packages: gputil</pre><pre>Successfully installed gputil-1.3.0</pre><pre>Requirement already satisfied: psutil in /usr/local/lib/python2.7/dist-packages (5.4.7)</pre><pre>Collecting humanize</pre><pre>Downloading <a href="https://files.pythonhosted.org/packages/8c/e0/e512e4ac6d091fc990bbe13f9e0378f34cf6eecd1c6c268c9e598dcf5bb9/humanize-0.5.1.tar.gz">https://files.pythonhosted.org/packages/8c/e0/e512e4ac6d091fc990bbe13f9e0378f34cf6eecd1c6c268c9e598dcf5bb9/humanize-0.5.1.tar.gz</a></pre><pre>Building wheels for collected packages: humanize</pre><pre>Running setup.py bdist_wheel for humanize ... done</pre><pre>Stored in directory: /root/.cache/pip/wheels/69/86/6c/f8b8593bc273ec4b0c653d3827f7482bb2001a2781a73b7f44</pre><pre>Successfully built humanize</pre><pre>Installing collected packages: humanize</pre><pre>Successfully installed humanize-0.5.1</pre><pre>(&#39;Gen RAM Free: 12.8 GB&#39;, &#39; | Proc size: 145.1 MB&#39;)</pre><pre>GPU RAM Free: 11439MB |<strong> Used: 0MB | Util   0%</strong> | Total 11439MB</pre><p>If this is not the case, and the utilization is greater than 0% try to <strong>kill</strong> your machine, using the code below. This might not work on your first attempt and you can try this multiple times.</p><p>!kill -9 -1</p><h3>Using your data</h3><p>When training your model, we will need not only your code, but also data. Uploading your code and data to Colab is possible but has 3 main drawbacks:</p><ul><li>The uploading speed is very low.</li><li>After 12 hours your machine will be shut down, and consequently all your data will be gone.</li><li>The data is saved to the /dev/shm mount point which has only 64MB available (running !df -h will show you that).</li></ul><p>For that reason, the easiest way to use your data is to mount your Google Drive account.</p><h3>Mounting Google Drive</h3><p>Using FUSE</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/273e26d84b6b0b4534716c8110d33bab/href">https://medium.com/media/273e26d84b6b0b4534716c8110d33bab/href</a></iframe><p><strong>OR </strong>using google.colab library</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e776b9ea9db4df14d48d66e2ce71d156/href">https://medium.com/media/e776b9ea9db4df14d48d66e2ce71d156/href</a></iframe><p>After running <strong>one </strong>the code snippets above, you’ll have to authenticate your Colab in your Drive account using the following steps:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VonjLFtKRM6G1JLK" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/0*QHBCVyVt_ggnYilb" /><figcaption>Choose your account and choose <strong>Allow</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/0*bXWnrYlGUYmhbAXg" /><figcaption>Copy the hash to the text entry in you Colab notebook</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*npYxrVg1BomQ5INC.png" /><figcaption>Copy the hash to the text entry in you Colab notebook and press Enter</figcaption></figure><p>A new link for authentication may appear and you should repeat the steps above.</p><p>After that being done, you should get:</p><p>Please enter the verification code: Access token retrieved correctly.</p><p>You are now ready to mount your Drive account to Colab (this is relevant for the first method that uses FUSE and not to the second that uses google.colab) library:</p><pre>!mkdir -p drive<br>!google-drive-ocamlfuse drive</pre><h3>Updating your data</h3><p>Once your Drive is mounted, any change to your drive directory (editing code, adding files, etc.) will <strong>not</strong> be encountered by Colab. This is due to Colab caching mechanism. To overcome this, you should clear the cache before using your new files, using:</p><p>!google-drive-ocamlfuse -cc</p><p>Note that this is a time-consuming process, and therefore you should better avoid it, if no change has been made to your drive.</p><h3>Accelerate Training</h3><p>If you reached to this point, you might think that you are ready to train your model. Although you can indeed start to train your model (after installing the required libraries), the training is going to be slow, and the promised speed-up using GPU won’t be noticeable. This is due to the overhead of transferring the data from your Drive to Colab. In order to overcome this issue we suggest you to use some sort of memory mapped file formats like HDF5 (aka H5) or LMDB. For your convenience, Python offers the h5py and lmdb libraries to handle these file formats. h5py makes it easy to store and manipulate existing data in the form of NumPy arrays.</p><p>This code creates a new .h5 file with placeholders for training, development and test datasets.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6639393caf26a86db5aee165521b7c62/href">https://medium.com/media/6639393caf26a86db5aee165521b7c62/href</a></iframe><p>To load your data into these placeholders you can access your place holders in a Python dictionary style. Here we load images to our X_train placeholder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d756d27e541680f92e329b02b95ef55/href">https://medium.com/media/4d756d27e541680f92e329b02b95ef55/href</a></iframe><p>To read you .h5 file, you use the same approach. for more details see <a href="http://docs.h5py.org/en/latest/quick.html">the official h5py documentation</a>.</p><p>If you are using PyTorch, you will have to write your own .h5 Dataset that will be used by PyTorch DataLoader:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/002273ce012182fa0099a1cb6c6b75f0/href">https://medium.com/media/002273ce012182fa0099a1cb6c6b75f0/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fd1bc1a3529a8344ed133c750e463d5/href">https://medium.com/media/6fd1bc1a3529a8344ed133c750e463d5/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b0585f82403" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>