summaryrefslogtreecommitdiff
path: root/test/testsuites/machine_learning/inference/test_face_detection.cpp
blob: db2f034295c70eeaefc541a225d4f619dc244138 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
 * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include <string>
#include <ImageHelper.h>
#include "test_inference_helper.hpp"

#define FD_TFLITE_WEIGHT_MOBILENET_V1_SSD_300_PATH \
	TEST_RES_PATH                                  \
	"/open_model_zoo/models/FD/tflite/fd_mobilenet_v1_ssd_postop_300x300.tflite"
#define FD_TFLITE_WEIGHT_BLAZEFACE_128_PATH \
	TEST_RES_PATH                           \
	"/open_model_zoo/models/FD/tflite/fd_blazeface_front_128x128.tflite"
#define IMG_FACE  \
	TEST_RES_PATH \
	"/res/inference/images/faceDetection.jpg"

void _face_detected_cb(mv_source_h source, const int number_of_faces, const float *confidences,
					   const mv_rectangle_s *locations, void *user_data)
{
	EXPECT_GT(number_of_faces, 0);
}

class TestFaceDetectionTflite : public TestInference
{
public:
	void inferenceFace()
	{
		TestInference::ConfigureInference();

		ASSERT_EQ(MediaVision::Common::ImageHelper::loadImageToSource(IMG_FACE, mv_source), MEDIA_VISION_ERROR_NONE);
		ASSERT_EQ(mv_inference_face_detect(mv_source, infer, _face_detected_cb, NULL), MEDIA_VISION_ERROR_NONE);
	}
};

TEST_P(TestFaceDetectionTflite, MobilenetV1_SSD)
{
	engine_config_hosted_tflite_model(engine_cfg, FD_TFLITE_WEIGHT_MOBILENET_V1_SSD_300_PATH, NULL, _use_json_parser,
									  _target_device_type);
	if (!_use_json_parser) {
		const char *inputNodeName = "normalized_input_image_tensor";
		const char *outputNodeName[] = { "TFLite_Detection_PostProcess", "TFLite_Detection_PostProcess:1",
										 "TFLite_Detection_PostProcess:2", "TFLite_Detection_PostProcess:3" };

		ASSERT_EQ(mv_engine_config_set_double_attribute(engine_cfg, MV_INFERENCE_MODEL_MEAN_VALUE, 127.5),
				  MEDIA_VISION_ERROR_NONE);
		ASSERT_EQ(mv_engine_config_set_double_attribute(engine_cfg, MV_INFERENCE_MODEL_STD_VALUE, 127.5),
				  MEDIA_VISION_ERROR_NONE);
		ASSERT_EQ(mv_engine_config_set_double_attribute(engine_cfg, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3),
				  MEDIA_VISION_ERROR_NONE);

		ASSERT_EQ(mv_engine_config_set_int_attribute(engine_cfg, MV_INFERENCE_INPUT_TENSOR_WIDTH, 300),
				  MEDIA_VISION_ERROR_NONE);
		ASSERT_EQ(mv_engine_config_set_int_attribute(engine_cfg, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 300),
				  MEDIA_VISION_ERROR_NONE);
		ASSERT_EQ(mv_engine_config_set_int_attribute(engine_cfg, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3),
				  MEDIA_VISION_ERROR_NONE);
		ASSERT_EQ(mv_engine_config_set_string_attribute(engine_cfg, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName),
				  MEDIA_VISION_ERROR_NONE);
		ASSERT_EQ(mv_engine_config_set_array_string_attribute(engine_cfg, MV_INFERENCE_OUTPUT_NODE_NAMES,
															  outputNodeName, 4),
				  MEDIA_VISION_ERROR_NONE);
	}

	inferenceFace();
}

INSTANTIATE_TEST_CASE_P(Prefix, TestFaceDetectionTflite,
						::testing::Values(ParamTypes(false, MV_INFERENCE_TARGET_DEVICE_CPU),
										  ParamTypes(true, MV_INFERENCE_TARGET_DEVICE_CPU)));