{"id":16943,"date":"2020-09-10T05:19:00","date_gmt":"2020-09-09T23:49:00","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/"},"modified":"2024-10-15T00:22:56","modified_gmt":"2024-10-14T18:52:56","slug":"object-detection-in-pytorch","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/","title":{"rendered":"Object Detection in Pytorch | What is Object Detection?"},"content":{"rendered":"\n<ol class=\"wp-block-list\">\n<li><strong><a href=\"#objectdetection\">What is object detection?<\/a><\/strong><\/li>\n\n\n\n<li><strong><a href=\"#objectclassification\">How is object detection different from object classification?<\/a><\/strong><\/li>\n\n\n\n<li><strong><a href=\"#typesofobjectdetection\">Types of object detection algorithms<\/a><\/strong><\/li>\n\n\n\n<li><strong><a href=\"#objectdetectionusingpytorch\">Code for object detection using PyTorch<\/a><\/strong><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-object-detection\"><strong>What is object detection?<\/strong><\/h2>\n\n\n\n<p>Object detection is a <a href=\"https:\/\/www.mygreatlearning.com\/blog\/what-is-computer-vision-the-basics\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"computer vision technique (opens in a new tab)\">computer vision technique<\/a> in which a software system can detect, locate, and trace the object from a given image or video. The special attribute about object detection is that it identifies the class of object (person, table, chair, etc.) and their location-specific coordinates in the given image. The location is pointed out by drawing a bounding box around the object. The bounding box may or may not accurately locate the position of the object. The ability to locate the object inside an image defines the performance of the algorithm used for detection.<\/p>\n\n\n\n<p>These object detection algorithms might be pre-trained or can be trained from scratch. In most use cases, we use pre-trained weights from pre-trained models and then <a href=\"https:\/\/www.mygreatlearning.com\/blog\/what-is-fine-tuning\/\">fine-tune<\/a> them as per our requirements and different use cases.<\/p>\n\n\n\n<p>Labeled data is of paramount importance in these tasks, and every algorithm when put into practice requires a lot of well-labeled data. The algorithms require data of varying nature to function correctly, and this can be done easily by either collecting a lot more samples of data or augmenting the available data in some form.<\/p>\n\n\n\n<p>Data Augmentation is required in such cases when we have particularly limited access to labeled data. Hence, by data augmentation, we create images that are effectively containing the same image but their interpretation is done differently by the algorithms. For instance, let's discuss a particular use case.<\/p>\n\n\n\n<p>Let\u2019s say we are given the task of detecting and classifying different types of fruits. Now the task is to detect both the type of fruit present and to also find the precise coordinates of the fruit in the image. But we have a problem. For training, we have 250 images containing bananas. For apples and oranges, we have only 120 images. This dataset imbalance can be dealt with by Data Augmentation. We can create superficial images by just distorting the existing images. The distortions can be in the form of rotation of images, such that the point of view of the objects in the picture changes. We can try different angles of rotation for the creation of new images. Similarly, we play with the lighting conditions, sharpness, or can even displace the images either vertically or horizontally to create images that will be digitally different from the existing image.<\/p>\n\n\n\n<p>Also Read: <a href=\"https:\/\/www.mygreatlearning.com\/blog\/what-is-computer-vision-the-basics\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Computer Vision: Deep Learning Approach  (opens in a new tab)\">Computer Vision: Deep Learning Approach <\/a><\/p>\n\n\n\n<p>Now let us see a simple program for object detection using python. The code is very simple if you ignore the underlying architecture.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import cv2\nimport matplotlib.pyplot as plt\nimport cvlib\nfrom cvlib.object_detection import draw_bbox\nim  =  cv2.imread ('Vegetable - market.jpg')\nbbox , label , conf  =  cvlib.detect_common_objects(im)\noutput_image = draw_bbox (im , bbox , label , conf)\nplt.imshow (output_image)\nplt.show()<\/code><\/pre>\n\n\n\n<p>Here cvlib is the library that has an object detection function for common objects. The model is trained to detect a variety of common objects like fruits, people, cars, etc.<\/p>\n\n\n\n<p>Every detected object can be seen in the resulting image with a bounding box around it. This a picture of a vegetable market we picked up randomly from the internet. You can experiment with your own image. Just change the name of the image in the given code and you are good to go.&nbsp;<\/p>\n\n\n\n<p>Another simple use case of object detection is face detection. Face detection is a specialized case of object detection in images or videos which is a collection of images in sequence. In a general object detection algorithm, the task is to identify a particular class of objects whether it be dogs, cats, trees, fruit cars, etc.<\/p>\n\n\n\n<p>In face detection, we have a database of images with faces and the aspect ratio of various distances. Facial feature data is stored in the database.<\/p>\n\n\n\n<p>When a new object comes in, its features are compared to that of faces stored in the database. Any feature mismatch disqualifies the image as a face. If all features are matched then a bounding box is drawn around the detected face.<\/p>\n\n\n\n<p>We would be using the same concept in which we will store all the attributes of a face in XML file. We would read each frame of our webcam and then, if a face is found in the particular frame we will draw a bounding box around the face.<\/p>\n\n\n\n<p>Also Read: Datasets for Computer Vision using Deep Learning <\/p>\n\n\n\n<p>For this we will require the <strong>OpenCV module and harrcascade_default.xml<\/strong><\/p>\n\n\n\n<p>We begin with <strong>importing the cv2 module<\/strong>. If you have not already installed it, you can do so by doing the following.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>!pip install opencv-python\nimport cv2<\/code><\/pre>\n\n\n\n<p>We then load the XML file which has all data about the facial features.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Load the cascade\nface_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')<\/code><\/pre>\n\n\n\n<p>We then start capturing the video using object detection. &nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># To capture video from a webcam. \ncap = cv2.VideoCapture(0)\n# To use a video file as input \n# cap = cv2.VideoCapture('filename.mp4')<\/code><\/pre>\n\n\n\n<p>Until we press escape the webcam will be functional. We read each frame and then convert that frame to a grayscale image.<\/p>\n\n\n\n<p>while True:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Read the frame\n_, img = cap.read()\n# Convert to grayscale\ngray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)<\/code><\/pre>\n\n\n\n<p>We then call the detectMultiScale function of OpenCV to detect faces in the frame. It detects multiple faces so if you hold a mobile phone with faces in it in front of the webcam it detects them as well.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Detect the faces\nfaces = face_cascade.detectMultiScale(gray, 1.1, 4)\n# Draw the rectangle around each face\nfor (x, y, w, h) in faces:\ncv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)\n# Display\ncv2.imshow('img', img)\n# Stop if escape key is pressed\nk = cv2.waitKey(30) &amp; 0xff\nif k==27:\nbreak\n# Release the VideoCapture object\ncap.release()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-is-object-detection-different-from-object-classification\"><strong>How is object detection different from object classification?<\/strong><\/h2>\n\n\n\n<p>Object classification is a traditional computer vision task that is effectively determining the class of the object in an image. Object classification finds out what the object in a given picture or video is. There is a probability score associated with the results so that we can get the confidence scores of the results.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Computer Vision with CNN ( Convolutional Neural Networks ) | Deep Learning | Great Learning\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/AcQW0C8PCpw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>Let\u2019s perform object detection on the mnist dataset and fashion mnist data sets to give you more clarity on the topic.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import tensorflow as tf\nmnist = tf.keras.datasets.mnist\n(x_train, y_train), (x_test, y_test) = mnist.load_data()\nx_train, x_test = x_train \/ 255.0, x_test \/ 255.0\nmodel = tf.keras.models.Sequential(&#91;\ntf.keras.layers.Flatten(input_shape=(28, 28)),\ntf.keras.layers.Dense(128, activation='relu'),\ntf.keras.layers.Dropout(0.2),\ntf.keras.layers.Dense(10)\n])\npredictions = model(x_train&#91;:1]).numpy()\npredictions\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"output\"><strong>Output:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>array(&#91;&#91;-0.63204   ,  0.29606453,  0.24910979,  0.28201205, -0.17138952,\n0.3396452 ,  0.37800127, -0.9318958 ,  0.0439647 , -0.0467336 ]],\ndtype=float32)\n\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>tf.nn.softmax(predictions).numpy()\n\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"output\"><strong>Output:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>array(&#91;&#91;0.05021724, 0.12703504, 0.12120801, 0.12526236, 0.07959959,\n0.13269372, 0.1378822 , 0.03720722, 0.09872746, 0.09016712]],\ndtype=float32)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\nloss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)\nloss_fn(y_train&#91;:1], predictions).numpy()\nmodel.compile(optimizer='adam',\n         loss=loss_fn,\n         metrics=&#91;'accuracy'])\nmodel.fit(x_train, y_train, epochs=20)\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"ouput\"><strong>Ouput:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>Epoch 1\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0672 - accuracy: 0.9791\nEpoch 2\/20\n1875\/1875 &#91;==============================] - 3s 2ms\/step - loss: 0.0580 - accuracy: 0.9811\nEpoch 3\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0537 - accuracy: 0.9829\nEpoch 4\/20\n1875\/1875 &#91;==============================] - 3s 2ms\/step - loss: 0.0472 - accuracy: 0.9851\nEpoch 5\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0446 - accuracy: 0.9855\nEpoch 6\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0399 - accuracy: 0.9870\nEpoch 7\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0403 - accuracy: 0.9857\nEpoch 8\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0351 - accuracy: 0.9885\nEpoch 9\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0343 - accuracy: 0.9886\nEpoch 10\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0347 - accuracy: 0.9880\nEpoch 11\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0296 - accuracy: 0.9901\nEpoch 12\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0285 - accuracy: 0.9901\nEpoch 13\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0288 - accuracy: 0.9902\nEpoch 14\/20\n1875\/1875 &#91;==============================] - 3s 2ms\/step - loss: 0.0268 - accuracy: 0.9908\nEpoch 15\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0277 - accuracy: 0.9901\nEpoch 16\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0228 - accuracy: 0.9919\nEpoch 17\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0236 - accuracy: 0.9918\nEpoch 18\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0233 - accuracy: 0.9920\nEpoch 19\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0230 - accuracy: 0.9920\nEpoch 20\/20\n1875\/1875 &#91;==============================] - 4s 2ms\/step - loss: 0.0227 - accuracy: 0.9919\n&lt;tensorflow.python.keras.callbacks.History at 0x7fa0f06cd390&gt;\n\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>model.evaluate(x_test,  y_test, verbose=2)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"output\">Output:<\/h2>\n\n\n\n<p>313\/313 - 0s - loss: 0.0765 - accuracy: 0.9762<br>\n[0.07645969837903976, 0.9761999845504761]<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>probability_model = tf.keras.Sequential(&#91;\nmodel,\ntf.keras.layers.Softmax()\n])\nprobability_model(x_test&#91;:5])\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"ouput\"><strong>Ouput:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;tf.Tensor: shape=(5, 10), dtype=float32, numpy=\narray(&#91;&#91;3.9212882e-12, 2.1834714e-19, 1.9253871e-10, 2.2876110e-07,\n9.0482010e-19, 1.1011923e-11, 2.5250806e-23, 9.9999976e-01,\n1.7883041e-12, 1.3832281e-09],\n&#91;1.4191020e-17, 1.3323700e-10, 1.0000000e+00, 7.2097401e-16,\n6.5754260e-37, 2.3290989e-16, 8.8370928e-17, 1.0187791e-29,\n2.0311796e-18, 0.0000000e+00],\n&#91;7.0981394e-17, 9.9999857e-01, 5.5766418e-07, 7.3810041e-11,\n4.1638457e-09, 5.4865166e-12, 1.6843820e-12, 7.9530673e-07,\n2.9518892e-08, 2.5004247e-15],\n&#91;9.9999964e-01, 6.0739493e-21, 1.9297003e-07, 4.0246032e-13,\n1.5357564e-12, 2.8772764e-08, 9.8391717e-10, 4.7179654e-08,\n3.7541407e-17, 7.9969936e-10],\n&#91;9.2232035e-14, 2.7456325e-20, 1.8037905e-14, 7.4756340e-18,\n9.9999642e-01, 7.5487475e-15, 6.5344392e-12, 6.5705713e-08,\n7.8566824e-13, 3.4821376e-06]], dtype=float32)&gt;\n<\/code><\/pre>\n\n\n\n<p>In the above example we did a use case on object classification using MNIST.<\/p>\n\n\n\n<p>Let\u2019s see another example, using the fashion mnist dataset.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># TensorFlow and tf.keras\n#based on tensorflow examples from google\nimport tensorflow as tf\nfrom tensorflow import keras\n# Helper libraries\nimport numpy as np\nimport matplotlib.pyplot as plt\nfashion_mnist = keras.datasets.fashion_mnist\n(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()\nclass_names = &#91;\u2018T-shirt\/top\u2019, \u2018Trouser\u2019, \u2018Pullover\u2019, \u2018Dress\u2019, \u2018Coat\u2019,\n        \t\u2018Sandal\u2019, \u2018Shirt\u2019, \u2018Sneaker\u2019, \u2018Bag\u2019, \u2018Ankle boot\u2019]\nplt.figure()\nplt.imshow(train_images&#91;0])\nplt.colorbar()\nplt.grid(False)\nplt.show()\ntrain_images&#91;10]\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"ouput\"><strong>Ouput:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>array(&#91;&#91;0.    , 0.    , 0.    , 0.    , 0.        ,\n \t0.    , 0.    , 0.04313725, 0.55686275, 0.78431373,\n \t0.41568627, 0.    , 0.    , 0.    , 0.    ,\n \t0.    , 0.    , 0.    , 0.33333333, 0.7254902 ,\n \t0.43921569, 0.    , 0.    , 0.    , 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.    ,\n \t0.    , 0.59607843, 0.83921569, 0.85098039, 0.76078431,\n \t0.9254902 , 0.84705882, 0.73333333, 0.58431373, 0.52941176,\n \t0.6   , 0.82745098, 0.85098039, 0.90588235, 0.80392157,\n \t0.85098039, 0.7372549 , 0.13333333, 0.    , 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.    ,\n \t0.25882353, 0.7254902 , 0.65098039, 0.70588235, 0.70980392,\n \t0.74509804, 0.82745098, 0.86666667, 0.77254902, 0.57254902,\n \t0.77647059, 0.80784314, 0.74901961, 0.65882353, 0.74509804,\n \t0.6745098 , 0.7372549 , 0.68627451, 0.    , 0.    ,\n \t0.    , 0.    , 0.    ],\n    &#91;0.    , 0.    , 0.    , 0.    , 0.    ,\n \t0.52941176, 0.6   , 0.62745098, 0.68627451, 0.70588235,\n \t0.66666667, 0.72941176, 0.73333333, 0.74509804, 0.7372549 ,\n \t0.74509804, 0.73333333, 0.68235294, 0.76470588, 0.7254902 ,\n \t0.68235294, 0.63137255, 0.68627451, 0.23137255, 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.    ,\n \t0.63137255, 0.57647059, 0.62745098, 0.66666667, 0.69803922,\n \t0.69411765, 0.70588235, 0.65882353, 0.67843137, 0.68235294,\n \t0.67058824, 0.7254902 , 0.72156863, 0.7254902 , 0.6745098 ,\n \t0.67058824, 0.64313725, 0.68235294, 0.47058824, 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.00784314,\n \t0.68627451, 0.57254902, 0.56862745, 0.65882353, 0.69803922,\n\t0.70980392, 0.7254902 , 0.70588235, 0.72156863, 0.69803922,\n \t0.70196078, 0.73333333, 0.74901961, 0.75686275, 0.74509804,\n \t0.70980392, 0.67058824, 0.6745098 , 0.61960784, 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.     , 0.    , 0.    , 0.   , 0.1372549 ,\n \t0.69411765, 0.60784314, 0.54901961, 0.59215686, 0.6745098 ,\n \t0.74901961, 0.73333333, 0.72941176, 0.73333333, 0.72941176,\n \t0.73333333, 0.71372549, 0.74901961, 0.76078431, 0.7372549 ,\n \t0.70588235, 0.63137255, 0.63137255, 0.7254902 , 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.23137255,\n \t0.66666667, 0.6   , 0.55294118, 0.47058824, 0.60392157,\n    0.62745098, 0.63137255, 0.6745098 , 0.65882353, 0.65098039,\n \t0.63137255, 0.64705882, 0.6745098 , 0.66666667, 0.64313725,\n \t0.54509804, 0.58431373, 0.63529412, 0.65098039, 0.08235294,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.        , 0.    , 0.    , 0.   , 0.30980392,\n \t0.56862745, 0.62745098, 0.83921569, 0.48235294, 0.50196078,\n \t0.6   , 0.62745098, 0.64313725, 0.61960784, 0.61568627,\n \t0.60392157, 0.60784314, 0.66666667, 0.64705882, 0.55294118,\n \t0.76470588, 0.75686275, 0.59607843, 0.65098039, 0.23921569,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.39215686,\n \t0.61568627, 0.88235294, 0.96078431, 0.68627451, 0.44313725,\n \t0.68235294, 0.61960784, 0.61960784, 0.62745098, 0.60784314,\n \t0.62745098, 0.64313725, 0.69803922, 0.7372549 , 0.52941176,\n \t0.7254902 , 0.94117647, 0.78823529, 0.6745098 , 0.42352941,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.        , 0.    ,\n \t0.12156863, 0.68235294, 0.10980392, 0.49411765, 0.6   ,\n \t0.65098039, 0.59607843, 0.61960784, 0.61960784, 0.62745098,\n \t0.63137255, 0.61568627, 0.65882353, 0.74901961, 0.7372549 ,\n \t0.07058824, 0.51764706, 0.62352941, 0.02745098, 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.    ,\n \t0.    , 0.    , 0.    , 0.32156863, 0.73333333,\n \t0.62352941, 0.6   , 0.61568627, 0.61960784, 0.63529412,\n \t0.64313725, 0.64313725, 0.60392157, 0.73333333, 0.74509804,\n \t0.    , 0.    , 0.    , 0.     , 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.        , 0.00392157,\n \t0.01176471, 0.01960784, 0.    , 0.14509804, 0.68627451,\n \t0.61960784, 0.60784314, 0.63529412, 0.61960784, 0.62745098,\n \t0.63529412, 0.64705882, 0.6   , 0.69411765, 0.80392157,\n \t0.    , 0.    , 0.01176471, 0.01176471, 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.    ,\n \t0.    , 0.00392157, 0.    , 0.09803922, 0.68627451,\n \t0.59607843, 0.62745098, 0.61960784, 0.63137255, 0.62745098,\n \t0.64313725, 0.64313725, 0.63137255, 0.65098039, 0.78431373,\n \t0.    , 0.    , 0.00392157, 0.    , 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.    ,\n \t0.    , 0.01568627, 0.    , 0.11764706, 0.67058824,\n\t0.57647059, 0.64313725, 0.60784314, 0.64705882, 0.63137255,\n \t0.64705882, 0.63529412, 0.66666667, 0.64313725, 0.63529412,\n \t0.    , 0.   , 0.00784314, 0.    , 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.     , 0.    , 0.    , 0.    , 0.    ,\n \t0.    , 0.01568627, 0.    , 0.22352941, 0.65098039,\n \t0.60784314, 0.64313725, 0.65098039, 0.63137255, 0.63137255,\n \t0.64313725, 0.65490196, 0.64705882, 0.64705882, 0.63529412,\n \t0.10980392, 0.    , 0.01176471, 0.    , 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.    ,\n \t0.    , 0.01176471, 0.    , 0.44705882, 0.63137255,\n    0.63137255, 0.65098039, 0.62352941, 0.65882353, 0.63137255,\n \t0.63137255, 0.6745098 , 0.63529412, 0.64705882, 0.67058824,\n \t0.19607843, 0.   , 0.01960784, 0.    , 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.        , 0.    , 0.    , 0.    , 0.    ,\n \t0.    , 0.00392157, 0.    , 0.58431373, 0.61568627,\n \t0.65490196, 0.6745098 , 0.62352941, 0.6745098 , 0.64313725,\n \t0.63137255, 0.6745098 , 0.66666667, 0.62745098, 0.67058824,\n \t0.34901961, 0.    , 0.01568627, 0.    , 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.   , 0.    , 0.    ,\n \t0.00784314, 0.    , 0.01568627, 0.67058824, 0.64313725,\n \t0.65098039, 0.67843137, 0.62352941, 0.70196078, 0.65098039,\n \t0.62745098, 0.68235294, 0.65490196, 0.63529412, 0.65098039,\n \t0.50196078, 0.        , 0.00784314, 0.    , 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.    ,\n \t0.01176471, 0.    , 0.07058824, 0.59607843, 0.67843137,\n \t0.62745098, 0.70196078, 0.60392157, 0.70980392, 0.65098039,\n \t0.64313725, 0.68627451, 0.66666667, 0.65098039, 0.66666667,\n \t0.64313725, 0.    , 0.    , 0.00392157, 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.   , 0.    , 0.    ,\n \t0.01568627, 0.    , 0.18431373, 0.64705882, 0.6745098 ,\n \t0.65490196, 0.7254902 , 0.6   , 0.73333333, 0.67843137,\n \t0.64705882, 0.68235294, 0.70196078, 0.65098039, 0.65098039,\n \t0.61960784, 0.01960784, 0.    , 0.01176471, 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.    ,\n \t0.01568627, 0.    , 0.34117647, 0.70588235, 0.63529412,\n \t0.70196078, 0.70196078, 0.61568627, 0.74901961, 0.71372549,\n \t0.64705882, 0.65882353, 0.74509804, 0.67843137, 0.64705882,\n \t0.65098039, 0.07843137, 0.    , 0.01568627, 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.        , 0.    , 0.    ,\n \t0.01568627, 0.    , 0.41176471, 0.73333333, 0.61568627,\n \t0.76078431, 0.68627451, 0.63137255, 0.74509804, 0.72156863,\n \t0.66666667, 0.61960784, 0.80392157, 0.69411765, 0.65882353,\n \t0.67058824, 0.17254902, 0.    , 0.01568627, 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.    ,\n \t0.01960784, 0.    , 0.54117647, 0.70980392, 0.61960784,\n\t0.80392157, 0.62745098, 0.65490196, 0.74509804, 0.77647059,\n \t0.65490196, 0.59607843, 0.85490196, 0.72941176, 0.66666667,\n \t0.6745098 , 0.22352941, 0.    , 0.01960784, 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.     , 0.    , 0.        , 0.    , 0.    ,\n \t0.01960784, 0.    , 0.52941176, 0.68235294, 0.65490196,\n \t0.78039216, 0.60784314, 0.65098039, 0.78823529, 0.85882353,\n \t0.64705882, 0.61960784, 0.85490196, 0.7372549 , 0.65490196,\n \t0.68627451, 0.21960784, 0.    , 0.02745098, 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.    ,\n \t0.01960784, 0.    , 0.50588235, 0.67058824, 0.6745098 ,\n    0.69411765, 0.6       , 0.62352941, 0.80784314, 0.84705882,\n \t0.58039216, 0.61568627, 0.80784314, 0.74509804, 0.64705882,\n \t0.68627451, 0.18823529, 0.    , 0.01960784, 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.        , 0.    , 0.    , 0.    , 0.    ,\n \t0.01960784, 0.    , 0.65490196, 0.73333333, 0.71372549,\n \t0.77647059, 0.76078431, 0.78431373, 0.88627451, 0.94117647,\n \t0.72156863, 0.80784314, 1.    , 0.77254902, 0.69803922,\n \t0.70196078, 0.16470588, 0.    , 0.01960784, 0.    ,\n \t0.    , 0.    , 0.    ],\n\t&#91;0.    , 0.    , 0.    , 0.    , 0.    ,\n \t0.01176471, 0.    , 0.45098039, 0.52941176, 0.44313725,\n \t0.41568627, 0.33333333, 0.32156863, 0.42352941, 0.52156863,\n \t0.3254902 , 0.35294118, 0.4745098 , 0.47058824, 0.43137255,\n \t0.61960784, 0.07058824, 0.    , 0.01176471, 0.    ,\n \t0.    , 0.    , 0.    ]])\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#scale pixel values between 0 and 1\nx=255.0\ntrain_images = train_images \/ x\ntest_images = test_images \/ x\nplt.figure(figsize=(15,15))\nj=np.random.randint(0,1000,100)\ny=1\nfor i in range(100):\nplt.subplot(10,10,i+y)\nplt.xticks(&#91;])\nplt.yticks(&#91;])\nplt.grid(False)\nplt.imshow(train_images&#91;j&#91;i]], cmap=plt.cm.binary)\nplt.xlabel(class_names&#91;train_labels&#91;i]])\nplt.show()\n#after scaling\nTrain_images&#91;10]\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"output\"><strong>Output:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>array(&#91;&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 6.63394924e-07,\n \t8.56382538e-06, 1.20617259e-05, 6.39271472e-06, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 5.12623350e-06, 1.11570964e-05,\n        6.75456649e-06, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 9.16691167e-06, 1.29060467e-05,\n \t1.30869726e-05, 1.16998741e-05, 1.42328365e-05, 1.30266640e-05,\n \t1.12777137e-05, 8.98598578e-06, 8.14166497e-06, 9.22722030e-06,\n \t1.27251208e-05, 1.30869726e-05, 1.39312934e-05, 1.23632690e-05,\n \t1.30869726e-05, 1.13380223e-05, 2.05049340e-06, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 3.98036954e-06, 1.11570964e-05, 1.00112325e-05,\n \t1.08555533e-05, 1.09158619e-05, 1.14586396e-05, 1.27251208e-05,\n \t1.33282071e-05, 1.18808000e-05, 8.80505989e-06, 1.19411086e-05,\n \t1.24235777e-05, 1.15189482e-05, 1.01318497e-05, 1.14586396e-05,\n \t1.03730843e-05, 1.13380223e-05, 1.05540101e-05, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 8.14166497e-06, 9.22722030e-06, 9.64938071e-06,\n \t1.05540101e-05, 1.08555533e-05, 1.02524670e-05, 1.12174051e-05,\n \t1.12777137e-05, 1.14586396e-05, 1.13380223e-05, 1.14586396e-05,\n \t1.12777137e-05, 1.04937015e-05, 1.17601827e-05, 1.11570964e-05,\n \t1.04937015e-05, 9.70968934e-06, 1.05540101e-05, 3.55820914e-06,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 9.70968934e-06, 8.86536852e-06, 9.64938071e-06,\n\t1.02524670e-05, 1.07349360e-05, 1.06746274e-05, 1.08555533e-05,\n \t1.01318497e-05, 1.04333929e-05, 1.04937015e-05, 1.03127756e-05,\n \t1.11570964e-05, 1.10967878e-05, 1.11570964e-05, 1.03730843e-05,\n \t1.03127756e-05, 9.89061522e-06, 1.04937015e-05, 7.23703553e-06,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t1.20617259e-07, 1.05540101e-05, 8.80505989e-06, 8.74475126e-06,\n \t1.01318497e-05, 1.07349360e-05, 1.09158619e-05, 1.11570964e-05,\n \t1.08555533e-05, 1.10967878e-05, 1.07349360e-05, 1.07952447e-05,\n \t1.12777137e-05, 1.15189482e-05, 1.16395655e-05, 1.14586396e-05,\n \t1.09158619e-05, 1.03127756e-05, 1.03730843e-05, 9.52876345e-06,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t2.11080203e-06, 1.06746274e-05, 9.34783756e-06, 8.44320812e-06,\n    9.10660304e-06, 1.03730843e-05, 1.15189482e-05, 1.12777137e-05,\n \t1.12174051e-05, 1.12777137e-05, 1.12174051e-05, 1.12777137e-05,\n \t1.09761706e-05, 1.15189482e-05, 1.16998741e-05, 1.13380223e-05,\n \t1.08555533e-05, 9.70968934e-06, 9.70968934e-06, 1.11570964e-05,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t3.55820914e-06, 1.02524670e-05, 9.22722030e-06, 8.50351675e-06,\n \t7.23703553e-06, 9.28752893e-06, 9.64938071e-06, 9.70968934e-06,\n \t1.03730843e-05, 1.01318497e-05, 1.00112325e-05, 9.70968934e-06,\n \t9.95092385e-06, 1.03730843e-05, 1.02524670e-05, 9.89061522e-06,\n \t8.38289949e-06, 8.98598578e-06, 9.76999796e-06, 1.00112325e-05,\n \t1.26648122e-06, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n\t4.76438172e-06, 8.74475126e-06, 9.64938071e-06, 1.29060467e-05,\n \t7.41796142e-06, 7.71950456e-06, 9.22722030e-06, 9.64938071e-06,\n \t9.89061522e-06, 9.52876345e-06, 9.46845482e-06, 9.28752893e-06,\n \t9.34783756e-06, 1.02524670e-05, 9.95092385e-06, 8.50351675e-06,\n \t1.17601827e-05, 1.16395655e-05, 9.16691167e-06, 1.00112325e-05,\n \t3.67882639e-06, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t6.03086294e-06, 9.46845482e-06, 1.35694416e-05, 1.47756142e-05,\n \t1.05540101e-05, 6.81487512e-06, 1.04937015e-05, 9.52876345e-06,\n \t9.52876345e-06, 9.64938071e-06, 9.34783756e-06, 9.64938071e-06,\n \t9.89061522e-06, 1.07349360e-05, 1.13380223e-05, 8.14166497e-06,\n \t1.11570964e-05, 1.44740711e-05, 1.21220345e-05, 1.03730843e-05,\n \t6.51333198e-06, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 1.86956751e-06, 1.04937015e-05, 1.68864162e-06,\n \t7.59888731e-06, 9.22722030e-06, 1.00112325e-05, 9.16691167e-06,\n \t9.52876345e-06, 9.52876345e-06, 9.64938071e-06, 9.70968934e-06,\n \t9.46845482e-06, 1.01318497e-05, 1.15189482e-05, 1.13380223e-05,\n \t1.08555533e-06, 7.96073908e-06, 9.58907208e-06, 4.22160406e-07,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t4.94530761e-06, 1.12777137e-05, 9.58907208e-06, 9.22722030e-06,\n \t9.46845482e-06, 9.52876345e-06, 9.76999796e-06, 9.89061522e-06,\n \t9.89061522e-06, 9.28752893e-06, 1.12777137e-05, 1.14586396e-05,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n\t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t6.03086294e-08, 1.80925888e-07, 3.01543147e-07, 0.00000000e+00,\n \t2.23141929e-06, 1.05540101e-05, 9.52876345e-06, 9.34783756e-06,\n \t9.76999796e-06, 9.52876345e-06, 9.64938071e-06, 9.76999796e-06,\n \t9.95092385e-06, 9.22722030e-06, 1.06746274e-05, 1.23632690e-05,\n \t0.00000000e+00, 0.00000000e+00, 1.80925888e-07, 1.80925888e-07,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 6.03086294e-08, 0.00000000e+00,\n \t1.50771574e-06, 1.05540101e-05, 9.16691167e-06, 9.64938071e-06,\n \t9.52876345e-06, 9.70968934e-06, 9.64938071e-06, 9.89061522e-06,\n \t9.89061522e-06, 9.70968934e-06, 1.00112325e-05, 1.20617259e-05,\n \t0.00000000e+00, 0.00000000e+00, 6.03086294e-08, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 2.41234518e-07, 0.00000000e+00,\n \t1.80925888e-06, 1.03127756e-05, 8.86536852e-06, 9.89061522e-06,\n \t9.34783756e-06, 9.95092385e-06, 9.70968934e-06, 9.95092385e-06,\n \t9.76999796e-06, 1.02524670e-05, 9.89061522e-06, 9.76999796e-06,\n \t0.00000000e+00, 0.00000000e+00, 1.20617259e-07, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 2.41234518e-07, 0.00000000e+00,\n \t3.43759188e-06, 1.00112325e-05, 9.34783756e-06, 9.89061522e-06,\n \t1.00112325e-05, 9.70968934e-06, 9.70968934e-06, 9.89061522e-06,\n \t1.00715411e-05, 9.95092385e-06, 9.95092385e-06, 9.76999796e-06,\n \t1.68864162e-06, 0.00000000e+00, 1.80925888e-07, 0.00000000e+00,\n\t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 1.80925888e-07, 0.00000000e+00,\n \t6.87518375e-06, 9.70968934e-06, 9.70968934e-06, 1.00112325e-05,\n        9.58907208e-06, 1.01318497e-05, 9.70968934e-06, 9.70968934e-06,\n \t1.03730843e-05, 9.76999796e-06, 9.95092385e-06, 1.03127756e-05,\n \t3.01543147e-06, 0.00000000e+00, 3.01543147e-07, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 6.03086294e-08, 0.00000000e+00,\n \t8.98598578e-06, 9.46845482e-06, 1.00715411e-05, 1.03730843e-05,\n \t9.58907208e-06, 1.03730843e-05, 9.89061522e-06, 9.70968934e-06,\n \t1.03730843e-05, 1.02524670e-05, 9.64938071e-06, 1.03127756e-05,\n \t5.36746802e-06, 0.00000000e+00, 2.41234518e-07, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 1.20617259e-07, 0.00000000e+00, 2.41234518e-07,\n \t1.03127756e-05, 9.89061522e-06, 1.00112325e-05, 1.04333929e-05,\n \t9.58907208e-06, 1.07952447e-05, 1.00112325e-05, 9.64938071e-06,\n \t1.04937015e-05, 1.00715411e-05, 9.76999796e-06, 1.00112325e-05,\n \t7.71950456e-06, 0.00000000e+00, 1.20617259e-07, 0.00000000e+00,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 1.80925888e-07, 0.00000000e+00, 1.08555533e-06,\n \t9.16691167e-06, 1.04333929e-05, 9.64938071e-06, 1.07952447e-05,\n \t9.28752893e-06, 1.09158619e-05, 1.00112325e-05, 9.89061522e-06,\n \t1.05540101e-05, 1.02524670e-05, 1.00112325e-05, 1.02524670e-05,\n\t9.89061522e-06, 0.00000000e+00, 0.00000000e+00, 6.03086294e-08,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 2.41234518e-07, 0.00000000e+00, 2.83450558e-06,\n \t9.95092385e-06, 1.03730843e-05, 1.00715411e-05, 1.11570964e-05,\n \t9.22722030e-06, 1.12777137e-05, 1.04333929e-05, 9.95092385e-06,\n \t1.04937015e-05, 1.07952447e-05, 1.00112325e-05, 1.00112325e-05,\n \t9.52876345e-06, 3.01543147e-07, 0.00000000e+00, 1.80925888e-07,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 2.41234518e-07, 0.00000000e+00, 5.24685076e-06,\n \t1.08555533e-05, 9.76999796e-06, 1.07952447e-05, 1.07952447e-05,\n \t9.46845482e-06, 1.15189482e-05, 1.09761706e-05, 9.95092385e-06,\n \t1.01318497e-05, 1.14586396e-05, 1.04333929e-05, 9.95092385e-06,\n \t1.00112325e-05, 1.20617259e-06, 0.00000000e+00, 2.41234518e-07,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n  &#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 2.41234518e-07, 0.00000000e+00, 6.33240609e-06,\n \t1.12777137e-05, 9.46845482e-06, 1.16998741e-05, 1.05540101e-05,\n \t9.70968934e-06, 1.14586396e-05, 1.10967878e-05, 1.02524670e-05,\n \t9.52876345e-06, 1.23632690e-05, 1.06746274e-05, 1.01318497e-05,\n \t1.03127756e-05, 2.65357969e-06, 0.00000000e+00, 2.41234518e-07,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 3.01543147e-07, 0.00000000e+00, 8.32259086e-06,\n \t1.09158619e-05, 9.52876345e-06, 1.23632690e-05, 9.64938071e-06,\n \t1.00715411e-05, 1.14586396e-05, 1.19411086e-05, 1.00715411e-05,\n\t9.16691167e-06, 1.31472812e-05, 1.12174051e-05, 1.02524670e-05,\n \t1.03730843e-05, 3.43759188e-06, 0.00000000e+00, 3.01543147e-07,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 3.01543147e-07, 0.00000000e+00, 8.14166497e-06,\n \t1.04937015e-05, 1.00715411e-05, 1.20014173e-05, 9.34783756e-06,\n \t1.00112325e-05, 1.21220345e-05, 1.32075898e-05, 9.95092385e-06,\n \t9.52876345e-06, 1.31472812e-05, 1.13380223e-05, 1.00715411e-05,\n \t1.05540101e-05, 3.37728325e-06, 0.00000000e+00, 4.22160406e-07,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 3.01543147e-07, 0.00000000e+00, 7.77981319e-06,\n \t1.03127756e-05, 1.03730843e-05, 1.06746274e-05, 9.22722030e-06,\n \t9.58907208e-06, 1.24235777e-05, 1.30266640e-05, 8.92567715e-06,\n \t9.46845482e-06, 1.24235777e-05, 1.14586396e-05, 9.95092385e-06,\n \t1.05540101e-05, 2.89481421e-06, 0.00000000e+00, 3.01543147e-07,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 3.01543147e-07, 0.00000000e+00, 1.00715411e-05,\n \t1.12777137e-05, 1.09761706e-05, 1.19411086e-05, 1.16998741e-05,\n \t1.20617259e-05, 1.36297502e-05, 1.44740711e-05, 1.10967878e-05,\n \t1.24235777e-05, 1.53787005e-05, 1.18808000e-05, 1.07349360e-05,\n \t1.07952447e-05, 2.53296244e-06, 0.00000000e+00, 3.01543147e-07,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n\t&#91;0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n \t0.00000000e+00, 1.80925888e-07, 0.00000000e+00, 6.93549238e-06,\n \t8.14166497e-06, 6.81487512e-06, 6.39271472e-06, 5.12623350e-06,\n\t4.94530761e-06, 6.51333198e-06, 8.02104771e-06, 5.00561624e-06,\n\t5.42777665e-06, 7.29734416e-06, 7.23703553e-06, 6.63394924e-06,\n \t9.52876345e-06, 1.08555533e-06, 0.00000000e+00, 1.80925888e-07,\n \t0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00]])<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>model = keras.Sequential(&#91;\n    keras.layers.Flatten(input_shape=(28, 28)),\n    keras.layers.Dense(128, activation=\u2019relu\u2019),\n    keras.layers.Dense(10)\n])\nmodel.compile(optimizer=\u2019adam\u2019,\n       \tloss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),\n       \tmetrics=&#91;\u2018accuracy\u2019])\nmodel.fit(train_images, train_labels, epochs=20)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Train on 60000 samples\nEpoch 1\/20\n60000\/60000 &#91;==============================] \u2013 10s 160us\/sample \u2013 loss: 2.3026 \u2013 accuracy: 0.1003\nEpoch 2\/20\n60000\/60000 &#91;==============================] \u2013 10s 159us\/sample \u2013 loss: 2.3004 \u2013 accuracy: 0.1214\nEpoch 3\/20\n60000\/60000 &#91;==============================] \u2013 9s 156us\/sample \u2013 loss: 2.2912 \u2013 accuracy: 0.1519\nEpoch 4\/20\n60000\/60000 &#91;==============================] \u2013 9s 150us\/sample \u2013 loss: 2.2710 \u2013 accuracy: 0.1963\nEpoch 5\/20\n60000\/60000 &#91;==============================] \u2013 9s 156us\/sample \u2013 loss: 2.2398 \u2013 accuracy: 0.2117\nEpoch 6\/20\n60000\/60000 &#91;==============================] \u2013 9s 147us\/sample \u2013 loss: 2.2013 \u2013 accuracy: 0.2122\nEpoch 7\/20\n60000\/60000 &#91;==============================] \u2013 9s 148us\/sample \u2013 loss: 2.1584 \u2013 accuracy: 0.2189\nEpoch 8\/20\n60000\/60000 &#91;==============================] \u2013 9s 146us\/sample \u2013 loss: 2.1131 \u2013 accuracy: 0.2311\nEpoch 9\/20\n60000\/60000 &#91;==============================] \u2013 9s 154us\/sample \u2013 loss: 2.0680 \u2013 accuracy: 0.2320\nEpoch 10\/20\n60000\/60000 &#91;==============================] \u2013 9s 146us\/sample \u2013 loss: 2.0240 \u2013 accuracy: 0.2304\nEpoch 11\/20\n60000\/60000 &#91;==============================] \u2013 9s 144us\/sample \u2013 loss: 1.9825 \u2013 accuracy: 0.2491\nEpoch 12\/20\n60000\/60000 &#91;==============================] \u2013 9s 149us\/sample \u2013 loss: 1.9438 \u2013 accuracy: 0.2526\nEpoch 13\/20\n60000\/60000 &#91;==============================] \u2013 8s 129us\/sample \u2013 loss: 1.9083 \u2013 accuracy: 0.2649\nEpoch 14\/20\n60000\/60000 &#91;==============================] \u2013 8s 128us\/sample \u2013 loss: 1.8761 \u2013 accuracy: 0.2816\nEpoch 15\/20\n60000\/60000 &#91;==============================] \u2013 8s 129us\/sample \u2013 loss: 1.8466 \u2013 accuracy: 0.3038\nEpoch 16\/20\n60000\/60000 &#91;==============================] \u2013 8s 135us\/sample \u2013 loss: 1.8195 \u2013 accuracy: 0.2962\nEpoch 17\/20\n60000\/60000 &#91;==============================] \u2013 8s 128us\/sample \u2013 loss: 1.7948 \u2013 accuracy: 0.3250\nEpoch 18\/20\n60000\/60000 &#91;==============================] \u2013 8s 127us\/sample \u2013 loss: 1.7716 \u2013 accuracy: 0.3496\nEpoch 19\/20\n60000\/60000 &#91;==============================] \u2013 8s 130us\/sample \u2013 loss: 1.7495 \u2013 accuracy: 0.3587\nEpoch 20\/20\n60000\/60000 &#91;==============================] \u2013 8s 129us\/sample \u2013 loss: 1.7280 \u2013 accuracy: 0.3801\n&lt;tensorflow.python.keras.callbacks.History at 0x1e9515f2088&gt;\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>test_loss, test_acc = model.evaluate(test_images,  test_labels, verbose=2)\nprint(\u2018nTest accuracy:\u2019, test_acc)\n10000\/10000 \u2013 2s \u2013 loss: 1.7180 \u2013 accuracy: 0.4055\nTest accuracy: 0.4055\n\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>probability_model = tf.keras.Sequential(&#91;model,\n    \t                              tf.keras.layers.Softmax()])\npredictions = probability_model.predict(test_images)\npredictions = probability_model.predict(test_images)\npredictions&#91;10]\n\narray(&#91;0.12555718, 0.13396162, 0.14664494, 0.13513418, 0.14349538,\n      0.02516511, 0.14363666, 0.01587282, 0.10545293, 0.02507922],\n  dtype=float32)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"output\"><strong>Output:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\nnp.argmax(predictions&#91;10])\ntest_labels&#91;10]\ndef plot_image(i, predictions_array, true_label, img):\n  predictions_array, true_label, img = predictions_array, true_label&#91;i], img&#91;i]\n  plt.grid(False)\n  plt.xticks(&#91;])\n  plt.yticks(&#91;])\n  plt.imshow(img, cmap=plt.cm.binary)\n  predicted_label = np.argmax(predictions_array)\n  if predicted_label == true_label:\ncolor = \u2018blue\u2019\n  else:\ncolor = \u2018red\u2019\n  plt.xlabel(\u201c{} {:2.0f}% ({})\u201d.format(class_names&#91;predicted_label],\n                         \t100*np.max(predictions_array),\n                         \tclass_names&#91;true_label]),\n                         \tcolor=color)\ndef plot_value_array(i, predictions_array, true_label):\n  predictions_array, true_label = predictions_array, true_label&#91;i]\n  plt.grid(False)\n  plt.xticks(range(10))\n  plt.yticks(&#91;])\n  thisplot = plt.bar(range(10), predictions_array, color=\u201d#777777\u2033)\n  plt.ylim(&#91;0, 1])\n  predicted_label = np.argmax(predictions_array)\n  thisplot&#91;predicted_label].set_color(\u2018red\u2019)\n  thisplot&#91;true_label].set_color(\u2018blue\u2019)\n\n\ni = 10\nplt.figure(figsize=(6,3))\nplt.subplot(1,2,1)\nplot_image(i, predictions&#91;i], test_labels, test_images)\nplt.subplot(1,2,2)\nplot_value_array(i, predictions&#91;i],  test_labels)\nplt.show()\n\ni = 122\nplt.figure(figsize=(6,3))\nplt.subplot(1,2,1)\nplot_image(i, predictions&#91;i], test_labels, test_images)\nplt.subplot(1,2,2)\nplot_value_array(i, predictions&#91;i],  test_labels)\nplt.show()\n\n# Plot the first X test images, their predicted labels, and the true labels.\n# Color correct predictions in blue and incorrect predictions in red.\nnum_rows = 7\nnum_cols = 7\nj=np.random.randint(0,1000,num_rows*num_cols)\nnum_images = num_rows*num_cols\nplt.figure(figsize=(2*2*num_cols, 2*num_rows))\nfor i in range(num_images):\n  plt.subplot(num_rows, 2*num_cols, 2*i+1)\n  plot_image(j&#91;i], predictions&#91;j&#91;i]], test_labels, test_images)\n  plt.subplot(num_rows, 2*num_cols, 2*i+2)\n  plot_value_array(j&#91;i], predictions&#91;j&#91;i]], test_labels)\nplt.tight_layout()\nplt.show()\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"types-of-object-detection-algorithms\"><strong>Types of Object Detection Algorithms<\/strong><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"1-region-based-convolutional-neural-networksr-cnn\"><strong>1. Region-based Convolutional Neural Networks(R-CNN):<\/strong><\/h4>\n\n\n\n<p>Since we know that object detection is a classification problem, the success of the model depends on the accuracy of the classification of all objects. The general idea is to use CNNs.But a problem with CNN's is that they are too slow and computationally expensive. Hence it's not feasible to run CNNs on so many patches generated by sliding window detectors.&nbsp;<\/p>\n\n\n\n<p>Hence, R-CNN we introduced.R-CNN networks solve this problem by using an object proposal algorithm termed Selective Search which is used to reduce the number of bounding boxes that are being fed to the classifier to a maximum of 2000 region proposals. Selective search uses features like texture, pixel intensity, color, etc to generate all possible locations of objects in an image. Now, these boxes can be fed to our CNN based classifier.Se we run Selective Search to generate probable objects.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>These patches are then fed to CNN, followed by an SVM classifier to predict the class of objects in each patch.<\/li>\n\n\n\n<li>We then optimize all patches by training a model for bounding box regression exclusively.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"2-fast-r-cnn\"><strong>2. Fast R-CNN:<\/strong><\/h4>\n\n\n\n<p>Fast R-CNN was introduced because R-CNN architectures were very slow. Fast RCNN uses the concepts of RCNN. But it has a few architectural changes as compared to R-CNN architectures. For instance for gradient propagation, it uses spatial pooling. Back-propagation calculation is used which is very similar to max-pooling but is more effective.<\/p>\n\n\n\n<p>In Fast R-CNN architectures the bounding box regression was added to the neural network training instead of doing it separately. It enabled the network to have two heads, classification head, and bounding box regression head.&nbsp;<\/p>\n\n\n\n<p>These two changes reduced the overall training time and increased the accuracy.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"3-faster-r-cnn\"><strong>3. Faster R-CNN:<\/strong><\/h4>\n\n\n\n<p>An improvement over Fast R-CNN was faster R-CNN.<\/p>\n\n\n<p><!--StartFragment--><\/p>\n\n\n<p>Apart from that, we have some more networks which are very popular.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Yolo<\/li>\n\n\n\n<li>SSD<\/li>\n<\/ol>\n\n\n\n<p>A comparative graph of performances of all networks.<\/p>\n\n\n\n<p>SSD seems to be a good choice as we are able to run it on a video and the accuracy trade-off is very little. However, it may not be that simple, look at this chart that compares the performance of SSD, YOLO, and Faster-RCNN on various sized objects. At large sizes, SSD seems to perform similarly to Faster-RCNN. However, look at the accuracy numbers when the object size is small, the gap widens.<\/p>\n\n\n\n<p>YOLO vs SSD vs Faster-RCNN for various sizes<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"code-for-object-detection-using-pytorch\"><strong>Code for object detection using PyTorch<\/strong><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"defining-the-dataset\"><strong>Defining the Dataset<\/strong><\/h4>\n\n\n\n<p>In defining the dataset we need to add our dataset to the torch.utils.data.Datasets. For this we inherit the torch.utils.data.Dataset class, and do implementation of&nbsp; __len__ and __getitem__.&nbsp;<\/p>\n\n\n\n<p>The reference scripts for training object detection, instance segmentation, and person keypoint detection allow for easily supporting adding new custom datasets.<\/p>\n\n\n\n<p>Our class should return the following values from __getitem__<\/p>\n\n\n\n<p><strong>image:<\/strong> an image of size (x, y) in PIL format as the dimensions of the image should already be predefined.<\/p>\n\n\n\n<p><strong>target:<\/strong> a dictionary which contains the following keys:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>boxes (FloatTensor[N, 4]): the numerical coordinates of the N bounding boxes which we obtain in [ x0, y0, x1, y1 ] format, ranging from 0 to x and 0 to y<\/li>\n\n\n\n<li>labels ( Int64Tensor [ N ] ) :\u00a0 It should have the label for each bounding box. 0 represents the background class and is reserved for the background class only.<\/li>\n\n\n\n<li>image_id ( Int64 Tensor[1]): An identifier for an image that should be unique for all the images in the dataset and which is used while evaluation of the performance of the metrics.<\/li>\n\n\n\n<li>area ( Tensor [ N ] ) : The bounding box area which is calculated from the coordinates. This is used with the COCO metric for evaluation, to separate the individual metric scores for small, medium, and large boxes.<\/li>\n\n\n\n<li>crowd ( UInt8Tensor [ N ] ) : cases with iscrowd=True will be ignored while evaluation\u00a0<\/li>\n\n\n\n<li>masks ( UInt8Tensor [N , x ,\u00a0 y ] ) : The segmentation masks for each one of the objects(optional)<\/li>\n\n\n\n<li>key points ( FloatTensor [ N , K , 3 ] ) : For each object in a total of N objects, it contains the K key points in [ x , y , visibility] format, defining the present object. visibility=0 means that the key point is not identified\/visible. It should be noted that for data augmentation, the idea of flipping a key point is dependent on the representation of data, and probably we should adapt references\/detection\/transforms.py for our new keypoint representations if any.<\/li>\n<\/ol>\n\n\n\n<p>If our model returns the above methods as specified, it will make it work for both training and evaluation phases, and will make use of the evaluation scripts from protocols.<\/p>\n\n\n\n<p>Point to be noted for the labels:<\/p>\n\n\n\n<p>Background is considered class 0 by the model. If the dataset does not have the background class, we will not have 0 in our labels. For instance, assuming we have only two classes, cat and dog, we can define 1 ( and not 0) to specify cats and 2 to specify dogs. So, for example, if any of the images have both the classes, our labels tensor will look like [1,2].<\/p>\n\n\n\n<p>Also, if we want to use a grouped aspect ratio during training (so that each and every batch of images only contains images which are having the same aspect ratio), then it is advised to incorporate the implementation of a get_height_and_width function, which returns the specific height and the specific width of the image for all images in the dataset. If this method is not defined, we will have to query all the elements of the dataset via __getitem__ , which in turn loads the image in computer memory and is comparatively slower than a custom method if defined.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"writing-a-custom-dataset\"><strong>Writing a custom dataset<\/strong><\/h4>\n\n\n\n<p>Let\u2019s write a dataset for the PennFudan dataset. Before that, we will have to download and extract the dataset as given in official PyTorch documentation. After we are finished with download and extraction of the zip file, we would have the following directory structure:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PennFudanPed\/\n  PedMasks\/\n    FudanPed00001_mask.png\n    FudanPed00002_mask.png\n    FudanPed00003_mask.png\n    FudanPed00004_mask.png\n    \u2026\n  PNGImages\/\n    FudanPed00001.png\n    FudanPed00002.png\n    FudanPed00003.png\n    FudanPed00004.png\n<\/code><\/pre>\n\n\n\n<p>So we see that each image has a segmentation mask, where each color is mapped to a different class. Let\u2019s write a torch.utils.data.Dataset class for this data we have.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#importing libraries\nimport os #os for folder operations\nimport numpy as np\nimport torch # pytorch library\nfrom PIL import Image #for image operations\nclass PennFudanDataset(object): #class for returning attributes as specified above\n    def __init__(self, root, transforms):\n        self.root = root\n        self.transforms = transforms\n        # loading all the image files, and sorting them to ensure that they have proper alignment\n        self.imgs = list(sorted(os.listdir(os.path.join(root, \u201cPNGImages\u201d))))\n        self.masks = list(sorted(os.listdir(os.path.join(root, \u201cPedMasks\u201d))))\n    def __getitem__(self, idx):\n        # loading images and masks\n        img_path = os.path.join(self.root, \u201cPNGImages\u201d, self.imgs&#91;idx])\n        mask_path = os.path.join(self.root, \u201cPedMasks\u201d, self.masks&#91;idx])\n        img = Image.open(img_path).convert(\u201cRGB\u201d)\n        # note that we have not converted the mask to RGB  color format\n        # as each color corresponds to a different class\n        # with 0 representing background class\n        mask = Image.open(mask_path)\n        # converting the PIL Image into a numpy arrayformat\n        mask = np.array(mask)\n        # different class of objects are encoded with different colors\n        obj_ids = np.unique(mask)\n        # first id is the background ie. class 0, hence we remove it\n        obj_ids = obj_ids&#91;1:]\n        # we split the color-encoded masks into a set\n        # of binary masks\n        masks = mask == obj_ids&#91;:, None, None]\n        # now we get bounding box coordinates for each of the masks\n        num_objs = len(obj_ids)\n        boxes = &#91;]\n        for i in range(num_objs):\n            pos = np.where(masks&#91;i])\n            xmin = np.min(pos&#91;1])\n            xmax = np.max(pos&#91;1])\n            ymin = np.min(pos&#91;0])\n            ymax = np.max(pos&#91;0])\n            boxes.append(&#91;xmin, ymin, xmax, ymax])\n        # converting everything to a torch.Tensor\n        boxes = torch.as_tensor(boxes, dtype=torch.float32)\n        # only one class is present\n        labels = torch.ones((num_objs,), dtype=torch.int64)\n        masks = torch.as_tensor(masks, dtype=torch.uint8)\n        image_id = torch.tensor(&#91;idx])\n        area = (boxes&#91;:, 3] \u2013 boxes&#91;:, 1]) * (boxes&#91;:, 2] \u2013 boxes&#91;:, 0])\n        # assuming all classes are not crowd\n        iscrowd = torch.zeros((num_objs,), dtype=torch.int64)\n        target = {}\n        target&#91;\u201cboxes\u201d] = boxes\n        target&#91;\u201clabels\u201d] = labels\n        target&#91;\u201cmasks\u201d] = masks\n        target&#91;\u201cimage_id\u201d] = image_id\n        target&#91;\u201carea\u201d] = area\n        target&#91;\u201ciscrowd\u201d] = iscrowd\n        if self.transforms is not None:\n            img, target = self.transforms(img, target)\n        return img, target\n    def __len__(self):\n        return len(self.imgs)\n<\/code><\/pre>\n\n\n\n<p>Now we have obtained the dataset in desired format. Now we define a model that can be used for predictions on the above dataset.<\/p>\n\n\n\n<p><strong>Model Definition<\/strong><\/p>\n\n\n\n<p>In this code demonstration, we are using Mask R-CNN, which is based on top of a Faster R-CNN implementation. Faster R-CNN is an object detection model that is used&nbsp; for prediction of both bounding boxes and the predicted class-scores for each potential object in the image.<\/p>\n\n\n\n<p>Mask R-CNN being an image segmentation technique adds an extra branch to the Faster R-CNN, by also predicting segmentation masks for each class.<\/p>\n\n\n\n<p>There are always two common situations where we might need to modify one of the available models currently being provided in torchvision modelzoo. The first condition being&nbsp; when we intend to start from a pre-trained model, and then finetune the last layer to get results. The other situation being when intending to replace the backbone of the model with a different model (for faster predictions).<\/p>\n\n\n\n<p>In following sections we will take a look at the aforementioned scenarios:&nbsp;<\/p>\n\n\n\n<p><strong>1. Fine Tuning a pretrained model<\/strong><\/p>\n\n\n\n<p>Let\u2019s assume that we want to start from a model pre-trained on the COCO dataset and&nbsp; we want to finetune it for our particular classes. Here is a feasible way of doing it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import torchvision\nfrom torchvision.models.detection.faster_rcnn import FastRCNNPredictor\n# loading a model pre-trained on the COCO dataset, resnet50 in this case\nmodel = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True)\n# then we replace the classifier of resnet50 with a new one, that has\n# number of classes defined by the user\nnum_classes = 2  # 1 class (person) + class(background)\n# specify number of input features required by the classifier\nin_features = model.roi_heads.box_predictor.cls_score.in_features\n# replace the already existing head with new one\nmodel.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)\n<\/code><\/pre>\n\n\n\n<p>&nbsp;<strong>2. Modification of the model to by adding a different backbone<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import torchvision\nfrom torchvision.models.detection import FasterRCNN\nfrom torchvision.models.detection.rpn import AnchorGenerator\n# we initially load a pre-trained model \n# we only return the features\nbackbone = torchvision.models.mobilenet_v2(pretrained=True).features\n# FasterRCNN requires the number of output channels in the backbone.\n# For mobilenet_v2, it\u2019s 1280  so we need to add it in our model\nbackbone.out_channels = 1280\n<\/code><\/pre>\n\n\n\n<p>Now let's make the RPN model generate 5 x 3 anchors for each spatial location, with 5 different sizes and 3 different aspect ratios. We obtain a Tuple[Tuple[int]] because for each feature map we have have different sizes and aspect ratios.<\/p>\n\n\n\n<p>anchor_generator = AnchorGenerator(sizes=((32, 64, 128, 256, 512),),<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aspect_ratios=((0.5, 1.0, 2.0),))<\/p>\n\n\n\n<p>#Now let's define feature maps that will be used to perform ROI cropping. We also define the size of the cropping after the rescaling.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># if the backbone returns a Tensor, featmap_names must be &#91;0].\n# More generally, the backbone should return an\n# OrderedDict&#91;Tensor], and in featmap_names you can choose which\n# feature maps to use.\nroi_pooler = torchvision.ops.MultiScaleRoIAlign(featmap_names=&#91;0],\n                                                output_size=7,\n                                                sampling_ratio=2)\n# put the pieces together inside a FasterRCNN model\nmodel = FasterRCNN(backbone,\n                   num_classes=2,\n                   rpn_anchor_generator=anchor_generator,\n                   box_roi_pool=roi_pooler)\n<\/code><\/pre>\n\n\n\n<p>An Instance segmentation model using PennFudan Dataset.<\/p>\n\n\n\n<p>In our case, we have to fine-tune a pre-trained model, and having seen that our dataset is very small, we will be following through on approach 1.<\/p>\n\n\n\n<p>Here we will also compute the instance segmentation masks, so we use a Mask R-CNN type of model.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import torchvision\nfrom torchvision.models.detection.faster_rcnn import FastRCNNPredictor\nfrom torchvision.models.detection.mask_rcnn import MaskRCNNPredictor\ndef get_model_instance_segmentation(num_classes):\n    # loading an instance segmentation model pre-trained on the  COCO dataset\n    model = torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained=True)\n    # get number of input features for the classifier\n    in_features = model.roi_heads.box_predictor.cls_score.in_features\n    # replacing the pre-trained head with the new one\n    model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)\n    # now we calculate the number of input features for the mask classifier\n    in_features_mask = model.roi_heads.mask_predictor.conv5_mask.in_channels\n    hidden_layer = 256\n    # we also replace the mask predictor with a new mask predictor\n    model.roi_heads.mask_predictor = MaskRCNNPredictor(in_features_mask,\n                                                       hidden_layer,\n                                                       num_classes)\n    return model\n<\/code><\/pre>\n\n\n\n<p>&nbsp;Now our model is ready to be trained and evaluated on our custom dataset.<\/p>\n\n\n\n<p><strong>Putting everything together<\/strong><\/p>\n\n\n\n<p>In references\/detection\/, we have a number of helper functions to simplify training and evaluating detection models. Here, we will use references\/detection\/engine.py, references\/detection\/utils.py and references\/detection\/transforms.py. Just copy them to your folder and use them here.<\/p>\n\n\n\n<p>Let\u2019s write some helper functions for data augmentation\/transformation:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import transforms as T\ndef get_transform(train):\n    transforms = &#91;]\n    transforms.append(T.ToTensor())\n    if train:\n        transforms.append(T.RandomHorizontalFlip(0.5))\n    return T.Compose(transforms)\nTesting forward() method (Optional)\n<\/code><\/pre>\n\n\n\n<p>Before iterating over the dataset, it\u2019s good to see what the model expects during training and inference time on sample data.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True)\ndataset = PennFudanDataset(\u2018PennFudanPed\u2019, get_transform(train=True))\ndata_loader = torch.utils.data.DataLoader(\n dataset, batch_size=2, shuffle=True, num_workers=4,\n collate_fn=utils.collate_fn)\n# For Training\nimages,targets = next(iter(data_loader))\nimages = list(image for image in images)\ntargets = &#91;{k: v for k, v in t.items()} for t in targets]\noutput = model(images,targets)   # Returns losses and detections\n# For inference\nmodel.eval()\nx = &#91;torch.rand(3, 300, 400), torch.rand(3, 500, 400)]\npredictions = model(x)           # Returns predictions\n<\/code><\/pre>\n\n\n\n<p>Let\u2019s now write the main function which performs the training and the validation:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from engine import train_one_epoch, evaluate\nimport utils\ndef main():\n    # train on the GPU or on the CPU, if a GPU is not available\n    device = torch.device(\u2018cuda\u2019) if torch.cuda.is_available() else torch.device(\u2018cpu\u2019)\n    # our dataset has two classes only \u2013 background and person\n    num_classes = 2\n    # use our dataset and defined transformations\n    dataset = PennFudanDataset(\u2018PennFudanPed\u2019, get_transform(train=True))\n    dataset_test = PennFudanDataset(\u2018PennFudanPed\u2019, get_transform(train=False))\n    # split the dataset in train and test set\n    indices = torch.randperm(len(dataset)).tolist()\n    dataset = torch.utils.data.Subset(dataset, indices&#91;:-50])\n    dataset_test = torch.utils.data.Subset(dataset_test, indices&#91;-50:])\n    # define training and validation data loaders\n    data_loader = torch.utils.data.DataLoader(\n        dataset, batch_size=2, shuffle=True, num_workers=4,\n        collate_fn=utils.collate_fn)\n    data_loader_test = torch.utils.data.DataLoader(\n        dataset_test, batch_size=1, shuffle=False, num_workers=4,\n        collate_fn=utils.collate_fn)\n    # get the model using our helper function\n    model = get_model_instance_segmentation(num_classes)\n    # move model to the right device\n    model.to(device)\n    # construct an optimizer\n    params = &#91;p for p in model.parameters() if p.requires_grad]\n    optimizer = torch.optim.SGD(params, lr=0.005,\n                                momentum=0.9, weight_decay=0.0005)\n    # and a learning rate scheduler\n    lr_scheduler = torch.optim.lr_scheduler.StepLR(optimizer,\n                                                   step_size=3,\n                                                   gamma=0.1)\n    # let\u2019s train it for 10 epochs\n    num_epochs = 10\n    for epoch in range(num_epochs):\n        # train for one epoch, printing every 10 iterations\n        train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq=10)\n        # update the learning rate\n        lr_scheduler.step()\n        # evaluate on the test dataset\n        evaluate(model, data_loader_test, device=device)\n    print(\u201cThat\u2019s it!\u201d)\n<\/code><\/pre>\n\n\n\n<p><strong>You should get as output for the first epoch:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Epoch: &#91;0]  &#91; 0\/60]  eta: 0:01:18  lr: 0.000090  loss: 2.5213 (2.5213)  loss_classifier: 0.8025 (0.8025)  loss_box_reg: 0.2634 (0.2634)  loss_mask: 1.4265 (1.4265)  loss_objectness: 0.0190 (0.0190)  loss_rpn_box_reg: 0.0099 (0.0099)  time: 1.3121  data: 0.3024  max mem: 3485\nEpoch: &#91;0]  &#91;10\/60]  eta: 0:00:20  lr: 0.000936  loss: 1.3007 (1.5313)  loss_classifier: 0.3979 (0.4719)  loss_box_reg: 0.2454 (0.2272)  loss_mask: 0.6089 (0.7953)  loss_objectness: 0.0197 (0.0228)  loss_rpn_box_reg: 0.0121 (0.0141)  time: 0.4198  data: 0.0298  max mem: 5081\nEpoch: &#91;0]  &#91;20\/60]  eta: 0:00:15  lr: 0.001783  loss: 0.7567 (1.1056)  loss_classifier: 0.2221 (0.3319)  loss_box_reg: 0.2002 (0.2106)  loss_mask: 0.2904 (0.5332)  loss_objectness: 0.0146 (0.0176)  loss_rpn_box_reg: 0.0094 (0.0123)  time: 0.3293  data: 0.0035  max mem: 5081\nEpoch: &#91;0]  &#91;30\/60]  eta: 0:00:11  lr: 0.002629  loss: 0.4705 (0.8935)  loss_classifier: 0.0991 (0.2517)  loss_box_reg: 0.1578 (0.1957)  loss_mask: 0.1970 (0.4204)  loss_objectness: 0.0061 (0.0140)  loss_rpn_box_reg: 0.0075 (0.0118)  time: 0.3403  data: 0.0044  max mem: 5081\nEpoch: &#91;0]  &#91;40\/60]  eta: 0:00:07  lr: 0.003476  loss: 0.3901 (0.7568)  loss_classifier: 0.0648 (0.2022)  loss_box_reg: 0.1207 (0.1736)  loss_mask: 0.1705 (0.3585)  loss_objectness: 0.0018 (0.0113)  loss_rpn_box_reg: 0.0075 (0.0112)  time: 0.3407  data: 0.0044  max mem: 5081\nEpoch: &#91;0]  &#91;50\/60]  eta: 0:00:03  lr: 0.004323  loss: 0.3237 (0.6703)  loss_classifier: 0.0474 (0.1731)  loss_box_reg: 0.1109 (0.1561)  loss_mask: 0.1658 (0.3201)  loss_objectness: 0.0015 (0.0093)  loss_rpn_box_reg: 0.0093 (0.0116)  time: 0.3379  data: 0.0043  max mem: 5081\nEpoch: &#91;0]  &#91;59\/60]  eta: 0:00:00  lr: 0.005000  loss: 0.2540 (0.6082)  loss_classifier: 0.0309 (0.1526)  loss_box_reg: 0.0463 (0.1405)  loss_mask: 0.1568 (0.2945)  loss_objectness: 0.0012 (0.0083)  loss_rpn_box_reg: 0.0093 (0.0123)  time: 0.3489  data: 0.0042  max mem: 5081\nEpoch: &#91;0] Total time: 0:00:21 (0.3570 s \/ it)\ncreating an index\u2026\nindex created!\nTest:  &#91; 0\/50]  eta: 0:00:19  model_time: 0.2152 (0.2152)  evaluator_time: 0.0133 (0.0133)  time: 0.4000  data: 0.1701  max mem: 5081\nTest:  &#91;49\/50]  eta: 0:00:00  model_time: 0.0628 (0.0687)  evaluator_time: 0.0039 (0.0064)  time: 0.0735  data: 0.0022  max mem: 5081\nTest: Total time: 0:00:04 (0.0828 s \/ it)\nAveraged stats: model_time: 0.0628 (0.0687)  evaluator_time: 0.0039 (0.0064)\nAccumulating evaluation results\u2026\nDONE (t=0.01s).\nAccumulating evaluation results\u2026\nDONE (t=0.01s).\nIoU metric: bbox\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.606\n Average Precision  (AP) @&#91; IoU=0.50      | area=   all | maxDets=100 ] = 0.984\n Average Precision  (AP) @&#91; IoU=0.75      | area=   all | maxDets=100 ] = 0.780\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.313\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.582\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.612\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.270\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.672\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.672\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.650\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.755\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.664\nIoU metric: segm\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.704\n Average Precision  (AP) @&#91; IoU=0.50      | area=   all | maxDets=100 ] = 0.979\n Average Precision  (AP) @&#91; IoU=0.75      | area=   all | maxDets=100 ] = 0.871\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.325\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.488\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.727\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.316\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.748\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.749\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.650\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.673\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.758\nSo after one epoch of training, we obtain a COCO-style mAP of 60.6, and a mask mAP of 70.4.\nAfter training for 10 epochs, I got the following metrics\nIoU metric: bbox\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.799\n Average Precision  (AP) @&#91; IoU=0.50      | area=   all | maxDets=100 ] = 0.969\n Average Precision  (AP) @&#91; IoU=0.75      | area=   all | maxDets=100 ] = 0.935\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.349\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.592\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.831\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.324\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.844\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.844\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.400\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.777\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.870\nIoU metric: segm\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.761\n Average Precision  (AP) @&#91; IoU=0.50      | area=   all | maxDets=100 ] = 0.969\n Average Precision  (AP) @&#91; IoU=0.75      | area=   all | maxDets=100 ] = 0.919\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.341\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.464\n Average Precision  (AP) @&#91; IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.788\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.303\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.799\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.799\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.400\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.769\n Average Recall     (AR) @&#91; IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.818\n<\/code><\/pre>\n\n\n\n<p><strong><em>So this was our model on object detection. Hope this helps!<\/em><\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n<figure class=\"wp-block-image size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/June-29-banner-for-GL-computer-vision-1.png\"><a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/computer-vision-essentials\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1000\" height=\"242\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/June-29-banner-for-GL-computer-vision-1.png\" alt=\"\" class=\"wp-image-17202\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/June-29-banner-for-GL-computer-vision-1.png 1000w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/June-29-banner-for-GL-computer-vision-1-300x73.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/June-29-banner-for-GL-computer-vision-1-768x186.png 768w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/June-29-banner-for-GL-computer-vision-1-696x168.png 696w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>What is object detection? Object detection is a computer vision technique in which a software system can detect, locate, and trace the object from a given image or video. The special attribute about object detection is that it identifies the class of object (person, table, chair, etc.) and their location-specific coordinates in the given image. [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":16945,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[2],"tags":[36803,36796],"content_type":[],"class_list":["post-16943","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-artificial-intelligence","tag-opencv","tag-python"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Object Detection in Pytorch | What is Object Detection?<\/title>\n<meta name=\"description\" content=\"TorchVision Object Detection Tutorial: Object detection is a computer vision technique in which a software system can detect, locate, and trace the object from a given image or video.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Object Detection in Pytorch | What is Object Detection?\" \/>\n<meta property=\"og:description\" content=\"TorchVision Object Detection Tutorial: Object detection is a computer vision technique in which a software system can detect, locate, and trace the object from a given image or video.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-09T23:49:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-14T18:52:56+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"700\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/object-detection-in-pytorch\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/object-detection-in-pytorch\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Object Detection in Pytorch | What is Object Detection?\",\"datePublished\":\"2020-09-09T23:49:00+00:00\",\"dateModified\":\"2024-10-14T18:52:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/object-detection-in-pytorch\\\/\"},\"wordCount\":2499,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/object-detection-in-pytorch\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Blog-Featured-Data-pre-processing-1000X700-02.jpg\",\"keywords\":[\"OpenCV\",\"python\"],\"articleSection\":[\"AI and Machine Learning\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/object-detection-in-pytorch\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/object-detection-in-pytorch\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/object-detection-in-pytorch\\\/\",\"name\":\"Object Detection in Pytorch | What is Object Detection?\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/object-detection-in-pytorch\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/object-detection-in-pytorch\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Blog-Featured-Data-pre-processing-1000X700-02.jpg\",\"datePublished\":\"2020-09-09T23:49:00+00:00\",\"dateModified\":\"2024-10-14T18:52:56+00:00\",\"description\":\"TorchVision Object Detection Tutorial: Object detection is a computer vision technique in which a software system can detect, locate, and trace the object from a given image or video.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/object-detection-in-pytorch\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/object-detection-in-pytorch\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/object-detection-in-pytorch\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Blog-Featured-Data-pre-processing-1000X700-02.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Blog-Featured-Data-pre-processing-1000X700-02.jpg\",\"width\":1000,\"height\":700,\"caption\":\"object detection\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/object-detection-in-pytorch\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"AI and Machine Learning\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/artificial-intelligence\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Object Detection in Pytorch | What is Object Detection?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Object Detection in Pytorch | What is Object Detection?","description":"TorchVision Object Detection Tutorial: Object detection is a computer vision technique in which a software system can detect, locate, and trace the object from a given image or video.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/","og_locale":"en_US","og_type":"article","og_title":"Object Detection in Pytorch | What is Object Detection?","og_description":"TorchVision Object Detection Tutorial: Object detection is a computer vision technique in which a software system can detect, locate, and trace the object from a given image or video.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2020-09-09T23:49:00+00:00","article_modified_time":"2024-10-14T18:52:56+00:00","og_image":[{"width":1000,"height":700,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Object Detection in Pytorch | What is Object Detection?","datePublished":"2020-09-09T23:49:00+00:00","dateModified":"2024-10-14T18:52:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/"},"wordCount":2499,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02.jpg","keywords":["OpenCV","python"],"articleSection":["AI and Machine Learning"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/","url":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/","name":"Object Detection in Pytorch | What is Object Detection?","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02.jpg","datePublished":"2020-09-09T23:49:00+00:00","dateModified":"2024-10-14T18:52:56+00:00","description":"TorchVision Object Detection Tutorial: Object detection is a computer vision technique in which a software system can detect, locate, and trace the object from a given image or video.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02.jpg","width":1000,"height":700,"caption":"object detection"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/object-detection-in-pytorch\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"AI and Machine Learning","item":"https:\/\/www.mygreatlearning.com\/blog\/artificial-intelligence\/"},{"@type":"ListItem","position":3,"name":"Object Detection in Pytorch | What is Object Detection?"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02.jpg",1000,700,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02-300x210.jpg",300,210,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02-768x538.jpg",768,538,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02.jpg",1000,700,false],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02.jpg",1000,700,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02.jpg",1000,700,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02.jpg",640,448,false],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02.jpg",96,67,false],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Data-pre-processing-1000X700-02.jpg",150,105,false]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"What is object detection? Object detection is a computer vision technique in which a software system can detect, locate, and trace the object from a given image or video. The special attribute about object detection is that it identifies the class of object (person, table, chair, etc.) and their location-specific coordinates in the given image.&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/16943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=16943"}],"version-history":[{"count":38,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/16943\/revisions"}],"predecessor-version":[{"id":106822,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/16943\/revisions\/106822"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/16945"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=16943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=16943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=16943"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=16943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}