Skip to main content

dbFlush

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 dbFlush component ?

dbFlush component is used to delete the face-embeddings database.

  • Description : dbFlush() takes an input(through STDIN) as a file e.g. database.txt and and returns 1 if successfully deleted or return 0. Check Input and output parameters for details.
  • Parameters :
    • Input(Via STDIN) : dbFlush.stdin() << jsonDoc2Text(inputJson) << std::endl;
      • An inputJson String with following parameters:
        • Parameter1 : string database filename
    • Output(Via STDOUT) : dbFlush.stdout() >> outputJson;
      • An outputJson string with following contents
        • 1 if deleted successfully 0 is unsuccessful deletion on database
        • int requestID

List of dbFlush features in shunya stack

  1. Delete database file.

Using dbFlush

Requirements to use dbFlush

  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 dbFlush

  1. Give database filename.
  2. Delete the database.
  3. Verify database deletion
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. Delete the database file

Steps are

Step 1: Give database filename.

  1. Start with an ready to use template for aligning faces 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/face-recognition/dbFlush
    • Open the file db_flush.cpp
    • Modify the line to set the name the database file
    /* Creating inputJson */
    rapidjson::Document inputJson;
    inputJson.SetObject();
    /* Replace file.txt with your database file name */
    /* Adding parameter1 in inputJson file */
    inputJson.AddMember("fname", "file.txt", inputJson.GetAllocator());

Step 2. Call API binary

  1. We will now call API binary by giving input image(parameter1) and face info(parameter2) as an input through STDIN.
    /* Call API binary */
    subprocess::popen dbFlush("/usr/bin/dbFlush", {});
    /* Passing inputJson to the API */
    dbFlush.stdin() << jsonDoc2Text(inputJson) << std::endl;
    dbFlush.close();
    std::string outputJson;
    /* Getting output in outputJson */
    dbFlush.stdout() >> outputJson;
  2. You will get output in outputJson string.

Step 3. Verify database deletion

  1. Code to print the json output, got from dbFlush API.
    /* ---- Parse outputJson  ---- */
    rapidjson::Document dbFlushJson = readJsonString(outputJson);
    int res1 = dbFlushJson["data"]["success"].GetInt();
    if(res1==1) {
    std::cout<<"\nDB cleared";
    } else {
    std::cout<<"\nDB not cleared";
    }

Run ready to use example.

  1. Once you are done editing, save and run the code, by running.
    git clone https://gitlab.iotiot.in/shunya/products/shunya-ai-examples.git
    mkdir build && cd build
    cmake ../
    make
    ./dbFlushCpp
  1. 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

      {
      "fname": "file.txt"
      }
    • Then the JSON output is

      {
      "apiVersion": "1.2.0",
      "requestId": 1606318527,
      "data": {
      "success": 1
      }
      }

This part is not updated yet (please do not use below example)

Understand this component with an example (ready to use code)

  • This is an example for face-recognition and here we will be using 5 components: detectFaces, alignFace, getEmbeddings, sameFace, dbFlush

  • Check this ready to use example in c++ and python

  • Download the code

    git clone https://gitlab.iotiot.in/shunya/products/shunya-ai-examples.git
    cd shunya-ai-examples/cpp-examples/face-recognition
    ```shell git clone https://gitlab.iotiot.in/shunya/products/shunya-ai-examples.git cd shunya-ai-examples/python-examples/face-recognition ```
  • In this folder there is a file, same_face.cpp or same_face.py

  • detectFaces Components used

    subprocess::popen detectFaces("/usr/bin/detectFaces", {});
    ```shell detectFaces = Popen(['/usr/bin/detectFaces'], stdout=PIPE, stdin=PIPE) ```
  • alignFace component used

    subprocess::popen alignFace("/usr/bin/alignFace", {});
    ```shell alignFace = Popen(['/usr/bin/alignFace'], stdout=PIPE, stdin=PIPE) ```
  • getEmbeddings component used

    subprocess::popen getEmbeddings("/usr/bin/getEmbeddings", {});
    ```shell getEmbeddings = Popen(['/usr/bin/getEmbeddings'], stdout=PIPE, stdin=PIPE) ```
  • sameFace component used

    subprocess::popen sameFace("/usr/bin/sameFace", {});
    ```shell sameFace = Popen(['/usr/bin/sameFace'], stdout=PIPE, stdin=PIPE) ```
  • dbFlush component used

    subprocess::popen dbFlush("/usr/bin/dbFlush", {});
    ```shell dbFlush = Popen(['/usr/bin/dbFlush'], stdout=PIPE, stdin=PIPE) ```
  • Run code by yourself

    mkdir build && cd build
    cmake .. && make
    ./sameFaceCpp
    ```shell python3 same_face.py ```
    - You will get "Same faces" and "DB cleared" as an output.

Facing errors with the component?