6int smp_mvad_simple(
const char* model_name,
const char* img_folder,
const FLOAT threshold)
13 FHANDLE* hsrcs = NULL;
15 FLOAT* anomaly_data = NULL;
16 size_t anomaly_data_len;
18 BOOL is_anomaly =
false;
20 FLOAT max_anomaly = .0;
30 printf_s(
"lic : %d\r\n", ret);
34 if (NULL == hmodel) { printf_s(
"failed to create handle\r\n"); }
35 else { printf_s(
"handle created\r\n"); }
39 printf_s(
"load: %d\r\n", ret);
43 printf_s(
"par : %d category=%d\r\n", ret, model_category);
44 if (
MULTI_VIEW_AD != model_category) { printf_s(
"unmatch model"); }
48 printf_s(
"ret : %d backend=%d\r\n", ret, model_backend);
52 printf_s(
"par : %d ch=%d w=%d h=%d\r\n", ret, ch, w, h);
56 printf_s(
"# of views=%d", n_views);
59 hsrcs = (FHANDLE*)fnOAL_calloc(n_views,
sizeof(FHANDLE));
62 printf_s(
"malloc error");
66 for (i_img = 0; i_img < n_views; i_img++) {
67 std::string image_path = std::string(img_folder) + std::to_string(i_img) +
".bmp";
68 ret = fnFIE_load_bmp(image_path.c_str(), &(hsrcs[i_img]), F_COLOR_IMG_TYPE_UC8);
69 printf_s(
"img ( #=%d ): %d\r\n", i_img, ret);
75 printf_s(
"pred: %d\r\n", ret);
78 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, NULL, NULL);
79 printf_s(
" is_anomaly: %d, %s\r\n", ret, (is_anomaly ?
"true" :
"false"));
82 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, NULL, NULL, NULL, &max_anomaly);
83 printf_s(
" max_anomaly: %d, %6e\r\n", ret, max_anomaly);
86 hmap = fnFIE_img_root_alloc(F_IMG_FLOAT, 1, w, h);
88 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, NULL, NULL, &hmap, NULL);
89 printf_s(
" calc_map: %d\r\n", ret);
91 ret = fnFIE_save_bmp(
"map_float.bmp", hmap);
92 printf_s(
" save map: %d\r\n", ret);
96 hmap = fnFIE_img_root_alloc(F_IMG_UC8, 1, w, h);
98 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, NULL, NULL, &hmap, NULL);
99 printf_s(
" calc_map: %d\r\n", ret);
101 ret = fnFIE_save_bmp(
"map_uc8.bmp", hmap);
102 printf_s(
" save map: %d\r\n", ret);
114 for (i_img = 0; i_img < n_views; i_img++) {
115 fnFIE_free_object(hsrcs[i_img]);
119 if (NULL != anomaly_data) { fnOAL_free(anomaly_data); }
120 if (NULL != hmap) { fnFIE_free_object(hmap); }
126int smp_mvad_benchmark(
const char* model_name,
const char* img_folder,
const FLOAT threshold,
const int bench_iter)
129 std::chrono::system_clock::time_point start, end;
131 INT ret = F_ERR_NONE;
135 FHANDLE* hsrcs = NULL;
137 FLOAT* anomaly_data = NULL;
138 size_t anomaly_data_len;
140 BOOL is_anomaly =
false;
142 FLOAT max_anomaly = .0;
149 printf_s(
"lic : %d\r\n", ret);
153 if (NULL == hmodel) { printf_s(
"failed to create handle\r\n"); }
154 else { printf_s(
"handle created\r\n"); }
158 printf_s(
"load: %d\r\n", ret);
162 printf_s(
"par : %d category=%d\r\n", ret, model_category);
163 if (
MULTI_VIEW_AD != model_category) { printf_s(
"unmatch model"); }
167 printf_s(
"par : %d ch=%d w=%d h=%d\r\n", ret, ch, w, h);
171 printf_s(
"# of views=%d", n_views);
174 hsrcs = (FHANDLE*)fnOAL_calloc(n_views,
sizeof(FHANDLE));
176 ret = F_ERR_NOMEMORY;
177 printf_s(
"malloc error");
181 for (i_img = 0; i_img < n_views; i_img++) {
182 std::string image_path = std::string(img_folder) + std::to_string(i_img) +
".bmp";
183 ret = fnFIE_load_bmp(image_path.c_str(), &(hsrcs[i_img]), F_COLOR_IMG_TYPE_UC8);
184 printf_s(
"img ( #=%d ): %d\r\n", i_img, ret);
189 hmap = fnFIE_img_root_alloc(F_IMG_FLOAT, 1, w, h);
190 if (NULL == hmap) { printf_s(
"map image: allocation error"); }
195 printf_s(
"--- start ---\r\n");
196 printf_s(
"ret, elapsed[msec], scores\r\n");
198 for (
int i = 0; i < bench_iter; i++) {
202 start = std::chrono::system_clock::now();
207 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, &hmap, &max_anomaly);
210 end = std::chrono::system_clock::now();
212 if (F_ERR_NONE != ret) {
213 printf_s(
"pred. err: %d\r\n", ret);
218 elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / (double)1000;
221 printf_s(
"%04d, %.3e, %s, %.6e\r\n", i, elapsed, (is_anomaly ?
"anomaly" :
"normal"), max_anomaly);
223 printf_s(
"--- finish ---\r\n");
235 for (i_img = 0; i_img < n_views; i_img++) {
236 fnFIE_free_object(hsrcs[i_img]);
240 if (NULL != anomaly_data) { fnOAL_free(anomaly_data); }
241 if (NULL != hmap) { fnFIE_free_object(hmap); }
246int smp_mvad_with_fie(
const char* model_name,
const char* img_folder,
const FLOAT threshold)
248 INT ret = F_ERR_NONE;
256 FHANDLE* hsrcs = NULL;
257 FHANDLE* hfiltereds = NULL;
262 FLOAT* anomaly_data = NULL;
263 size_t anomaly_data_len;
264 BOOL is_anomaly =
false;
265 FLOAT max_anomaly = .0;
273 printf_s(
"lic : %d\r\n", ret);
277 if (NULL == hmodel) { printf_s(
"failed to create handle\r\n"); }
278 else { printf_s(
"handle created\r\n"); }
282 printf_s(
"load: %d\r\n", ret);
286 printf_s(
"par : %d category=%d\r\n", ret, model_category);
287 if (
MULTI_VIEW_AD != model_category) { printf_s(
"unmatch model"); }
291 printf_s(
"par : %d ch=%d w=%d h=%d\r\n", ret, ch, w, h);
295 printf_s(
"# of views=%d", n_views);
298 hsrcs = (FHANDLE*)fnOAL_calloc(n_views,
sizeof(FHANDLE));
300 ret = F_ERR_NOMEMORY;
301 printf_s(
"malloc error");
305 for (i_img = 0; i_img < n_views; i_img++) {
306 std::string image_path = std::string(img_folder) + std::to_string(i_img) +
".bmp";
307 ret = fnFIE_load_bmp(image_path.c_str(), &(hsrcs[i_img]), F_COLOR_IMG_TYPE_UC8);
308 printf_s(
"img ( #=%d ): %d\r\n", i_img, ret);
318 printf_s(
"pred(original): %d\r\n", ret);
320 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, NULL, &max_anomaly);
321 printf_s(
"postproc(original): %d %s, %.6e\r\n", ret, (is_anomaly ?
"anomaly" :
"normal"), max_anomaly);
328 hfiltereds = (FHANDLE*)fnOAL_calloc(n_views,
sizeof(FHANDLE));
330 ret = F_ERR_NOMEMORY;
331 printf_s(
"malloc error ( filtered images )");
335 for (i_img = 0; i_img < n_views; i_img++) {
336 FHANDLE hsrc = hsrcs[i_img];
337 FHANDLE hdst = hfiltereds[i_img];
338 ret = fnFIE_average(hsrc, hdst, 0, 0);
339 if (F_ERR_NONE != ret) {
goto finally; }
345 printf_s(
"pred(original): %d\r\n", ret);
347 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, NULL, &max_anomaly);
348 printf_s(
"postproc(original): %d %s, %.6e\r\n", ret, (is_anomaly ?
"anomaly" :
"normal"), max_anomaly);
358 for (i_img = 0; i_img < n_views; i_img++) {
359 fnFIE_free_object(hsrcs[i_img]);
363 if (NULL != hfiltereds) {
365 for (i_img = 0; i_img < n_views; i_img++) {
366 fnFIE_free_object(hfiltereds[i_img]);
368 fnOAL_free(hfiltereds);
370 if (NULL != anomaly_data) { fnOAL_free(anomaly_data); }
INT FVALGAPI fnPDL_get_input_image_size(const H_MODEL hmodel, INT *channels, INT *width, INT *height)
モデルパラメータの取得
Definition: prediction_cpp.cpp:1680
INT FVALGAPI fnPDL_get_model_backend(const H_MODEL hmodel, MODEL_BACKEND *model_backend)
モデルのバックエンドの取得
Definition: prediction_cpp.cpp:1659
MODEL_CATEGORY
モデルの種別
Definition: fv_pdl.h:46
INT fnPDL_check_license()
ライセンス確認
Definition: check_licence.cpp:158
MODEL_BACKEND
推論バックエンド
Definition: fv_pdl.h:30
INT FVALGAPI fnPDL_get_model_category(const H_MODEL hmodel, MODEL_CATEGORY *model_category)
モデルの種別の取得
Definition: prediction_cpp.cpp:1628
INT FVALGAPI fnPDL_get_how_many_views(const H_MODEL hmodel, INT *num_views)
モデルパラメータの取得
Definition: prediction_cpp.cpp:1704
INT FVALGAPI fnPDL_postproc_ad(const H_MODEL hmodel, const FLOAT *anomaly_data, const size_t num_scores, const FLOAT threshold, BOOL *is_anomaly, FHANDLE *hmap, FLOAT *max_anomaly)
推論結果の加工 ( アノマリー検出 )
Definition: prediction_cpp.cpp:2084
INT FVALGAPI fnPDL_predict_multi_images(const H_MODEL hmodel, INT num_images, FHANDLE *hsrcs, FLOAT **scores, size_t *num_scores)
推論の実行 ( 多視点画像分類、多視点アノマリー検出 )
Definition: prediction_cpp.cpp:1937
VOID FVALGAPI fnPDL_dispose(H_MODEL hmodel)
モデルハンドルの解放
Definition: prediction_cpp.cpp:2110
INT FVALGAPI fnPDL_load_model(const CHAR *filename, H_MODEL hmodel)
モデルの読み込み
Definition: prediction_cpp.cpp:1501
VOID * H_MODEL
モデルハンドル
Definition: fv_pdl.h:18
H_MODEL *FVALGAPI fnPDL_create_handle()
モデルハンドルの生成
Definition: prediction_cpp.cpp:1446
@ MULTI_VIEW_AD
Definition: fv_pdl.h:56