{"id":1058,"date":"2020-05-13T20:48:48","date_gmt":"2020-05-13T19:48:48","guid":{"rendered":"http:\/\/www.klaushaller.net\/?page_id=1058"},"modified":"2022-03-26T10:09:26","modified_gmt":"2022-03-26T09:09:26","slug":"tutorial-first-steps-in-image-classification-using-python-jupyter-notebook-and-gluon-cv-on-aws-sagemaker","status":"publish","type":"page","link":"https:\/\/www.klaushaller.net\/?page_id=1058","title":{"rendered":"Tutorial: First Steps in Image Classification using Python, Jupyter Notebook and   Gluon-CV on AWS SageMaker"},"content":{"rendered":"\n<p class=\"has-text-align-center\"><em>Klaus Haller, 13.5.2020<\/em><\/p>\n\n\n\n<p class=\"has-text-align-center\">Click <a rel=\"noreferrer noopener\" href=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/Tutorial-Klaus-Haller-SageMaker-Python-Gluon-CV-Computer-Vision.pdf\" target=\"_blank\">here <\/a>to download the tutorial as a pdf file &#8211; or scroll down to read it online&#8230;<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><a>1.&nbsp;&nbsp;&nbsp; Aim of this Computer Vision Introduction Tutorial<\/a><\/h1>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignright size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-13.png\" alt=\"\" class=\"wp-image-1091\" width=\"329\" height=\"395\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-13.png 657w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-13-249x300.png 249w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-13-624x750.png 624w\" sizes=\"auto, (max-width: 329px) 100vw, 329px\" \/><\/figure><\/div>\n\n\n\n<p>Deep Learning, Analytics, Computer Vision \u2013 these are some of today\u2019s hot topics in the IT industry. These are key technologies for innovation. Universities and big tech companies put high efforts in research and engineering in these areas. However, even individual developers can enrich their applications with such artificial intelligence and computer vision technology if they on existing technologies, tools, and libraries.<\/p>\n\n\n\n<p>This short tutorial explains you one way to achieve this. We use Python and Jupyter Notebook running on Amazon SageMaker to \u201cimplement\u201d image classification based on available, pretrained neural networks within one to two hours. In other words: You will learn that you do not need any research, no Ph.D., and not two years and a big team to incorporate such features in your applications.<\/p>\n\n\n\n<p>The first half of the tutorial is about navigating the AWS web console, whereas the second part covers the code to get your first images classified.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><a>2.&nbsp;&nbsp;&nbsp; Amazon SageMaker \/ Amazon Sage Maker Studio<\/a><\/h1>\n\n\n\n<p>SageMaker is Amazon&#8217;s solution for machine learning. It comes with one big benefit if you start learning computer vision with SageMaker: You do not have to do any installations on your local laptop. When you have your AWS login, it takes you less than five minutes and you can start with development work. And it is free, at least for the first two months and if you use it moderately, i.e., you stay away from expensive AMIs or extra options.<\/p>\n\n\n\n<p><em><span class=\"has-inline-color has-blue-color\">To continue, you need an AWS account and you have to be signed in to your AWS account. Alternatively, you have to have a local Jupyter Notebook installation on your computer. In this case, you can continue with section 3 \u201cUnderstanding Juypter Notebook\u201d.<\/span><\/em><\/p>\n\n\n\n<p>xxWhen you are signed in to your AWS account and you are in the AWS services page, you type in \u201cSageMaker\u201d and select and click on the service.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik.png\" alt=\"\" class=\"wp-image-1064\" width=\"596\" height=\"285\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik.png 596w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-300x143.png 300w\" sizes=\"auto, (max-width: 596px) 100vw, 596px\" \/><\/figure>\n\n\n\n<p>Then, you click on \u201cAmazon SageMaker Studio\u201d, which is Amazon\u2019s development environment.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/AmazonSageMakerIntro.png\" alt=\"\" class=\"wp-image-1067\" width=\"588\" height=\"213\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/AmazonSageMakerIntro.png 588w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/AmazonSageMakerIntro-300x109.png 300w\" sizes=\"auto, (max-width: 588px) 100vw, 588px\" \/><\/figure>\n\n\n\n<p>Next, you create a new user for SageMaker Studio. Therefore, click on \u201cAdd user\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/SageMakerAddUser.png\" alt=\"\" class=\"wp-image-1068\" width=\"595\" height=\"138\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/SageMakerAddUser.png 595w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/SageMakerAddUser-300x70.png 300w\" sizes=\"auto, (max-width: 595px) 100vw, 595px\" \/><\/figure>\n\n\n\n<p>Select \u201cQuick start, add a user name, and select \u201cCreate new role\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"598\" height=\"335\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/SageMakerQuickStart.png\" alt=\"\" class=\"wp-image-1069\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/SageMakerQuickStart.png 598w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/SageMakerQuickStart-300x168.png 300w\" sizes=\"auto, (max-width: 598px) 100vw, 598px\" \/><\/figure>\n\n\n\n<p>A mask shows up for creating an IAM role. If you are in a test environment, just accept by clicking on \u201cCreate Role\u201d.<\/p>\n\n\n\n<p>Now you can create the SageMakerStudio environment by clicking on \u201cSubmit\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"598\" height=\"221\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/QuickStartSubmit.png\" alt=\"\" class=\"wp-image-1070\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/QuickStartSubmit.png 598w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/QuickStartSubmit-300x111.png 300w\" sizes=\"auto, (max-width: 598px) 100vw, 598px\" \/><\/figure>\n\n\n\n<p><em><span class=\"has-inline-color has-blue-color\">A couple of times, I had issues with the submit button. I could click it, but there was no reaction. In such a case, you are most probably a person with some experience using AWS. You might want to choose the \u201cstandard setup\u201d option and choose an existing VPC or subnet.<\/span><\/em><\/p>\n\n\n\n<p>A little bit later (it might take a while), you see the following page and you can select \u201cOpen Studio\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"608\" height=\"233\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-1.png\" alt=\"\" class=\"wp-image-1071\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-1.png 608w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-1-300x115.png 300w\" sizes=\"auto, (max-width: 608px) 100vw, 608px\" \/><\/figure>\n\n\n\n<p>Now, click the \u201cCreate a notebook\u201d button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"573\" height=\"267\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-2.png\" alt=\"\" class=\"wp-image-1072\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-2.png 573w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-2-300x140.png 300w\" sizes=\"auto, (max-width: 573px) 100vw, 573px\" \/><\/figure>\n\n\n\n<p>You get to the following screen:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"577\" height=\"200\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-3.png\" alt=\"\" class=\"wp-image-1073\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-3.png 577w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-3-300x104.png 300w\" sizes=\"auto, (max-width: 577px) 100vw, 577px\" \/><\/figure>\n\n\n\n<p>Congratulations. You are now ready to go! The next section will give you a brief introduction in Juypter Notebook and how to use it as a development environment.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><a>3.&nbsp;&nbsp;&nbsp; Understanding Juypter Notebook<\/a><\/h1>\n\n\n\n<p>Jupyter Notebook is a development environment used by many data scientists. Compared to your typical Java Eclipse IDE, there are important differences:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>You work interactively like you might know it from interpreted languages. You write some lines of code to download data, query your data, or to train a machine learning model \u2013 and you see the result immediately.<\/li><li>Jupyter Notebook is like a paper notebook when it comes to documenting. You write down the code and add comments to it immediately. In contrast to commenting your code in Java, you can make it look nicer, it feels more natural, and it really helps that you work interactively. You write what you want to achieve as a comment, then you write the code. Then you continue with the next comment, followed by code again.<\/li><\/ul>\n\n\n\n<p>Figure 1 provides an example, a screenshot showing part of the code of this tutorial. The screenshot shows the second step where we download the images from the web and store them in an array for later processing. On the top, we see a cell with comments or text. This is called \u201cmarkdown\u201d. It is followed by a cell with actual code. We define variables, then download the images in a for-loop, and write to the console that we are finished. Down there, we see the output that was written to the console when we executed the code cell.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"616\" height=\"347\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-5.png\" alt=\"\" class=\"wp-image-1075\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-5.png 616w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-5-300x169.png 300w\" sizes=\"auto, (max-width: 616px) 100vw, 616px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\"><a>4.&nbsp;&nbsp;&nbsp; Implementing Image Classification in Python<\/a><\/h1>\n\n\n\n<p>It is straight forward to implement an image classification using Python. We do not need our own training data and we do not have to train a neural network. We just use existing models available for download from the web. You can either copy &amp; paste the input for the cells from the tutorial or type the code in by yourself.<\/p>\n\n\n\n<p>Input the following to the cell on the Juypter Notebook.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>**\n** This script demonstrates image classification using Python 3 and Gluon-CV.\n** (c) Klaus Haller, 13.5.2020\n**<\/code><\/pre>\n\n\n\n<p>Then, change the cell type from \u201cCode\u201d to \u201cRaw\u201d &nbsp;\u2026<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"288\" height=\"104\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-6.png\" alt=\"\" class=\"wp-image-1076\"\/><\/figure>\n\n\n\n<p>\u2026 and press Shit+Return.<\/p>\n\n\n\n<p>We are ready for the the first step. We begin with a comment:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Step 1: Load the libraries<\/code><\/pre>\n\n\n\n<p>Change the cell type to \u201cMarkdown\u201d and press Shift+Return.<\/p>\n\n\n\n<p>We have to download and install some libraries:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install mxnet gluoncv matplotlib<\/code><\/pre>\n\n\n\n<p>Once you press Shift+Return, you see an output similar to the following (it might look different if you run it the first time):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Requirement already satisfied: mxnet in \/opt\/conda\/lib\/python3.7\/site-packages (1.6.0)\nRequirement already satisfied: gluoncv in \/opt\/conda\/lib\/python3.7\/site-packages (0.7.0)\nRequirement already satisfied: matplotlib in \/opt\/conda\/lib\/python3.7\/site-packages (3.1.3)\nRequirement already satisfied: numpy&lt;2.0.0,&gt;1.16.0 in \/opt\/conda\/lib\/python3.7\/site-packages (from mxnet) (1.18.1)\n&#91;\u2026]\nRequirement already satisfied: setuptools in \/opt\/conda\/lib\/python3.7\/site-packages (from kiwisolver&gt;=1.0.1-&gt;matplotlib) (45.2.0.post20200210)\nNote: you may need to restart the kernel to use updated packages.<\/code><\/pre>\n\n\n\n<p>Now, we import the libraries to our notebook:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import mxnet as mx\nimport gluoncv as gcv\nimport matplotlib.pyplot as plt<\/code><\/pre>\n\n\n\n<p>As for all other code cells, we have to press Shift+Return to execute the commands (in the following, I will not mention this again).<\/p>\n\n\n\n<p>Aim of the next step, the second step, is to download the pictures we are using and loading them to an array. We write the following short text in a markdown cell:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Step 2: Download some images from the web and store them in an array.<\/code><\/pre>\n\n\n\n<p>We continue with the actual code we want to execute:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>image1_url = 'http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/klaushaller_demopicture_01.jpg'\nimage2_url = 'http:\/\/www.klaushaller.net\/wp-content\/uploads\/2017\/11\/20130510_200219-1c.jpg'\nimage3_url = 'http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/klaushaller_demopicture_00-1.jpg'\nimage4_url = 'http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/klaushaller_demopicture_03.jpg'\nimage5_url = 'http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/klaushaller_demopicture_04.jpg'\n\nimages_url= &#91;image1_url, image2_url, image3_url, image4_url, image5_url]\n\nimages=&#91;]\n\nfor i in range(len(images_url)):\n    gcv.utils.download(url=images_url&#91;i], path='imagedownload0'+str(i)) \n    images.append(mx.image.imread('imagedownload0'+str(i))) \nprint('Image download completed.')\n<\/code><\/pre>\n\n\n\n<p>You can verify whether everything worked perfect by submitting the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>plt.imshow(images&#91;0].asnumpy())<\/code><\/pre>\n\n\n\n<p>You should see a yellow boat on the sea with a small beach and forest in the background.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"598\" height=\"403\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-7.png\" alt=\"\" class=\"wp-image-1077\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-7.png 598w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-7-300x202.png 300w\" sizes=\"auto, (max-width: 598px) 100vw, 598px\" \/><\/figure>\n\n\n\n<p>Step 3 is about preparing the images so that they can be classified (dealing with different sizes, brightness etc.). We start again with a markdown cell documenting what we do:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Step 3: Prepare the images for object identification<\/code><\/pre>\n\n\n\n<p>The actual code follows here:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>images_prepared=&#91;]\nfor i in range(len(images)):\n  images_prepared.append(gcv.data.transforms.presets.imagenet.transform_eval(images&#91;i]))<\/code><\/pre>\n\n\n\n<p>In the following 4<sup>th<\/sup> step, we install a pretrained neural network. This means, it is a neural for which all training is completed. It is ready to classify our sample pictures.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Step 4: Initialize pretrained neural and classify images<\/code><\/pre>\n\n\n\n<p>The code for step 4:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pretrainedNN = gcv.model_zoo.get_model('densenet201', pretrained=True)\ntop3classes=&#91;]\nfor i in range(len(images_prepared)):\n    top3classes.append(mx.nd.topk(mx.nd.softmax(pretrainedNN(images_prepared&#91;i])), k=3)&#91;0])<\/code><\/pre>\n\n\n\n<p>The following code shows the images and the three most likely classifications for the image. To prevent misunderstandings: The neural network classifies (hopefully) the most dominant object on the image, though looking at the second or third most likely class can be an indication what else is on the picture.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print('Picture 1')\nplt.imshow(images&#91;0].asnumpy())\nfor i in range(3):\n    index=top3classes&#91;0]&#91;i].astype('int').asscalar()\n    label=pretrainedNN.classes&#91;index]\n    print('#',i+1, 'Detected object: ', label)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"383\" height=\"327\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-8.png\" alt=\"\" class=\"wp-image-1078\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-8.png 383w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-8-300x256.png 300w\" sizes=\"auto, (max-width: 383px) 100vw, 383px\" \/><\/figure>\n\n\n\n<p>Obviously, the first classification is perfect.<\/p>\n\n\n\n<p>Now we have a look at the second image and how it is classified by the neural network:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print('Picture 2')\nplt.imshow(images&#91;1].asnumpy())\nfor i in range(3):\n    index=top3classes&#91;1]&#91;i].astype('int').asscalar()\n    label=pretrainedNN.classes&#91;index]\n    print('#',i+1, 'Detected object: ',label)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"319\" height=\"282\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-9.png\" alt=\"\" class=\"wp-image-1079\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-9.png 319w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-9-300x265.png 300w\" sizes=\"auto, (max-width: 319px) 100vw, 319px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>print('Picture 3')\nplt.imshow(images&#91;2].asnumpy())\nfor i in range(3):\n    index=top3classes&#91;2]&#91;i].astype('int').asscalar()\n    label=pretrainedNN.classes&#91;index]\n    print('#',i+1, 'Detected object: ',label)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"304\" height=\"314\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-10.png\" alt=\"\" class=\"wp-image-1080\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-10.png 304w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-10-290x300.png 290w\" sizes=\"auto, (max-width: 304px) 100vw, 304px\" \/><\/figure>\n\n\n\n<p>This picture does not have one dominant object, but various ones \u2013 the Matterhorn mountain in the Alpes, some trees in the middle, and a lake in the foreground. Again, the suggested classes \u2013 at least alp and lakeside \u2013 make sense.<\/p>\n\n\n\n<p>Now the fourth picture.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print('Picture 4')\nplt.imshow(images&#91;3].asnumpy())\nfor i in range(3):\n    index=top3classes&#91;3]&#91;i].astype('int').asscalar()\n    label=pretrainedNN.classes&#91;index]\n    print('#',i+1, 'Detected object: ',label)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"282\" height=\"391\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-11.png\" alt=\"\" class=\"wp-image-1081\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-11.png 282w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-11-216x300.png 216w\" sizes=\"auto, (max-width: 282px) 100vw, 282px\" \/><\/figure>\n\n\n\n<p>This picture contains a bottle of sparkling wine and a champagne flute as larger objects, plus a table, a plastic chair, and a tree in the background. Again, the algorithm works well with suggesting a wine bottle. The alternative, beer bottle, is also not bad.<\/p>\n\n\n\n<p>The neural network has the goal to classify the image, aka the main object, correctly. It does not aim to identify the second or third most important or biggest object on the image. Also, the exact objects \u2013 sparkling wine bottle and champagne flute \u2013 were not trained. Thus, the neural network cannot identify them as such.<\/p>\n\n\n\n<p>The last picture is one with me.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print('Picture 5')\nplt.imshow(images&#91;4].asnumpy())\nfor i in range(3):\n    index=top3classes&#91;4]&#91;i].astype('int').asscalar()\n    label=pretrainedNN.classes&#91;index]\n    print('#',i+1, 'Detected object: ',label)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"485\" height=\"349\" src=\"http:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-12.png\" alt=\"\" class=\"wp-image-1082\" srcset=\"https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-12.png 485w, https:\/\/www.klaushaller.net\/wp-content\/uploads\/2020\/05\/grafik-12-300x216.png 300w\" sizes=\"auto, (max-width: 485px) 100vw, 485px\" \/><\/figure>\n\n\n\n<p>Obviously, this pretrained neural network does not identify a human plus some illustration in the background well. However, that is nothing the neural network was trained for \u2013 and this is to make you aware that pretrained neural networks have also their limitations and cannot solve everything.<\/p>\n\n\n\n<p>To conclude: It takes an hour or two to classify pictures using pretrained neural network. This has implications for projects in companies. It makes no sense to start a project with checking for existing pretrained neural networks before embarking in time-intense software engineering and neural network endeavors. The pretrained models do not beat a human, but in many cases, they might be enough to start your journey of using images to generate new knowledge and new insights for your company.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Klaus Haller, 13.5.2020 Click here to download the tutorial as a pdf file &#8211; or scroll down to read it online&#8230; 1.&nbsp;&nbsp;&nbsp; Aim of this Computer Vision Introduction Tutorial Deep Learning, Analytics, Computer Vision \u2013 these are some of today\u2019s hot topics in the IT industry. These are key technologies for innovation. Universities and big [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":843,"menu_order":5000,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1058","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.klaushaller.net\/index.php?rest_route=\/wp\/v2\/pages\/1058","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.klaushaller.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.klaushaller.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.klaushaller.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.klaushaller.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1058"}],"version-history":[{"count":11,"href":"https:\/\/www.klaushaller.net\/index.php?rest_route=\/wp\/v2\/pages\/1058\/revisions"}],"predecessor-version":[{"id":1244,"href":"https:\/\/www.klaushaller.net\/index.php?rest_route=\/wp\/v2\/pages\/1058\/revisions\/1244"}],"up":[{"embeddable":true,"href":"https:\/\/www.klaushaller.net\/index.php?rest_route=\/wp\/v2\/pages\/843"}],"wp:attachment":[{"href":"https:\/\/www.klaushaller.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1058"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}