classifyObjects

warning

The document is a continuation of the previous document, if you have landed directly on this page then, Please read from page Get started.

What is classifyObjects component ?#

classifyObjects component is used to classify object from an input image.

  • Description : classifyObjects() takes an input as image in base64 format and N i.e. top N probability of classes with probabilities. Check Input and output parameters for details.
  • Parameters :
    • Input(Via STDIN) : A JSON String with following contents:
      • Input1 : Image (.jpg/.png) in base64 format
      • Input2 : N : Top N class predictions (value between 1 to 1000)
    • Output(Via STDOUT) : A JSON string with following contents
      • For each object in top n
        • Score/Probabillity
        • Index
      • int responseID

List of classifyObjects features in shunya stack#

  1. Set N, get top N predictions
  2. Get class data.

Using classifyObject#

Requirements to use classifyObject#

  1. Shunya OS installed (supported Arm devices) or Shunya OS docker container (X86 based windows/linux devices)
  2. Shunya AI installed in Shunya OS.

Steps to use classifyObject#

  1. Set input image location.
  2. Customize top N prediction value.
  3. Get class data
note

Run the steps given below inside Shunya OS installed (supported Arm devices) or Shunya OS docker container (X86 based windows/linux devices) terminals.

Lets take an example use case: Say we need to

  1. Get top N classes predictions
  2. Get JSON output of classified object.

Steps are

Step 1: Set location of the input image for object classification#

  1. Start with an ready to use template for classifying objects from image.

    git clone https://gitlab.iotiot.in/shunya/products/shunya-ai-examples.git
    cd shunya-ai-examples/indiv-components
  2. Open the examples in a text editor and modify as per your usecase.

    • For CPP you will find the examples in the folder cpp-examples/object-classification/classifyObjects
    • Open the file classify_objects.cpp
    • Modify the line to set the location of the input image
    /* Modify the location of the image to your input image */
    cv::Mat inputImage = cv::imread("../images/f2.jpeg");
    • For Python you will find the examples in the folder python-examples/object-classification/classifyObjects
    • Open the file classify_objects.py
    • Modify the line to set the location of the input image
    # Modify the location of the image to your input image
    img = cv2.imread("images/f2.jpeg")

2. Customize top N prediction value.#

  1. Open the examples in a text editor and modify as per your usecase.

    • For CPP you will find the examples in the folder cpp-examples/object-classification/classifyObjects
    • Open the file classify_objects.cpp
    • Modify the line to set the N.
    /* Replace 1 with your N value */
    nprob.SetString("1");
    • For Python you will find the examples in the folder python-examples/object-classification/classifyObjects
    • Open the file classify_objects.py
    • Modify the line to set N.
    # Replace 1 with your N value
    inputJson['nprob'] = '1'

Step 3: Get class data.#

  1. Once you are done editing, save and run the code, by running

    mkdir build && cd build
    cmake ../
    make
    ./classifyObjectsCpp
    python3 classify_objects.py
  2. Running the codes will print the JSON output on the terminal (to STDOUT).

    For Example:

    • Lets say the input image is

      Oops!, No Image to display.
    • Input JSON is

      {
      "inputImage": "4h32e898473urmcrkd947ryuemcc3x21j98k09754ycmx1k030i1d98754yn==",
      "nprob": "1"
      }
    • Then the JSON output is

      {
      "ClassifiedObjsJSON": [
      {
      "Class0": {
      "Score": 0.45643138885498047,
      "Index": 834
      }
      },
      {
      "responseID": 1606897774
      }
      ]
      }

Related Components to classifyObjects that you may need to complete your application#

  • no related components

Facing errors with the component?#