18 #include <unordered_map> 19 #include "fastdeploy/utils/utils.h" 20 #include "fastdeploy/core/fd_tensor.h" 21 #if defined(ENABLE_BENCHMARK) && defined(ENABLE_VISION) 22 #include "fastdeploy/vision/common/result.h" 28 #if defined(ENABLE_BENCHMARK) 31 class FASTDEPLOY_DECL ResourceUsageMonitor {
38 explicit ResourceUsageMonitor(
int sampling_interval_ms,
int gpu_id = 0);
40 ~ResourceUsageMonitor() { StopInternal(); }
47 float GetMaxCpuMem()
const {
48 if (!is_supported_ || check_memory_thd_ ==
nullptr) {
54 float GetMaxGpuMem()
const {
55 if (!is_supported_ || check_memory_thd_ ==
nullptr) {
61 float GetMaxGpuUtil()
const {
62 if (!is_supported_ || check_memory_thd_ ==
nullptr) {
68 ResourceUsageMonitor(ResourceUsageMonitor&) =
delete;
69 ResourceUsageMonitor& operator=(
const ResourceUsageMonitor&) =
delete;
70 ResourceUsageMonitor(ResourceUsageMonitor&&) =
delete;
71 ResourceUsageMonitor& operator=(
const ResourceUsageMonitor&&) =
delete;
76 std::string GetCurrentGpuMemoryInfo(
int device_id);
78 bool is_supported_ =
false;
79 bool stop_signal_ =
false;
80 const int sampling_interval_;
81 float max_cpu_mem_ = 0.0f;
82 float max_gpu_mem_ = 0.0f;
83 float max_gpu_util_ = 0.0f;
84 const int gpu_id_ = 0;
85 std::unique_ptr<std::thread> check_memory_thd_ =
nullptr;
89 FASTDEPLOY_DECL std::string Strip(
const std::string& str,
char ch =
' ');
92 FASTDEPLOY_DECL
void Split(
const std::string& s,
93 std::vector<std::string>& tokens,
97 struct FASTDEPLOY_DECL BaseDiff {};
99 struct FASTDEPLOY_DECL EvalStatis {
105 struct FASTDEPLOY_DECL TensorDiff:
public BaseDiff {
109 #if defined(ENABLE_VISION) 110 struct FASTDEPLOY_DECL DetectionDiff:
public BaseDiff {
116 struct FASTDEPLOY_DECL ClassifyDiff:
public BaseDiff {
121 struct FASTDEPLOY_DECL SegmentationDiff:
public BaseDiff {
126 struct FASTDEPLOY_DECL OCRDetDiff:
public BaseDiff {
130 struct FASTDEPLOY_DECL MattingDiff:
public BaseDiff {
132 EvalStatis foreground;
135 #endif // ENABLE_VISION 136 #endif // ENABLE_BENCHMARK 140 #if defined(ENABLE_BENCHMARK) 141 static bool SaveFDTensor(
const FDTensor& tensor,
const std::string& path);
143 static bool LoadFDTensor(
FDTensor* tensor,
const std::string& path);
145 static TensorDiff CalculateDiffStatis(
const FDTensor& lhs,
148 static void SaveBenchmarkResult(
const std::string& res,
149 const std::string& path);
151 static bool LoadBenchmarkConfig(
const std::string& path,
152 std::unordered_map<std::string, std::string>* config_info);
154 static std::vector<std::vector<int32_t>> GetInputShapes(
155 const std::string& raw_shapes);
156 #if defined(ENABLE_VISION) 159 const std::string& path);
161 const std::string& path);
163 const std::string& path);
165 const std::string& path);
167 const std::string& path);
169 const std::string& path);
170 static bool SaveOCRDetResult(
const std::vector<std::array<int, 8>>& res,
171 const std::string& path);
172 static bool LoadOCRDetResult(std::vector<std::array<int, 8>>* res,
173 const std::string& path);
175 const std::string& path);
177 const std::string& path);
181 const float& score_threshold = 0.3f);
184 static SegmentationDiff CalculateDiffStatis(
187 static OCRDetDiff CalculateDiffStatis(
188 const std::vector<std::array<int, 8>>& lhs,
189 const std::vector<std::array<int, 8>>& rhs);
190 static MattingDiff CalculateDiffStatis(
193 #endif // ENABLE_VISION 194 #endif // ENABLE_BENCHMARK Utils for precision evaluation.
Definition: utils.h:139
Segmentation result structure for all the segmentation models.
Definition: result.h:270
FDTensor object used to represend data matrix.
Definition: fd_tensor.h:31
Detection result structure for all the object detection models and instance segmentation models...
Definition: result.h:106
Classify result structure for all the image classify models.
Definition: result.h:46
Matting result structure for all the Matting models.
Definition: result.h:331
void Split(const FDTensor &x, const std::vector< int > &num_or_sections, std::vector< FDTensor > *out, int axis)
Definition: split.cc:152
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16