<?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 Ali on Medium]]></title>
        <description><![CDATA[Stories by Ali on Medium]]></description>
        <link>https://medium.com/@alitbk?source=rss-e1ade2619a87------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*IdedKN6DfacDUx9cbddeTA.png</url>
            <title>Stories by Ali on Medium</title>
            <link>https://medium.com/@alitbk?source=rss-e1ade2619a87------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 12:04:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alitbk/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[Image Classification in a Nutshell: 5 Different Modelling Approaches in PyTorch with CIFAR100]]></title>
            <link>https://medium.com/@alitbk/image-classification-in-a-nutshell-5-different-modelling-approaches-in-pytorch-with-cifar100-8f690866b373?source=rss-e1ade2619a87------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f690866b373</guid>
            <category><![CDATA[resnet]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[pytorch]]></category>
            <dc:creator><![CDATA[Ali]]></dc:creator>
            <pubDate>Sat, 04 Jul 2020 09:19:43 GMT</pubDate>
            <atom:updated>2020-07-13T23:51:25.570Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*SA6F97VF-xMKuiSMVOEw0w.png" /><figcaption>Source: A sample data from CIFAR100</figcaption></figure><p><strong>Introduction:</strong></p><p>This project includes 5 different modelling approaches for image classification problem with CIFAR100 data-set and demonstrates how the power of the models increase as they become deeper. Here I am going to represent the results from first 4 models, since the ResNet12 model is nothing but a further improvement on the similar structure of ResNet9 model. However, you can check the <a href="https://jovian.ml/alitabakds/my-first-project">notebook </a>of this project to see the models in more detail. Additionally, this blog post also does not aim to explain all the details about each model but rather it compares the results and highlights the difference of the model structures. That’s said, here is the list of models used:</p><ul><li>Logistic Regression Model</li><li>Feedforward Neural Network</li><li>Convolutional Neural Network</li><li>ResNet9</li><li>ResNet12</li></ul><p><strong>Data-set:</strong></p><p>For this project CIFAR100 data-set is used. This data-set consist of 60000 32x32 RGB images, means they have 3 channels, where 50000 of the objects in the data are training images and 10000 are testing images. CIFAR100 has 100 classes and each of those has 600 images, these are separated as 500 training images and 100 testing images. Both the data-set and also above given explanations can be found on: <a href="https://www.cs.toronto.edu/~kriz/cifar.html">https://www.cs.toronto.edu/~kriz/cifar.html</a>. <br>(<strong>Citation of the Data-set:</strong> Learning Multiple Layers of Features from Tiny Images, Alex Krizhevsky, 2009.)</p><p><strong>Exploration of the Data-set:</strong></p><p>1- Below given codes represent:</p><ul><li>The libraries used in this project, from which <em>“from torchvision.datasets import CIFAR100” </em>is used<em> </em>to import the data-set.</li><li>A way of downloading the data-set. Please note that there are also alternative ways to download a data. Since we need our data in tensor form, the data is transformed by using ToTensor() which is also imported from torchvision with the following code: <em>“from torchvision.transforms import ToTensor”</em></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D1&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D1&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/259fafc36e9859e09847c3db653ab8ff/href">https://medium.com/media/259fafc36e9859e09847c3db653ab8ff/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D6%26hideOutput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D6%26hideOutput%3Dtrue&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/dec9cf6cbdd9c02b3aba5d1811971df6/href">https://medium.com/media/dec9cf6cbdd9c02b3aba5d1811971df6/href</a></iframe><p>2 - To be able to see the length of the training and the test data-sets, and also the names of the 100 classes in CIFAR100 data, following codes are used. Here classes demonstrate the specific categories to which each image belongs to.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D7&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D7&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0d3abb9e067adab8db8ed6e4ad0a2c2/href">https://medium.com/media/a0d3abb9e067adab8db8ed6e4ad0a2c2/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D8&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D8&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/86699f8bfbc6a28a8c50b3f6fb0c22f2/href">https://medium.com/media/86699f8bfbc6a28a8c50b3f6fb0c22f2/href</a></iframe><p>3- In the data-set explanations it has been mentioned that CIFAR100 data consist of 60000 32x32 images with 3 channels. This can be also seen in a tensor form. To see that following block of code is used and that gives the output <em>“torch.Size([3, 32, 32])”</em> where each number represents a dimension and:</p><ul><li>The initial number 3 shows the number of channels, since they are images with colors they have 3 channels which represent Red, Green, and Blue so to say RGB.</li><li>The last two numbers indicate the pixels which means these are images with 32x32 pixels.</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D9&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D9&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb71c7a2af8e9d456538e784f1e648b5/href">https://medium.com/media/cb71c7a2af8e9d456538e784f1e648b5/href</a></iframe><ul><li>Images can be explored even in further detail in order to see how the information in those images are stored. Below given example shows the partial information in those tensors:</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D10&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D10&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/492579e15d0a8b12f540f8694dbc12e5/href">https://medium.com/media/492579e15d0a8b12f540f8694dbc12e5/href</a></iframe><ul><li>Please note that these pixel values are only in between 20th and 25th rows and columns.</li><li>A visualization of a single image is given below:</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D11&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D11&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/383f41aac2c00eb5cd63e7ff1e9b7695/href">https://medium.com/media/383f41aac2c00eb5cd63e7ff1e9b7695/href</a></iframe><ul><li>As a final point in the data exploration let us see how in general the images are seen in our data:</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D20&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D20&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/963cb13856f2808f0c68279fa70288a8/href">https://medium.com/media/963cb13856f2808f0c68279fa70288a8/href</a></iframe><p><strong>Data Preparation:</strong></p><p>Below one can find how we can prepare our data for our machine learning algorithms.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D16&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D16&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c091eead84351fec36b7357613311dfb/href">https://medium.com/media/c091eead84351fec36b7357613311dfb/href</a></iframe><p>Here the manual_seed is used to ensure that the results are reproducible. The code also shows that 10000 images out of 50000 training images are stored as the validation data-set. After that there are 40000 images for training, 10000 images for validation and 10000 images for testing.</p><p>As a next step dataloaders are defined which are used in order to be able to load the data in batches.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D19&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D19&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/caa1accd79a4dc31a32c4e2534ec4ed9/href">https://medium.com/media/caa1accd79a4dc31a32c4e2534ec4ed9/href</a></iframe><p><strong>GPU(s) and why we need them?</strong></p><p>Before going further I would like to mention shortly about the GPUs and why we need to use them. I am mentioning about GPUs because of two main reasons. Firstly, we are going to re-define our dataloaders so that a GPU can also be used for dataloaders, when the GPU is available. Secondly, GPU is also used for model training because increasing size of data and complexity of the models could increase also the training time. In order to be able to reduce the training time we need to use GPUs, if one is available. You can check the <a href="https://jovian.ml/alitabakds/my-first-project">notebook </a>of this project to see in detail how GPUs are defined.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D26&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D26&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/54a09c38a1ea0417e03b8ea785c210b7/href">https://medium.com/media/54a09c38a1ea0417e03b8ea785c210b7/href</a></iframe><p><strong>Defining the Base of the Models: Generics Creation</strong></p><p>Even if each model has some model specific features to be written, some of the model procedures are common. Therefore, we can define the generics and the code below shows that for the training and validation step.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D100&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D100&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6dc9cb6b2f05c29394e90c743e2908d/href">https://medium.com/media/e6dc9cb6b2f05c29394e90c743e2908d/href</a></iframe><p><strong>Create the Logistic Regression Model:</strong></p><p>This model is used as an initial base model in this project. Subsequent models represent gradual improvement as it has been mentioned in the introduction. Logistic regression model has images as inputs and output is a vector of size 10 for each image. This output represents the probabilities of the labels for those images and model picks the highest probability as the predicted label of an image. For more detailed information please check the following references from <strong>Aakash N S</strong>: Lecture notebook on<a href="https://jovian.ml/aakashns/03-logistic-regression"> Logistic Regression</a> and the lecture <a href="https://www.youtube.com/watch?v=4ZZrP68yXCI">video</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D31&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D31&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/343c0e9e936aaf323be0a8e3420e7cb5/href">https://medium.com/media/343c0e9e936aaf323be0a8e3420e7cb5/href</a></iframe><p><strong>Logistic Regression Model Setup:</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D32&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D32&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b8049fbb19290f7cee1f8dce96cfc30/href">https://medium.com/media/7b8049fbb19290f7cee1f8dce96cfc30/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D33&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D33&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/19a559e98f536948f3ddfc6bbb09d145/href">https://medium.com/media/19a559e98f536948f3ddfc6bbb09d145/href</a></iframe><p><strong>Logistic Regression Model Training:</strong></p><p>In the following code evaluate and fit functions are defined where evaluate function is used to evaluate the model and fit function is defined to train the algorithm with the given hyperparameters.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D35&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D35&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/729edec3ec7e1e3c5cce010f5ae6e831/href">https://medium.com/media/729edec3ec7e1e3c5cce010f5ae6e831/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D37&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D37&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/681005335671253fd44848800a32006d/href">https://medium.com/media/681005335671253fd44848800a32006d/href</a></iframe><p>Above given code calculates the initial results of the model before training. Output shows that the loss is high and accuracy is low.</p><p>After training the model, see the following block of code, it can be seen how the model results improve further.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D39&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D39&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/3dd466f3ced0766286f11c439f72b64e/href">https://medium.com/media/3dd466f3ced0766286f11c439f72b64e/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D40&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D40&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ef4fcba0e90444e3271aa1e53fef3b3/href">https://medium.com/media/6ef4fcba0e90444e3271aa1e53fef3b3/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D41&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D41&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/10f294fce28372b355f73e609d72b106/href">https://medium.com/media/10f294fce28372b355f73e609d72b106/href</a></iframe><p>After 30 epochs in total and with the given learning rates model reaches to 18% accuracy. In addition to that, these results also shows the limits of this model with those given epoch numbers and learning rates. Because as it can be seen also from the results, model does not improve further than 18% accuracy. The following figure also visualizes this, on which we can see that after certain point accuracy level has a stable path.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D46&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D46&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/470fb98e9cd6b6a040270f12646a88b3/href">https://medium.com/media/470fb98e9cd6b6a040270f12646a88b3/href</a></iframe><p>In order to improve these results other architecture(s) might be helpful. For that reason in the subsequent sections feedforward neural network, convolutional neural network and ResNet9 is demonstrated, respectively.</p><p><strong>Create the Feedforward Neural Network - Model Setup:</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D55&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D55&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ea95798111d2ead4442c14444d3f552/href">https://medium.com/media/7ea95798111d2ead4442c14444d3f552/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D56&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D56&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/abc8dfccca6d890ae6b3ac9dd77cdfd6/href">https://medium.com/media/abc8dfccca6d890ae6b3ac9dd77cdfd6/href</a></iframe><p>Since fit and evaluation functions are similar with logistic regression model, only the model structure represented here. As a brief explanation, feedforward neural network differs at the point where we insert an additional layer in our model. In this example, model consist of one hidden layer and one output layer. For more details please check the following reference notebook on <a href="https://jovian.ml/aakashns/04-feedforward-nn">feedforward neural networks</a> and <a href="https://www.youtube.com/watch?v=9suSsTVhYuw">lecture video</a> from <strong>Aakash N S</strong>. Additionally, I benefited also from the information in this <a href="https://stats.stackexchange.com/questions/181/how-to-choose-the-number-of-hidden-layers-and-nodes-in-a-feedforward-neural-netw"><strong>link</strong></a><strong> </strong>when it comes to the number of layers in the model structure.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D58&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D58&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/cee270a50c156aa4db2db0da50f30b5c/href">https://medium.com/media/cee270a50c156aa4db2db0da50f30b5c/href</a></iframe><p>Above, similarly to the logistic regression model, initial results of the model before the training can be found. Again the loss is high and accuracy is low. However, this time it can be seen that, after the training, how the results of the model improved further than 18% accuracy level after inserting that additional layer, where the number of epochs and learning rates are same as logistic regression model.</p><p><strong>Feedforward Neural Network Model Training:</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D60&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D60&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/56278b762168445c4f95e135521f1d80/href">https://medium.com/media/56278b762168445c4f95e135521f1d80/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D61&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D61&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/caa362d9c7bbab07161d2020730fe802/href">https://medium.com/media/caa362d9c7bbab07161d2020730fe802/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D62&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D62&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/9deac4f333ced1ed15f9274ea11ffb28/href">https://medium.com/media/9deac4f333ced1ed15f9274ea11ffb28/href</a></iframe><p>As it can be seen from the results, model has reached to 25–26% accuracy which is a clear improvement after basic logistic regression model. However, similarly to the results of logistic regression model, this model also reaches its limits after certain number of epochs and does not improve further than 26% level of accuracy. Again, below given figure shows how the model accuracy evolves over time and stays on a stable path after certain point.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D66&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D66&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/228c24f87be72b360819e0874179e208/href">https://medium.com/media/228c24f87be72b360819e0874179e208/href</a></iframe><p>On the other hand, end result of the model also depends on defined hyperparameters but this can also increase the training time. Since the objective here is also to show the improvement in the results, as models become deeper, from this point on I would like to introduce the results from the convolutional neural network.</p><p><strong>Create the Convolutional Neural Network (CNN):</strong></p><p>As a further improvement after feedforward neural network below CNN model is represented. In order to keep the focus on model comparison, I would not go into details about CNN. However, basically, in CNN we have a kernel to apply on the images where an elementwise multiplication between kernel and image matrix takes place. For more detail information please see the following references about CNN: (1) - <a href="https://jovian.ml/aakashns/05-cifar10-cnn">Lecture Notebook</a> and <a href="https://www.youtube.com/watch?v=TN9fMYQxw4E">Video</a> from <strong>Aakash N S</strong>, (2) - A blog post from <strong>Irhum Shafkat:</strong> <a href="https://towardsdatascience.com/intuitively-understanding-convolutions-for-deep-learning-1f6f42faee1">Intuitively Understanding Convolutions for Deep Learning</a></p><p><strong>CNN Model Setup:</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D76&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D76&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1a40875043909ce786586d3c7b1931e/href">https://medium.com/media/b1a40875043909ce786586d3c7b1931e/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D79&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D79&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3e1f5bf6aa48bd9f6aaa3f993c265a1/href">https://medium.com/media/f3e1f5bf6aa48bd9f6aaa3f993c265a1/href</a></iframe><p><strong>CNN Model Training:</strong></p><p>Again with the same logic from logistic regression and feedforward neural network model, in the following code evaluate and fit functions are defined.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D78&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D78&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/df43d738b218d75566869935290a890f/href">https://medium.com/media/df43d738b218d75566869935290a890f/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D81&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D81&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e6dfd21cce9d1ad2c7a71bfc9dfe976/href">https://medium.com/media/3e6dfd21cce9d1ad2c7a71bfc9dfe976/href</a></iframe><p>Above initial results of the model before training can be found. Here it can be also seen that magnitude of the loss and accuracy are also quite similar to the previous models. Below it can be seen that after the training the results of the model improved further than 25–26% accuracy level of feedforward neural network. As a side note, this time in addition to different model structure also another optimizer is used.</p><ul><li>Model hyperparameters and optimizer:</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D83&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D83&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b882ad204fd7fadc7367a5451a216c5/href">https://medium.com/media/3b882ad204fd7fadc7367a5451a216c5/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D84&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D84&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/d030dc7b21c6b570e608972bc28e0032/href">https://medium.com/media/d030dc7b21c6b570e608972bc28e0032/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D85&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D85&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c1a71102f595168d957b6da36d24b61/href">https://medium.com/media/8c1a71102f595168d957b6da36d24b61/href</a></iframe><p>From the results above it can be seen that model has reached to 35% validation accuracy which is a further improvement on previous two models. Similarly to the previous arguments, this model also has its limits as in the previous models. In the below provided figure it can be seen again that accuracy level improves gradually over time and becomes stable after certain point:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D87&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D87&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd77fd302edbde7b06bd74f7d504e18c/href">https://medium.com/media/fd77fd302edbde7b06bd74f7d504e18c/href</a></iframe><p>In addition to the discussion above, the CNN model also starts to over-fit after some time. However, I would like to go into details about that in the following section.</p><p><strong>Create the ResNet9 model:</strong></p><p>Before going into model details, I would like to explain why I used ResNet models. As I have explained in the introduction, this project is based on 5 different models with the objective of showing how the model accuracy improves when the models become deeper. At this step, I would like to shortly introduce the validation loss and accuracy of the first three models based on the test data-set.</p><p><em>Logistic Regression:</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D50&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D50&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ba9a9570c75fd43fe0435dcda5c0e72/href">https://medium.com/media/3ba9a9570c75fd43fe0435dcda5c0e72/href</a></iframe><p><em>Feedforward Neural Network:</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D69&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D69&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b5e651e0af057a4e4008d7df1f21ab3/href">https://medium.com/media/7b5e651e0af057a4e4008d7df1f21ab3/href</a></iframe><p><em>Convolutional Neural Network:</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D93&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D93&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f71dc0e09d8e4b0650c8cfd32289ce0/href">https://medium.com/media/5f71dc0e09d8e4b0650c8cfd32289ce0/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D89&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D89&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c243ebb56ae7096e1b751c32cdc06994/href">https://medium.com/media/c243ebb56ae7096e1b751c32cdc06994/href</a></iframe><p>Here we can see clearly once again how the accuracy level increases from basic logistic regression model through the CNN. However, as we can also see in the figure above, in CNN model, after some point, we are facing with over-fitting problem. Since the training loss continues to decrease, but on the other hand validation loss first decreases and then starts to increase again. Why is that? It is because, during the training, algorithm tries to reduce the loss in training data-set and at some point starts to learn some patterns which is quite specific to the training data-set. This issue leads to that model cannot generalize well to the unseen data! (<a href="https://jovian.ml/aakashns/05-cifar10-cnn">Reference: CNN Lecture</a>)</p><p>To overcome this problem, we can insert more data, use regularization techniques (e.g. Batch Normalization), and we can also stop earlier with training of the model if validation loss starts to increase. (<a href="https://jovian.ml/aakashns/05-cifar10-cnn">Reference: CNN Lecture</a>)</p><p>With the ResNet model some of these methods will be applied. After the implementation of the ResNet model we are going to see a substantial increase in the model accuracy.</p><p>Below ResNet9 model is demonstrated, which is a further improvement after the CNN model. Part of this improvement comes from the implementation of two residual blocks that we are using. In ResNet9 model, 9 means that our model has 9 layers, which consists of 8 convolutional layers and 1 linear layer. (Reference: <a href="https://jovian.ml/aakashns/05b-cifar10-resnet">ResNet Lecture</a>)</p><p>In the model setup we can see that <em>def conv_block()</em> helper function is used and there <em>Batch Normalization</em> method is applied. Batch Normalization basically normalizes the outputs of each layer to prevent that an output from a layer having a disproportionately larger effect on the rest of the process.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D101&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D101&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b06705391ed4db0c3445052bc13e9fdf/href">https://medium.com/media/b06705391ed4db0c3445052bc13e9fdf/href</a></iframe><p><strong>Model Training:</strong></p><p>In the below given code block, similarly to the previous models, evaluate and fit functions are defined for evaluation and training of the model, respectively. However this time there is a difference from the first three models. Because for the training of the ResNet model additional measures are taken on learning rate, weights and gradients.</p><p>For the learning rate, <em>learning rate scheduling method</em> is used and with that method learning rate is no longer constant. The method used here is based on <em>“One Cycle Learning Rate Policy”</em> to learn more about this you can use the following <a href="https://sgugger.github.io/the-1cycle-policy.html">source</a>.</p><p>Fit function also includes <em>weight decay</em> and <em>gradient clipping</em>. Weight decay is a measure taken to prevent that weights become too large and have disproportionate affects. Gradient clipping is also a measure which prevents gradients becoming too large and having harmful impact on model parameters.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D103&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D103&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/979849fd8c0f629bf25ad018e5f1c6d1/href">https://medium.com/media/979849fd8c0f629bf25ad018e5f1c6d1/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D104%26hideOutput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D104%26hideOutput%3Dtrue&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/97b98176bbfc3e2af023381cad46f680/href">https://medium.com/media/97b98176bbfc3e2af023381cad46f680/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D105&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D105&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/be72a62829b428837de8d2f4efaf4688/href">https://medium.com/media/be72a62829b428837de8d2f4efaf4688/href</a></iframe><p>Above we can see the initial results of ResNet model before training. At this step we have similar initial results as with the previous models. To improve the results we need to train the model. For that, the following hyperparameters are defined and the ResNet model is trained.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D106&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D106&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbee58f8a935e40147841805dba7ec80/href">https://medium.com/media/fbee58f8a935e40147841805dba7ec80/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D107&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F64%26cellId%3D107&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/f805dca3df7118d0aa95fdf8a331e834/href">https://medium.com/media/f805dca3df7118d0aa95fdf8a331e834/href</a></iframe><p>From the results above we can see that after all measures taken and with the ResNet model, we can reach to 65% validation accuracy, which was 35% with CNN model. The result here is a substantial improvement in comparison to other models!</p><p>The figures below show the movement of both accuracy and losses of the model over time.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D108&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D108&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/eba7e5f1451f7b3fc25c7eefa198f3cd/href">https://medium.com/media/eba7e5f1451f7b3fc25c7eefa198f3cd/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D110&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D110&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd3eab4403dca31f98ba3b49e5d9ec82/href">https://medium.com/media/bd3eab4403dca31f98ba3b49e5d9ec82/href</a></iframe><p>Here is also an extra figure which shows the movement of learning rates over time. Since the model did not use a constant learning rate, it was changing throughout the training process.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D112&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2Fmy-first-project%2Fv%2F65%26cellId%3D112&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce9a041c22e282425b5b5c2cd93013ff/href">https://medium.com/media/ce9a041c22e282425b5b5c2cd93013ff/href</a></iframe><p><strong>Conclusion:</strong></p><p>Well that’s it! I hope this blog post provides you insight about how the power of models increases as they become deeper.</p><p>That’s said, I would like to thank once again to <a href="https://jovian.ml/">Jovian.ml</a> and <a href="https://www.freecodecamp.org/">freecodecamp.org</a> for providing the Deep Learning with PyTorch: Zero to GANs online certification course. Additionally, I also would like to thank to instructor of the course <a href="https://medium.com/u/ca6fe690e934">Aakash N S</a> and <strong>his team</strong>. That was a really nice journey!</p><p>This project is prepared as the course project of Deep Learning with PyTorch: Zero to GANs online certification course. You can access to the entire <a href="https://jovian.ml/alitabakds/my-first-project">notebook </a>by clicking on the link.</p><p><strong>References:</strong></p><ul><li><a href="https://www.cs.toronto.edu/~kriz/cifar.html"><strong>Source link for CIFAR100</strong></a></li><li><strong>Citation of Dataset:</strong> Learning Multiple Layers of Features from Tiny Images, Alex Krizhevsky, 2009.</li><li><a href="https://jovian.ml/alitabakds/my-first-project"><strong>Notebook of this project</strong></a></li><li><strong>Lecture Notebooks from Aakash N S:</strong></li><li><a href="https://jovian.ml/aakashns/03-logistic-regression">Logistic Regression</a></li><li><a href="https://jovian.ml/aakashns/04-feedforward-nn">Feedforward neural networks</a></li><li><a href="https://jovian.ml/aakashns/05-cifar10-cnn">Convolutional Neural Networks</a></li><li><a href="https://jovian.ml/aakashns/05b-cifar10-resnet">ResNet</a></li><li><strong>Lecture Videos from Aakash N S:</strong></li><li><a href="https://www.youtube.com/watch?v=4ZZrP68yXCI">Logistic Regression</a></li><li><a href="https://www.youtube.com/watch?v=9suSsTVhYuw">Feedforward Neural Network</a></li><li><a href="https://www.youtube.com/watch?v=TN9fMYQxw4E">Convolutional Neural Networks</a></li><li><a href="https://www.youtube.com/watch?v=sJF6PiAjE1M">ResNet</a></li><li><strong>Convolutional Neural Network:</strong></li><li>Irhum Shafkat: <a href="https://towardsdatascience.com/intuitively-understanding-convolutions-for-deep-learning-1f6f42faee1">Intuitively Understanding Convolutions for Deep Learning</a></li><li><strong>One Cycle Learning Rate Policy:</strong></li><li><a href="https://sgugger.github.io/the-1cycle-policy.html">https://sgugger.github.io/the-1cycle-policy.html</a></li><li><strong>Feedforward Neural Networks Model Structure:</strong></li><li><a href="https://stats.stackexchange.com/questions/181/how-to-choose-the-number-of-hidden-layers-and-nodes-in-a-feedforward-neural-netw">Number of Hidden Layers</a></li><li><strong>Other Notebooks and References:</strong></li><li><a href="https://jovian.ml/aakashns/03-cifar10-feedforward">Neural Network</a></li><li>Overall lecture notebooks on <em>jovian.ml</em> and lecture videos available on Youtube from <strong>Aakash N S</strong> and <strong>Jovian.ml</strong></li><li><a href="https://pytorch.org/docs/stable/index.html">Pytorch documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f690866b373" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 different tensor functions from PyTorch library for a deep learning journey]]></title>
            <link>https://medium.com/@alitbk/5-different-tensor-functions-from-pytorch-library-for-a-deep-learning-journey-7c7881a342a6?source=rss-e1ade2619a87------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c7881a342a6</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Ali]]></dc:creator>
            <pubDate>Fri, 05 Jun 2020 00:30:26 GMT</pubDate>
            <atom:updated>2020-07-27T17:58:05.350Z</atom:updated>
            <content:encoded><![CDATA[<h3>5 different tensor functions from the PyTorch library for a deep learning journey</h3><p>This very first blog post of mine on this platform is about tensor functions in <a href="https://pytorch.org/">PyTorch </a>which is an open-source deep learning and neural networks library and here I am going to present, briefly, 5 different tensor functions from PyTorch library. With this regard I would like to also express my sincere thanks to <a href="https://medium.com/u/ca6fe690e934">Aakash N S</a> and <a href="https://jovian.ml/">Jovian.ml</a> team for their encouragements, since this blog post is written in relation to their 6 week online certification course named “Deep Learning with PyTorch: Zero to GANs”.</p><h3>Torch.cat(tensors, dim=0, out=None) → Tensor</h3><p><em>Torch.cat() </em>function is used in order to concatenate same shaped tensors. For more detailed information please see the documentation: <a href="https://jovian.ml/outlink?url=https%3A%2F%2Fpytorch.org%2Fdocs%2Fstable%2Ftorch.html%23torch.cat">https://pytorch.org/docs/stable/torch.html#torch.cat</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D3&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D3&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b31076989f1e8f64ca615f085be711e/href">https://medium.com/media/6b31076989f1e8f64ca615f085be711e/href</a></iframe><p>Here 2 random tensors are created with the help of torch.randn() function and stored under the variable name t1 and t2. Afterwards they are concatenated with each other over the dimension 1.</p><p>Note: I presume that dimension idea might be quite confusing at the very begining. Therefore I would like to briefly touch to that point. For that I would like to mention number of sources which improved both my appraoch and my understanding. As follows:</p><p>1- The explanation of <a href="https://medium.com/u/ca6fe690e934">Aakash N S</a> during the <a href="https://www.youtube.com/watch?v=vo_fUOk-IKk">online-lecture</a> that the dimensions show the number of elements starting from the outermost bracket to the direction of innermost bracket, so to say, dim = 0 in the above tensors shows the number of row vectors after the outermost bracket which is 3 and dim=1 shows the number of elements, which are 2, in the subset brackets.</p><p>2- The two separate blog posts from <a href="https://medium.com/u/897ba0e94236">Boyan Barakov</a> and <a href="https://medium.com/u/1d8994ad0efc">Aerin Kim 🙏</a>. <a href="https://medium.com/@aerinykim/numpy-sum-axis-intuition-6eb94926a5d1">Aerin</a> explains about axis operations in NumPy and how the <em>“specified axis collapses”</em> in a given array over a given axis once those axis is defined as an argument, and <a href="https://towardsdatascience.com/understanding-dimensions-in-pytorch-6edf9972d3be">Boyan</a> points out the similarity between axis in NumPy and dimensions in PyTorch and explains further.</p><p>Consequently, when we look at the output above in combination with the information from references in those 2 points, I hope it helps to understand how the number of elements over the dimension 1 changes after torch.cat() function.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D6&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D6&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9b33bef529475d4c108de0c13d6e9dd/href">https://medium.com/media/c9b33bef529475d4c108de0c13d6e9dd/href</a></iframe><p>Here in line with the example above 2 random tensors, “t1” and “t2”, are created and concatenated with each other over the dimension 0.</p><h3>Torch.narrow(input, dim, start, length) → Tensor</h3><p><em>Torch.narrow() </em>function reduces the given initial tensor to a given dimension. For more detailed information please see the documentation: <a href="https://jovian.ml/outlink?url=https%3A%2F%2Fpytorch.org%2Fdocs%2Fstable%2Ftorch.html%23torch.narrow">https://pytorch.org/docs/stable/torch.html#torch.narrow</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D12&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D12&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/83c81848a421e3091f1d1f237fed560c/href">https://medium.com/media/83c81848a421e3091f1d1f237fed560c/href</a></iframe><p>The tensor “t” is reduced over the dimension 1 after it is randomly created. Basically parameters are input=t is the input tensor, dim=1 is the dimension over which the tensor is reduced, start=2 shows where it starts and length=2 shows after how many steps it will end, including the starting point.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D16&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D16&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8c3ac0c9a7a96265be28934c5d7aedd/href">https://medium.com/media/a8c3ac0c9a7a96265be28934c5d7aedd/href</a></iframe><p>Here a breaking example of this function is represented and we see a <em>RuntimeError</em>, it might be easy to imagine when we think it as a 4x4 matrix and so we have in total 4 columns. At the time when we define starting parameter as 2, we have only 2 columns left which are 3rd and 4th columns. Therefore we cannot use the ending dimension as 3 because it is beyond the available dimension size at that point.</p><h3>Torch.where(condition, x, y) → Tensor</h3><p><em>Torch.where()</em> function allows us to set conditions on tensors. As an output we will get a tensor, depending on the defined condition, which might be a combination of initial tensors. For more detailed information please see the documentation: <a href="https://jovian.ml/outlink?url=https%3A%2F%2Fpytorch.org%2Fdocs%2Fstable%2Ftorch.html%23torch.where">https://pytorch.org/docs/stable/torch.html#torch.where</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D20&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D20&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0e27cda3fa94d54183c17cc0fc4d542/href">https://medium.com/media/c0e27cda3fa94d54183c17cc0fc4d542/href</a></iframe><p>t1 is a randomly created tensor, t2 is a tensor with 0 values. And all the values which are negative in t1 are replaced with zeros from t2.</p><p>Below is another example which returns a <em>RuntimeError</em>, because in order to be apply this <em>torch.where()</em> function, tensors must have the same shape.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D24&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D24&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ebf1f05c19ea4200bb74b016edf5da1/href">https://medium.com/media/7ebf1f05c19ea4200bb74b016edf5da1/href</a></iframe><h3>Torch.eq(input, other, out=None) → Tensor</h3><p><em>Torch.eq() </em>function controls the equality of the elements in different tensors. For more detailed information please see the documentation: <a href="https://jovian.ml/outlink?url=https%3A%2F%2Fpytorch.org%2Fdocs%2Fstable%2Ftorch.html%23torch.eq">https://pytorch.org/docs/stable/torch.html#torch.eq</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D28&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D28&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec24674bcca20bf20242f6f750961bc0/href">https://medium.com/media/ec24674bcca20bf20242f6f750961bc0/href</a></iframe><p>2 same tensors are created and the function checks the equality of elements with each other and returns the Boolean tensor where all the elements are True.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D30&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D30&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f79d9d1bc1fa6b3819e137719c940df/href">https://medium.com/media/3f79d9d1bc1fa6b3819e137719c940df/href</a></iframe><p>2 different random tensors are created and their elements are compared. As a return we have a Boolean tensor where all the elements are False.</p><h3>Torch.mul(input, other, out=None)</h3><p>With <em>torch.mul()</em> function we can multiply a tensor either with a scalar or element-wise with another tensor. For more detailed information please see the documentation: <a href="https://jovian.ml/outlink?url=https%3A%2F%2Fpytorch.org%2Fdocs%2Fstable%2Ftorch.html%23torch.mul">https://pytorch.org/docs/stable/torch.html#torch.mul</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D36&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F40%26cellId%3D36&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/befd32c2174dbf17ff6c22b712c89216/href">https://medium.com/media/befd32c2174dbf17ff6c22b712c89216/href</a></iframe><p>As we can see above initially a random tensor is created and afterwards multiplied with a scalar.</p><p>Below 3 examples are presented, 2 of them are working and 1 is breaking. They are illustrated in order to show what element-wise multiplication means.</p><p>First: Below two random tensors are created and multiplied with each other (element-wise) where both tensors have the dimensions (3,2).</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F29%26cellId%3D37&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F29%26cellId%3D37&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/23c353df3835914ca20d5731ddc6550f/href">https://medium.com/media/23c353df3835914ca20d5731ddc6550f/href</a></iframe><p>Second: In the following example same operation is conducted however this time tensors have different dimensions (3,1) and (1,3), respectively. As a result we see a tensor which has the dimension (3,3). Here I added this example since I want to refer to this example in the last one when it breaks. Because when we see this example, we might think of it as a matrix multiplication but it is actually not, as we will see that in the last example.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F29%26cellId%3D39&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F29%26cellId%3D39&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/0aac67ecc39def974986ebb33d01f954/href">https://medium.com/media/0aac67ecc39def974986ebb33d01f954/href</a></iframe><p>Last: Here I would like to show that when we create 2 different tensors where they have the dimension (3,2) and (2,3), respectively, the<em> torch.mul() </em>function will return a <em>RuntimeError, </em>in contrast to the what we saw in the previous example<em>. </em>Because, this function does not do a matrix multiplication rather it is an element-wise multiplication of tensor elements, and here dimensions are not suitable for element-wise multiplication.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F29%26cellId%3D41&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Falitabakds%2F01-tensor-operations%2Fv%2F29%26cellId%3D41&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Falitabakds%2Fprofile_images%2F8f059a0696924085b5d608e62e7ba1dd%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/20a6f4f4cb0d5c306cd1a3452099820d/href">https://medium.com/media/20a6f4f4cb0d5c306cd1a3452099820d/href</a></iframe><h3><strong>To Sum Up</strong></h3><p>In this post I tried to represent 5 different tensor functions from the torch library, there are more interesting functions in the library and if you are interested in PyTorch I would strongly suggest you to visit official documentation. The explanations are naive approach of my understanding. I would be more than happy to receive a constructive feedback. Hope the above given explanations will be helpful for you!</p><h3>References</h3><ul><li>Official documentation: <a href="https://pytorch.org/docs/stable/torch.html">https://pytorch.org/docs/stable/torch.html</a></li><li>D<a href="https://www.youtube.com/watch?v=vo_fUOk-IKk">eep Learning with PyTorch: Zero to GANs Online lecture</a> from Jovian.ml, instructor <a href="https://medium.com/u/ca6fe690e934">Aakash N S</a></li><li>Blog post of Aerin Kim: <a href="https://medium.com/@aerinykim/numpy-sum-axis-intuition-6eb94926a5d1">Numpy Sum Axis Intuition</a></li><li>Blog post of Boyan Barakov: <a href="https://towardsdatascience.com/understanding-dimensions-in-pytorch-6edf9972d3be">Understanding dimensions in PyTorch</a></li><li><a href="https://jovian.ml/alitabakds/01-tensor-operations">My Juypter Notebook on Jovian.ml</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c7881a342a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>