Phone

+919997782184

Email

support@roboticswithpython.com

Geeks of Coding

Join us on Telegram

Viewing 0 reply threads
  • Author
    Posts
    • #586
      Abhishek TyagiAbhishek Tyagi
      Keymaster

      You can download the following code from the given link :

      https://github.com/AbhishekTyagi404/AWS-Computer-Vision-GluonCV/tree/master/Basics%20GluonCV

       

      #!/usr/bin/env python
      # coding: utf-8
      
      # In[1]:
      
      
      #Image detection ste by step
      import gluoncv as gcv
      import mxnet as mx
      import matplotlib.pyplot as plt
      
      
      # In[45]:
      
      
      image_filepath = 'Desktop/Horse.jpg'
      
      
      # In[46]:
      
      
      image = mx.image.imread('Desktop/Horse.jpg')
      
      
      # In[47]:
      
      
      print('shape:', image.shape)
      print('data_type:', image.dtype)
      print('maximum_value:', image.min().asscalar())
      print('minimum_value:', image.max().asscalar())
      
      
      # In[48]:
      
      
      plt.imshow(image.asnumpy())
      
      
      # In[49]:
      
      
      network = gcv.model_zoo.get_model('yolo3_darknet53_coco' , pretrained=True)
      
      
      # In[50]:
      
      
      #Below command is only for linux users
      #!ls -sh /home/ec2-user/.mxnet/models/yolo3_darkent53_coco*.params
      
      
      # In[51]:
      
      
      #Reshaping Image
      image, chw_image = gcv.data.transforms.presets.yolo.transform_test(image, short=512)
      print('shape:', image.shape)
      print('data_type:', image.dtype)
      print('maximum_value:', image.min().asscalar())
      print('minimum_value:', image.max().asscalar())
      
      
      # In[52]:
      
      
      plt.imshow(chw_image)
      
      
      # In[53]:
      
      
      #making prediction
      prediction = network(image)
      
      
      # In[54]:
      
      
      type(prediction)
      
      
      # In[55]:
      
      
      for index, array in enumerate(prediction):
          print('#{}shape: {}'.format(index + 1, array.shape))
      
      
      # In[56]:
      
      
      #Unpacking prediction
      prediction = [array[0] for array in prediction]
      class_indicies, probabilities, bounding_boxes=prediction 
      
      
      # In[60]:
      
      
      #here I'm selecting 17 classes that are too much as comapre to given image(as we can see there are 3 horses so k=3 after this it will show -1)
      k=17
      print(class_indicies[:k])
      
      
      # In[58]:
      
      
      network.classes
      
      
      # In[59]:
      
      
      class_index =17
      assert class_index > -1
      print(network.classes[class_index])
      
      
      # In[61]:
      
      
      print(probabilities[:k])
      
      
      # In[62]:
      
      
      #3 objects found so 4x4 matrix
      print(bounding_boxes[:k])
      
      
      # In[67]:
      
      
      gcv.utils.viz.plot_bbox(chw_image,
                               bounding_boxes,
                               probabilities,
                               class_indicies,
                               class_names=network.classes)
      
      
Viewing 0 reply threads
  • You must be logged in to reply to this topic.