Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions demos/smart_classroom_demo_gapi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
file (GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
file (GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)

ie_add_sample(NAME smart_classroom_demo
ie_add_sample(NAME smart_classroom_demo_gapi
SOURCES ${SOURCES}
HEADERS ${HEADERS}
INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include"
DEPENDENCIES monitors
OPENCV_DEPENDENCIES highgui)
OPENCV_DEPENDENCIES highgui
OPENCV_DEPENDENCIES gapi)

target_link_libraries(smart_classroom_demo PRIVATE ngraph::ngraph)
target_link_libraries(smart_classroom_demo_gapi PRIVATE ngraph::ngraph)
22 changes: 9 additions & 13 deletions demos/smart_classroom_demo_gapi/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Smart Classroom C++ Demo
# G-API. Smart Classroom C++ Demo

The demo shows an example of joint usage of several neural networks to detect student actions (sitting, standing, raising hand for the `person-detection-action-recognition-0005` model and sitting, writing, raising hand, standing, turned around, lie on the desk for the `person-detection-action-recognition-0006` model) and recognize people by faces in the classroom environment. The demo uses Async API for action and face detection networks. It allows to parallelize execution of face recognition and detection: while face recognition is running on one accelerator, face and action detection could be performed on another. You can use a set of the following pre-trained models with the demo:

Expand Down Expand Up @@ -28,12 +28,12 @@ To recognize faces on a frame, the demo needs a gallery of reference images. Eac

Running the application with the `-h` option yields the following usage message:
```
./smart_classroom_demo -h
./smart_classroom_demo_gapi -h
InferenceEngine:
API version ............ <version>
Build .................. <number>

smart_classroom_demo [OPTION]
smart_classroom_demo_gapi [OPTION]
Options:

-h Print a usage message.
Expand All @@ -44,16 +44,12 @@ Options:
-m_fd '<path>' Required. Path to the Face Detection model (.xml) file.
-m_lm '<path>' Required. Path to the Facial Landmarks Regression Retail model (.xml) file.
-m_reid '<path>' Required. Path to the Face Reidentification Retail model (.xml) file.
-l '<absolute_path>' Optional. For CPU custom layers, if any. Absolute path to a shared library with the kernels implementation.
Or
-c '<absolute_path>' Optional. For GPU custom kernels, if any. Absolute path to an .xml file with the kernels description.
-d_act '<device>' Optional. Specify the target device for Person/Action Detection Retail (the list of available devices is shown below). Default value is CPU. Use "-d HETERO:<comma-separated_devices_list>" format to specify HETERO plugin. The application looks for a suitable plugin for the specified device.
-d_fd '<device>' Optional. Specify the target device for Face Detection Retail (the list of available devices is shown below). Default value is CPU. Use "-d HETERO:<comma-separated_devices_list>" format to specify HETERO plugin. The application looks for a suitable plugin for the specified device.
-d_lm '<device>' Optional. Specify the target device for Landmarks Regression Retail (the list of available devices is shown below). Default value is CPU. Use "-d HETERO:<comma-separated_devices_list>" format to specify HETERO plugin. The application looks for a suitable plugin for the specified device.
-d_reid '<device>' Optional. Specify the target device for Face Reidentification Retail (the list of available devices is shown below). Default value is CPU. Use "-d HETERO:<comma-separated_devices_list>" format to specify HETERO plugin. The application looks for a suitable plugin for the specified device.
-d_act '<device>' Optional. Specify the target device for Person/Action Detection Retail (the list of available devices is shown below). Default value is CPU.
-d_fd '<device>' Optional. Specify the target device for Face Detection Retail (the list of available devices is shown below). Default value is CPU.
-d_lm '<device>' Optional. Specify the target device for Landmarks Regression Retail (the list of available devices is shown below). Default value is CPU.
-d_reid '<device>' Optional. Specify the target device for Face Reidentification Retail (the list of available devices is shown below). Default value is CPU.
-out_v '<path>' Optional. File to write output video with visualization to.
-greedy_reid_matching Optional. Use faster greedy matching algorithm in face reid.
-pc Optional. Enables per-layer performance statistics.
-r Optional. Output Inference results as raw values.
-ad Optional. Output file name to save per-person action statistics in.
-t_ad Optional. Probability threshold for person/action detection.
Expand Down Expand Up @@ -89,15 +85,15 @@ To run the demo, you can use public or pre-trained models. To download the pre-t

Example of a valid command line to run the application with pre-trained models for recognizing students actions:
```sh
./smart_classroom_demo -m_act <path_to_model>/person-detection-action-recognition-0005.xml \
./_smart_classroom_demo_gapi -m_act <path_to_model>/person-detection-action-recognition-0005.xml \
-m_fd <path_to_model>/face-detection-adas-0001.xml \
-i <path_to_video>
```
> **NOTE**: To recognize actions of students, use `person-detection-action-recognition-0005` model for 3 basic actions and `person-detection-action-recognition-0006` model for 6 actions.

Example of a valid command line to run the application for recognizing first raised-hand students:
```sh
./smart_classroom_demo -m_act <path_to_model>/person-detection-raisinghand-recognition-0001.xml \
./smart_classroom_demo_gapi -m_act <path_to_model>/person-detection-raisinghand-recognition-0001.xml \
-a_top <number of first raised-hand students> \
-i <path_to_video>
```
Expand Down
59 changes: 15 additions & 44 deletions demos/smart_classroom_demo_gapi/include/action_detector.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2018-2019 Intel Corporation
// Copyright (C) 2021 Intel Corporation

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For every file coming from the original demo, can you please mention it in the file's header comment?
It'd simplify the review a lot.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased.

// SPDX-License-Identifier: Apache-2.0
//

Expand All @@ -10,8 +10,6 @@

#include <opencv2/core/core.hpp>

#include "cnn.hpp"

/**
* @brief Class for detection with action info
*/
Expand Down Expand Up @@ -50,32 +48,12 @@ struct SSDHead {
SSDHead(int step, const std::vector<cv::Size2f>& anchors) : step(step), anchors(anchors) {}
};
using SSDHeads = std::vector<SSDHead>;

/**
* @brief Config for the Action Detection model
*/
struct ActionDetectorConfig : public CnnConfig {
explicit ActionDetectorConfig(const std::string& path_to_model)
: CnnConfig(path_to_model) {}

/** @brief Name of output blob with location info */
std::string old_loc_blob_name{"mbox_loc1/out/conv/flat"};
/** @brief Name of output blob with detection confidence info */
std::string old_det_conf_blob_name{"mbox_main_conf/out/conv/flat/softmax/flat"};
/** @brief Prefix of name of output blob with action confidence info */
std::string old_action_conf_blob_name_prefix{"out/anchor"};
/** @brief Name of output blob with priorbox info */
std::string old_priorbox_blob_name{"mbox/priorbox"};

/** @brief Name of output blob with location info */
std::string new_loc_blob_name{"ActionNet/out_detection_loc"};
/** @brief Name of output blob with detection confidence info */
std::string new_det_conf_blob_name{"ActionNet/out_detection_conf"};
/** @brief Prefix of name of output blob with action confidence info */
std::string new_action_conf_blob_name_prefix{"ActionNet/action_heads/out_head_"};
/** @brief Suffix of name of output blob with action confidence info */
std::string new_action_conf_blob_name_suffix{"_anchor_"};

struct ActionDetectorConfig {
/** @brief Person detection action recognition 0006 network enable flag */
bool net_with_six_actions = false;
/** @brief Scale parameter for Soft-NMS algorithm */
float nms_sigma = 0.6f;
/** @brief Threshold for detected objects */
Expand All @@ -96,8 +74,10 @@ struct ActionDetectorConfig : public CnnConfig {
std::vector<int> new_anchors{1, 4};
/** @brief Number of actions to detect */
size_t num_action_classes = 3;
/** @brief Async execution flag */
bool is_async = true;
/** @brief Input image size height*/
int input_height = 0;
/** @brief Input image size width*/
int input_width = 0;
/** @brief SSD bbox encoding variances */
float variances[4]{0.1f, 0.1f, 0.2f, 0.2f};
SSDHeads new_det_heads{{8, {{26.17863728f, 58.670372f}}},
Expand All @@ -107,26 +87,13 @@ struct ActionDetectorConfig : public CnnConfig {
{93.5070856f, 201.107692f}}}};
};


class ActionDetection : public AsyncDetection<DetectedAction>, public BaseCnnDetection {
class ActionDetection {
public:
explicit ActionDetection(const ActionDetectorConfig& config);

void submitRequest() override;
void enqueue(const cv::Mat &frame) override;
void wait() override { BaseCnnDetection::wait(); }
void printPerformanceCounts(const std::string &fullDeviceName) override {
BaseCnnDetection::printPerformanceCounts(fullDeviceName);
}
DetectedActions fetchResults() override;

DetectedActions fetchResults(const std::vector<cv::Mat> &ssd_results, const cv::Mat &in_frame);
private:
ActionDetectorConfig config_;
InferenceEngine::ExecutableNetwork net_;
std::string input_name_;
InferenceEngine::BlobMap outputs_;

int enqueued_frames_ = 0;
float width_ = 0;
float height_ = 0;
bool new_network_ = false;
Expand Down Expand Up @@ -204,7 +171,7 @@ class ActionDetection : public AsyncDetection<DetectedAction>, public BaseCnnDet
* @brief Carry out Soft Non-Maximum Suppression algorithm under detected actions
*
* @param detections Detected actions
* @param sigma Scale parameter
* @param sigma Scale paramter
* @param top_k Number of top-score bboxes
* @param min_det_conf Minimum detection confidence
* @param out_indices Out indices of valid detections
Expand All @@ -215,3 +182,7 @@ class ActionDetection : public AsyncDetection<DetectedAction>, public BaseCnnDet
const float min_det_conf,
std::vector<int>* out_indices) const;
};

struct ActionDetectionKernelInput {
std::shared_ptr<ActionDetection> ptr;
};
2 changes: 1 addition & 1 deletion demos/smart_classroom_demo_gapi/include/actions.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2018-2019 Intel Corporation
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased.

//

Expand Down
160 changes: 0 additions & 160 deletions demos/smart_classroom_demo_gapi/include/cnn.hpp

This file was deleted.

Loading