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);
31 if (F_ERR_NONE != ret) {
goto finally; }
37 printf_s(
"failed to create handle\r\n");
40 else { printf_s(
"handle created\r\n"); }
44 printf_s(
"load: %d\r\n", ret);
48 printf_s(
"par : %d category=%d\r\n", ret, model_category);
50 ret = F_ERR_INVALID_OBJECT;
51 printf_s(
"unmatch model\r\n");
57 printf_s(
"ret : %d backend=%d\r\n", ret, model_backend);
61 printf_s(
"par : %d ch=%d w=%d h=%d\r\n", ret, ch, w, h);
65 printf_s(
"# of views=%d\r\n", n_views);
68 hsrcs = (FHANDLE*)fnOAL_calloc(n_views,
sizeof(FHANDLE));
71 printf_s(
"malloc error\r\n");
76 for (i_img = 0; i_img < n_views; i_img++) {
77 std::string image_path = std::string(img_folder) + std::to_string(i_img) +
".bmp";
78 ret = fnFIE_load_bmp(image_path.c_str(), &(hsrcs[i_img]), F_COLOR_IMG_TYPE_UC8);
79 printf_s(
"img ( #=%d ): %d\r\n", i_img, ret);
85 printf_s(
"pred: %d\r\n", ret);
88 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, NULL, NULL);
89 printf_s(
" is_anomaly: %d, %s\r\n", ret, (is_anomaly ?
"true" :
"false"));
92 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, NULL, NULL, NULL, &max_anomaly);
93 printf_s(
" max_anomaly: %d, %6e\r\n", ret, max_anomaly);
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);
115 for (i_img = 0; i_img < n_views; i_img++) {
116 fnFIE_free_object(hsrcs[i_img]);
120 if (NULL != anomaly_data) { fnOAL_free(anomaly_data); }
121 if (NULL != hmap) { fnFIE_free_object(hmap); }
127int smp_mvad_benchmark(
const char* model_name,
const char* img_folder,
const FLOAT threshold,
const int bench_iter)
130 std::chrono::system_clock::time_point start, end;
132 INT ret = F_ERR_NONE;
136 FHANDLE* hsrcs = NULL;
138 FLOAT* anomaly_data = NULL;
139 size_t anomaly_data_len;
141 BOOL is_anomaly =
false;
143 FLOAT max_anomaly = .0;
150 printf_s(
"lic : %d\r\n", ret);
154 if (NULL == hmodel) {
155 ret = F_ERR_NOMEMORY;
156 printf_s(
"failed to create handle\r\n");
159 else { printf_s(
"handle created\r\n"); }
163 printf_s(
"load: %d\r\n", ret);
167 printf_s(
"par : %d category=%d\r\n", ret, model_category);
169 ret = F_ERR_INVALID_OBJECT;
170 printf_s(
"unmatch model\r\n");
176 printf_s(
"par : %d ch=%d w=%d h=%d\r\n", ret, ch, w, h);
180 printf_s(
"# of views=%d\r\n", n_views);
183 hsrcs = (FHANDLE*)fnOAL_calloc(n_views,
sizeof(FHANDLE));
185 ret = F_ERR_NOMEMORY;
186 printf_s(
"malloc error\r\n");
191 for (i_img = 0; i_img < n_views; i_img++) {
192 std::string image_path = std::string(img_folder) + std::to_string(i_img) +
".bmp";
193 ret = fnFIE_load_bmp(image_path.c_str(), &(hsrcs[i_img]), F_COLOR_IMG_TYPE_UC8);
194 printf_s(
"img ( #=%d ): %d\r\n", i_img, ret);
199 hmap = fnFIE_img_root_alloc(F_IMG_UC8, 1, w, h);
201 ret = F_ERR_NOMEMORY;
202 printf_s(
"map image: allocation error\r\n");
208 printf_s(
"--- start ---\r\n");
209 printf_s(
"ret, elapsed[msec], scores\r\n");
211 for (
int i = 0; i < bench_iter; i++) {
215 start = std::chrono::system_clock::now();
220 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, &hmap, &max_anomaly);
223 end = std::chrono::system_clock::now();
225 if (F_ERR_NONE != ret) {
226 printf_s(
"pred. err: %d\r\n", ret);
231 elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / (double)1000;
234 printf_s(
"%04d, %.3e, %s, %.6e\r\n", i, elapsed, (is_anomaly ?
"anomaly" :
"normal"), max_anomaly);
236 printf_s(
"--- finish ---\r\n");
248 for (i_img = 0; i_img < n_views; i_img++) {
249 fnFIE_free_object(hsrcs[i_img]);
253 if (NULL != anomaly_data) { fnOAL_free(anomaly_data); }
254 if (NULL != hmap) { fnFIE_free_object(hmap); }
260int smp_mvad_with_fie(
const char* model_name,
const char* img_folder,
const FLOAT threshold)
262 INT ret = F_ERR_NONE;
270 FHANDLE* hsrcs = NULL;
271 FHANDLE* hfiltereds = NULL;
276 FLOAT* anomaly_data = NULL;
277 size_t anomaly_data_len;
278 BOOL is_anomaly =
false;
279 FLOAT max_anomaly = .0;
287 printf_s(
"lic : %d\r\n", ret);
291 if (NULL == hmodel) {
292 ret = F_ERR_NOMEMORY;
293 printf_s(
"failed to create handle\r\n");
296 else { printf_s(
"handle created\r\n"); }
300 printf_s(
"load: %d\r\n", ret);
304 printf_s(
"par : %d category=%d\r\n", ret, model_category);
306 ret = F_ERR_INVALID_OBJECT;
307 printf_s(
"unmatch model\r\n");
313 printf_s(
"par : %d ch=%d w=%d h=%d\r\n", ret, ch, w, h);
317 printf_s(
"# of views=%d\r\n", n_views);
320 hsrcs = (FHANDLE*)fnOAL_calloc(n_views,
sizeof(FHANDLE));
322 ret = F_ERR_NOMEMORY;
323 printf_s(
"malloc error\r\n");
328 for (i_img = 0; i_img < n_views; i_img++) {
329 std::string image_path = std::string(img_folder) + std::to_string(i_img) +
".bmp";
330 ret = fnFIE_load_bmp(image_path.c_str(), &(hsrcs[i_img]), F_COLOR_IMG_TYPE_UC8);
331 printf_s(
"img ( #=%d ): %d\r\n", i_img, ret);
341 printf_s(
"pred(original): %d\r\n", ret);
343 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, NULL, &max_anomaly);
344 printf_s(
"postproc(original): %d %s, %.6e\r\n", ret, (is_anomaly ?
"anomaly" :
"normal"), max_anomaly);
351 hfiltereds = (FHANDLE*)fnOAL_calloc(n_views,
sizeof(FHANDLE));
353 ret = F_ERR_NOMEMORY;
354 printf_s(
"malloc error ( filtered images )\r\n");
359 for (i_img = 0; i_img < n_views; i_img++) {
360 hfiltereds[i_img] = fnFIE_img_root_alloc(F_IMG_UC8, ch, w, h);
361 if (NULL == hfiltereds[i_img]) {
362 ret = F_ERR_NOMEMORY;
363 printf_s(
"malloc error ( filtered images )\r\n");
370 for (i_img = 0; i_img < n_views; i_img++) {
371 FHANDLE hsrc = hsrcs[i_img];
372 FHANDLE hdst = hfiltereds[i_img];
373 ret = fnFIE_average(hsrc, hdst, 0, 0);
374 if (F_ERR_NONE != ret) {
goto finally; }
380 printf_s(
"pred(average): %d\r\n", ret);
382 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, NULL, &max_anomaly);
383 printf_s(
"postproc(average): %d %s, %.6e\r\n", ret, (is_anomaly ?
"anomaly" :
"normal"), max_anomaly);
393 for (i_img = 0; i_img < n_views; i_img++) {
394 fnFIE_free_object(hsrcs[i_img]);
398 if (NULL != hfiltereds) {
400 for (i_img = 0; i_img < n_views; i_img++) {
401 fnFIE_free_object(hfiltereds[i_img]);
403 fnOAL_free(hfiltereds);
405 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:1989
INT FVALGAPI fnPDL_get_model_backend(const H_MODEL hmodel, MODEL_BACKEND *model_backend)
モデルのバックエンドの取得
Definition: prediction_cpp.cpp:1968
MODEL_CATEGORY
モデルの種別
Definition: fv_pdl.h:46
INT fnPDL_check_license()
ライセンス確認
Definition: check_licence.cpp:160
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:1937
INT FVALGAPI fnPDL_get_how_many_views(const H_MODEL hmodel, INT *num_views)
モデルパラメータの取得
Definition: prediction_cpp.cpp:2013
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:2530
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:2295
VOID FVALGAPI fnPDL_dispose(H_MODEL hmodel)
モデルハンドルの解放
Definition: prediction_cpp.cpp:2556
INT FVALGAPI fnPDL_load_model(const CHAR *filename, H_MODEL hmodel)
モデルの読み込み
Definition: prediction_cpp.cpp:1810
VOID * H_MODEL
モデルハンドル
Definition: fv_pdl.h:18
H_MODEL *FVALGAPI fnPDL_create_handle()
モデルハンドルの生成
Definition: prediction_cpp.cpp:1755
@ MULTI_VIEW_AD
Definition: fv_pdl.h:56