5int smp_ad_simple(
const char* model_name,
const char* img_name,
const FLOAT threshold)
13 FLOAT* anomaly_data = NULL;
14 size_t anomaly_data_len;
16 BOOL is_anomaly =
false;
18 FLOAT max_anomaly = .0;
24 ret = fnFIE_load_img_file(img_name, &hsrc, F_COLOR_IMG_TYPE_UC8);
25 printf_s(
"img: %d\r\n", ret);
31 printf_s(
"lic : %d\r\n", ret);
35 if (NULL == hmodel) { printf_s(
"failed to create handle\r\n"); }
36 else { printf_s(
"handle created\r\n"); }
40 printf_s(
"load: %d\r\n", ret);
44 printf_s(
"ret : %d category=%d\r\n", ret, model_category);
49 printf_s(
"ret : %d backend=%d\r\n", ret, model_backend);
53 printf_s(
"par : %d ch=%d w=%d h=%d\r\n", ret, ch, w, h);
56 ret =
fnPDL_predict(hmodel, hsrc, &anomaly_data, &anomaly_data_len);
57 printf_s(
"pred: %d\r\n", ret);
60 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, NULL, NULL);
61 printf_s(
" is_anomaly: %d, %s\r\n", ret, (is_anomaly ?
"true" :
"false"));
64 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, NULL, NULL, NULL, &max_anomaly);
65 printf_s(
" max_anomaly: %d, %6e\r\n", ret, max_anomaly);
68 hmap = fnFIE_img_root_alloc(F_IMG_FLOAT, 1, w, h);
70 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, NULL, NULL, &hmap, NULL);
71 printf_s(
" calc_map: %d\r\n", ret);
73 ret = fnFIE_save_bmp(
"map_float.bmp", hmap);
74 printf_s(
" save map: %d\r\n", ret);
78 hmap = fnFIE_img_root_alloc(F_IMG_UC8, 1, w, h);
80 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, NULL, NULL, &hmap, NULL);
81 printf_s(
" calc_map: %d\r\n", ret);
83 ret = fnFIE_save_bmp(
"map_uc8.bmp", hmap);
84 printf_s(
" save map: %d\r\n", ret);
93 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
94 if (NULL != anomaly_data) { fnOAL_free(anomaly_data); }
95 if (NULL != hmap) { fnFIE_free_object(hmap); }
101int smp_ad_benchmark(
const char* model_name,
const char* img_name,
const FLOAT threshold,
const int bench_iter)
104 std::chrono::system_clock::time_point start, end;
106 INT ret = F_ERR_NONE;
111 FLOAT* anomaly_data = NULL;
112 size_t anomaly_data_len;
114 BOOL is_anomaly =
false;
116 FLOAT max_anomaly = .0;
122 ret = fnFIE_load_img_file(img_name, &hsrc, F_COLOR_IMG_TYPE_UC8);
123 printf_s(
"img: %d\r\n", ret);
124 if (F_ERR_NONE != ret) {
goto finally; }
128 printf_s(
"lic : %d\r\n", ret);
132 if (NULL == hmodel) { printf_s(
"failed to create handle\r\n"); }
133 else { printf_s(
"handle created\r\n"); }
137 printf_s(
"load: %d\r\n", ret);
141 printf_s(
"par : %d category=%d\r\n", ret, model_category);
146 printf_s(
"par : %d ch=%d w=%d h=%d\r\n", ret, ch, w, h);
149 hmap = fnFIE_img_root_alloc(F_IMG_FLOAT, 1, w, h);
150 if (NULL == hmap) { printf_s(
"map image: allocation error"); }
152 printf_s(
"--- start ---\r\n");
153 printf_s(
"ret, elapsed[msec], scores\r\n");
155 for (
int i = 0; i < bench_iter; i++) {
159 start = std::chrono::system_clock::now();
162 ret =
fnPDL_predict(hmodel, hsrc, &anomaly_data, &anomaly_data_len);
164 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, &hmap, &max_anomaly);
167 end = std::chrono::system_clock::now();
169 if (F_ERR_NONE != ret) {
170 printf_s(
"pred. err: %d\r\n", ret);
175 elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / (double)1000;
178 printf_s(
"%04d, %.3e, %s, %.6e\r\n", i, elapsed, (is_anomaly?
"anomaly":
"normal"), max_anomaly);
180 printf_s(
"--- finish ---\r\n");
187 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
188 if (NULL != anomaly_data) { fnOAL_free(anomaly_data); }
189 if (NULL != hmap) { fnFIE_free_object(hmap); }
195int smp_ad_with_fie(
const char* model_name,
const char* img_name,
const FLOAT threshold)
197 INT ret = F_ERR_NONE;
201 FLOAT* anomaly_data = NULL;
202 size_t anomaly_data_len;
204 BOOL is_anomaly =
false;
205 FLOAT max_anomaly = .0;
207 FHANDLE hfiltered = NULL;
215 ret = fnFIE_load_img_file(img_name, &hsrc, F_COLOR_IMG_TYPE_UC8);
216 printf_s(
"img: %d\r\n", ret);
222 printf_s(
"lic : %d\r\n", ret);
226 if (NULL == hmodel) { printf_s(
"failed to create handle\r\n"); }
227 else { printf_s(
"handle created\r\n"); }
231 printf_s(
"load: %d\r\n", ret);
235 printf_s(
"par : %d category=%d\r\n", ret, model_category);
243 ret =
fnPDL_predict(hmodel, hsrc, &anomaly_data, &anomaly_data_len);
244 printf_s(
"pred(original): %d\r\n", ret);
246 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, NULL, &max_anomaly);
247 printf_s(
"postproc(original): %d %s, %.6e\r\n", ret, (is_anomaly ?
"anomaly" :
"normal"), max_anomaly);
254 ret = fnFIE_img_get_params(hsrc, &ch, &type, &step, &w, &h);
255 if (F_ERR_NONE != ret) {
goto finally; }
256 hfiltered = fnFIE_img_root_alloc(type, ch, w, h);
257 if (NULL == hfiltered) { ret = F_ERR_NOMEMORY;
goto finally; }
258 ret = fnFIE_average(hsrc, hfiltered, 0, 0);
259 if (F_ERR_NONE != ret) {
goto finally; }
262 ret =
fnPDL_predict(hmodel, hfiltered, &anomaly_data, &anomaly_data_len);
263 printf_s(
"pred(original): %d\r\n", ret);
265 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, NULL, &max_anomaly);
266 printf_s(
"postproc(original): %d %s, %.6e\r\n", ret, (is_anomaly ?
"anomaly" :
"normal"), max_anomaly);
275 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
276 if (NULL != anomaly_data) { fnOAL_free(anomaly_data); }
277 if (NULL != hfiltered) { fnFIE_free_object(hfiltered); }
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_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
VOID FVALGAPI fnPDL_dispose(H_MODEL hmodel)
モデルハンドルの解放
Definition: prediction_cpp.cpp:2110
INT FVALGAPI fnPDL_predict(const H_MODEL hmodel, const FHANDLE hsrc, FLOAT **scores, size_t *num_scores)
推論の実行
Definition: prediction_cpp.cpp:1881
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
@ ANOMALY_DETECTION
Definition: fv_pdl.h:52