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);
26 if (F_ERR_NONE != ret) {
goto finally; }
32 printf_s(
"lic : %d\r\n", ret);
33 if (F_ERR_NONE != ret) {
goto finally; }
39 printf_s(
"failed to create handle\r\n");
42 else { printf_s(
"handle created\r\n"); }
46 printf_s(
"load: %d\r\n", ret);
47 if (F_ERR_NONE != ret) {
goto finally; }
51 printf_s(
"ret : %d category=%d\r\n", ret, model_category);
52 if (F_ERR_NONE != ret) {
goto finally; }
54 ret = F_ERR_INVALID_OBJECT;
55 printf_s(
"unmatch model\r\n");
61 printf_s(
"ret : %d backend=%d\r\n", ret, model_backend);
62 if (F_ERR_NONE != ret) {
goto finally; }
66 printf_s(
"par : %d ch=%d w=%d h=%d\r\n", ret, ch, w, h);
67 if (F_ERR_NONE != ret) {
goto finally; }
70 ret =
fnPDL_predict(hmodel, hsrc, &anomaly_data, &anomaly_data_len);
71 printf_s(
"pred: %d\r\n", ret);
72 if (F_ERR_NONE != ret) {
goto finally; }
75 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, NULL, NULL);
76 printf_s(
" is_anomaly: %d, %s\r\n", ret, (is_anomaly ?
"true" :
"false"));
77 if (F_ERR_NONE != ret) {
goto finally; }
80 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, NULL, NULL, NULL, &max_anomaly);
81 printf_s(
" max_anomaly: %d, %6e\r\n", ret, max_anomaly);
82 if (F_ERR_NONE != ret) {
goto finally; }
84 FLOAT adrs[1024] = {0};
85 FHANDLE test_org = fnFIE_img_root_import_alloc((VOID**)&adrs, 1, F_IMG_FLOAT, 32, 32, 32);
86 FHANDLE test = fnFIE_img_root_alloc(2, 1, 32, 32);
87 ret = fnFIE_img_copy_ex(test_org, test, 1, 0, 0);
88 FHANDLE test2 = fnFIE_img_root_alloc(2, 1, 34, 34);
89 ret = fnFIE_copy_border(test, test2, 1, 1, F_BORDER_CONTINUOUS, 0);
92 hmap = fnFIE_img_root_alloc(F_IMG_UC8, 1, w, h);
95 printf_s(
"map image: allocation error\r\n");
99 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, NULL, NULL, &hmap, NULL);
100 printf_s(
" calc_map: %d\r\n", ret);
101 if (F_ERR_NONE != ret) {
goto finally; }
103 ret = fnFIE_save_bmp(
"map_uc8.bmp", hmap);
104 printf_s(
" save map: %d\r\n", ret);
105 if (F_ERR_NONE != ret) {
goto finally; }
115 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
116 if (NULL != anomaly_data) { fnOAL_free(anomaly_data); }
117 if (NULL != hmap) { fnFIE_free_object(hmap); }
123int smp_ad_benchmark(
const char* model_name,
const char* img_name,
const FLOAT threshold,
const int bench_iter)
126 std::chrono::system_clock::time_point start, end;
128 INT ret = F_ERR_NONE;
133 FLOAT* anomaly_data = NULL;
134 size_t anomaly_data_len;
136 BOOL is_anomaly =
false;
138 FLOAT max_anomaly = .0;
144 ret = fnFIE_load_img_file(img_name, &hsrc, F_COLOR_IMG_TYPE_UC8);
145 printf_s(
"img: %d\r\n", ret);
146 if (F_ERR_NONE != ret) {
goto finally; }
150 printf_s(
"lic : %d\r\n", ret);
151 if (F_ERR_NONE != ret) {
goto finally; }
155 if (NULL == hmodel) {
156 ret = F_ERR_NOMEMORY;
157 printf_s(
"failed to create handle\r\n");
160 else { printf_s(
"handle created\r\n"); }
164 printf_s(
"load: %d\r\n", ret);
165 if (F_ERR_NONE != ret) {
goto finally; }
169 printf_s(
"par : %d category=%d\r\n", ret, model_category);
170 if (F_ERR_NONE != ret) {
goto finally; }
172 ret = F_ERR_INVALID_OBJECT;
173 printf_s(
"unmatch model\r\n");
179 printf_s(
"par : %d ch=%d w=%d h=%d\r\n", ret, ch, w, h);
180 if (F_ERR_NONE != ret) {
goto finally; }
183 hmap = fnFIE_img_root_alloc(F_IMG_UC8, 1, w, h);
185 ret = F_ERR_NOMEMORY;
186 printf_s(
"map image: allocation error\r\n");
190 printf_s(
"--- start ---\r\n");
191 printf_s(
"ret, elapsed[msec], scores\r\n");
193 for (
int i = 0; i < bench_iter; i++) {
197 start = std::chrono::system_clock::now();
200 ret =
fnPDL_predict(hmodel, hsrc, &anomaly_data, &anomaly_data_len);
201 if (F_ERR_NONE != ret) {
202 printf_s(
"pred. err: %d\r\n", ret);
206 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, &hmap, &max_anomaly);
207 if (F_ERR_NONE != ret) {
208 printf_s(
"postproc. err: %d\r\n", ret);
212 end = std::chrono::system_clock::now();
215 elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / (double)1000;
218 printf_s(
"%04d, %.3e, %s, %.6e\r\n", i, elapsed, (is_anomaly?
"anomaly":
"normal"), max_anomaly);
220 printf_s(
"--- finish ---\r\n");
228 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
229 if (NULL != anomaly_data) { fnOAL_free(anomaly_data); }
230 if (NULL != hmap) { fnFIE_free_object(hmap); }
236int smp_ad_with_fie(
const char* model_name,
const char* img_name,
const FLOAT threshold)
238 INT ret = F_ERR_NONE;
242 FLOAT* anomaly_data = NULL;
243 size_t anomaly_data_len;
245 BOOL is_anomaly =
false;
246 FLOAT max_anomaly = .0;
248 FHANDLE hfiltered = NULL;
256 ret = fnFIE_load_img_file(img_name, &hsrc, F_COLOR_IMG_TYPE_UC8);
257 printf_s(
"img: %d\r\n", ret);
258 if (F_ERR_NONE != ret) {
goto finally; }
264 printf_s(
"lic : %d\r\n", ret);
265 if (F_ERR_NONE != ret) {
goto finally; }
269 if (NULL == hmodel) {
270 ret = F_ERR_NOMEMORY;
271 printf_s(
"failed to create handle\r\n");
274 else { printf_s(
"handle created\r\n"); }
278 printf_s(
"load: %d\r\n", ret);
279 if (F_ERR_NONE != ret) {
goto finally; }
283 printf_s(
"par : %d category=%d\r\n", ret, model_category);
284 if (F_ERR_NONE != ret) {
goto finally; }
286 ret = F_ERR_INVALID_OBJECT;
287 printf_s(
"unmatch model\r\n");
296 ret =
fnPDL_predict(hmodel, hsrc, &anomaly_data, &anomaly_data_len);
297 printf_s(
"pred(original): %d\r\n", ret);
298 if (F_ERR_NONE != ret) {
goto finally; }
300 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, NULL, &max_anomaly);
301 printf_s(
"postproc(original): %d %s, %.6e\r\n", ret, (is_anomaly ?
"anomaly" :
"normal"), max_anomaly);
302 if (F_ERR_NONE != ret) {
goto finally; }
309 ret = fnFIE_img_get_params(hsrc, &ch, &type, &step, &w, &h);
310 if (F_ERR_NONE != ret) {
goto finally; }
311 hfiltered = fnFIE_img_root_alloc(type, ch, w, h);
312 if (NULL == hfiltered) { ret = F_ERR_NOMEMORY;
goto finally; }
313 ret = fnFIE_average(hsrc, hfiltered, 0, 0);
314 if (F_ERR_NONE != ret) {
goto finally; }
317 ret =
fnPDL_predict(hmodel, hfiltered, &anomaly_data, &anomaly_data_len);
318 printf_s(
"pred(original): %d\r\n", ret);
319 if (F_ERR_NONE != ret) {
goto finally; }
321 ret =
fnPDL_postproc_ad(hmodel, anomaly_data, anomaly_data_len, threshold, &is_anomaly, NULL, &max_anomaly);
322 printf_s(
"postproc(original): %d %s, %.6e\r\n", ret, (is_anomaly ?
"anomaly" :
"normal"), max_anomaly);
323 if (F_ERR_NONE != ret) {
goto finally; }
333 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
334 if (NULL != anomaly_data) { fnOAL_free(anomaly_data); }
335 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: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_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
VOID FVALGAPI fnPDL_dispose(H_MODEL hmodel)
モデルハンドルの解放
Definition: prediction_cpp.cpp:2556
INT FVALGAPI fnPDL_predict(const H_MODEL hmodel, const FHANDLE hsrc, FLOAT **scores, size_t *num_scores)
推論の実行
Definition: prediction_cpp.cpp:2239
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
@ ANOMALY_DETECTION
Definition: fv_pdl.h:52