5int smp_mlcls_simple(
const char* model_name,
const char* img_name)
15 FLOAT score_thresh = 0.5;
16 UINT* result_cls_ids = NULL;
17 FLOAT* result_scores = NULL;
18 size_t num_pred_labels = 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; }
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"); }
41 if (F_ERR_NONE != ret) {
goto finally; }
45 printf_s(
"load: %d\r\n", ret);
46 if (F_ERR_NONE != ret) {
goto finally; }
50 printf_s(
"par : %d category=%d\r\n", ret, model_category);
51 if (F_ERR_NONE != ret) {
goto finally; }
53 ret = F_ERR_INVALID_OBJECT;
54 printf_s(
"unmatch model\r\n");
60 printf_s(
"ret : %d backend=%d\r\n", ret, model_backend);
61 if (F_ERR_NONE != ret) {
goto finally; }
65 printf_s(
"par : %d ch=%d w=%d h=%d\r\n", ret, ch, w, h);
66 if (F_ERR_NONE != ret) {
goto finally; }
70 printf_s(
"pred: %d\r\n", ret);
71 if (F_ERR_NONE != ret) {
goto finally; }
73 hmodel, scores, n_scores, score_thresh, &result_cls_ids, &result_scores, &num_pred_labels
75 printf_s(
"postproc: %d\r\n", ret);
76 if (F_ERR_NONE != ret) {
goto finally; }
77 if (NULL != result_cls_ids && NULL != result_scores) {
79 for (i_result = 0; i_result < num_pred_labels; i_result++) {
80 printf_s(
" label%d: %.6e\r\n", result_cls_ids[i_result], result_scores[i_result]);
89 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
90 if (NULL != scores) { fnOAL_free(scores); }
91 if (NULL != result_cls_ids) { fnOAL_free(result_cls_ids); }
92 if (NULL != result_scores) { fnOAL_free(result_scores); }
99int smp_mlcls_benchmark(
const char* model_name,
const char* img_name,
const int bench_iter)
102 std::chrono::system_clock::time_point start, end;
104 INT ret = F_ERR_NONE;
108 FLOAT* scores = NULL;
110 FLOAT score_thresh = 0.5;
111 UINT* result_cls_ids = NULL;
112 FLOAT* result_scores = NULL;
113 size_t num_pred_labels = 0;
119 ret = fnFIE_load_img_file(img_name, &hsrc, F_COLOR_IMG_TYPE_UC8);
120 printf_s(
"img: %d\r\n", ret);
121 if (F_ERR_NONE != ret) {
goto finally; }
125 printf_s(
"lic : %d\r\n", ret);
126 if (F_ERR_NONE != ret) {
goto finally; }
130 if (NULL == hmodel) {
131 ret = F_ERR_NOMEMORY;
132 printf_s(
"failed to create handle\r\n");
135 else { printf_s(
"handle created\r\n"); }
139 printf_s(
"load: %d\r\n", ret);
140 if (F_ERR_NONE != ret) {
goto finally; }
144 printf_s(
"par : %d category=%d\r\n", ret, model_category);
145 if (F_ERR_NONE != ret) {
goto finally; }
147 ret = F_ERR_INVALID_OBJECT;
148 printf_s(
"unmatch model\r\n");
152 printf_s(
"--- start ---\r\n");
153 printf_s(
"number, elapsed[msec]\r\n");
154 printf_s(
" result(class, score)\r\n");
156 for (
int i = 0; i < bench_iter; i++) {
160 start = std::chrono::system_clock::now();
164 if (F_ERR_NONE != ret) {
165 printf_s(
"pred. err: %d\r\n", ret);
169 hmodel, scores, n_scores, score_thresh, &result_cls_ids, &result_scores, &num_pred_labels
171 if (F_ERR_NONE != ret) {
172 printf_s(
"postproc. err: %d\r\n", ret);
177 end = std::chrono::system_clock::now();
180 elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / (double)1000;
183 printf_s(
"%04d, %.3e\r\n", i, elapsed);
185 if (NULL != result_cls_ids && NULL != result_scores) {
187 for (i_result = 0; i_result < num_pred_labels; i_result++) {
188 printf_s(
" label%d: %.6e\r\n", result_cls_ids[i_result], result_scores[i_result]);
192 if (NULL != result_cls_ids) {
193 fnOAL_free(result_cls_ids);
194 result_cls_ids = NULL;
196 if (NULL != result_scores) {
197 fnOAL_free(result_scores);
198 result_scores = NULL;
201 printf_s(
"--- finish ---\r\n");
208 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
209 if (NULL != scores) { fnOAL_free(scores); }
210 if (NULL != result_cls_ids) { fnOAL_free(result_cls_ids); }
211 if (NULL != result_scores) { fnOAL_free(result_scores); }
218int smp_mlcls_with_fie(
const char* model_name,
const char* img_name)
220 INT ret = F_ERR_NONE;
224 FLOAT* scores = NULL;
226 FLOAT score_thresh = 0.5;
227 UINT* result_cls_ids = NULL;
228 FLOAT* result_scores = NULL;
229 size_t num_pred_labels = 0;
231 FHANDLE hfiltered = NULL;
239 ret = fnFIE_load_img_file(img_name, &hsrc, F_COLOR_IMG_TYPE_UC8);
240 printf_s(
"img: %d\r\n", ret);
241 if (F_ERR_NONE != ret) {
goto finally; }
245 printf_s(
"lic : %d\r\n", ret);
246 if (F_ERR_NONE != ret) {
goto finally; }
250 if (NULL == hmodel) {
251 ret = F_ERR_NOMEMORY;
252 printf_s(
"failed to create handle\r\n");
255 else { printf_s(
"handle created\r\n"); }
259 printf_s(
"load: %d\r\n", ret);
260 if (F_ERR_NONE != ret) {
goto finally; }
264 printf_s(
"par : %d category=%d\r\n", ret, model_category);
265 if (F_ERR_NONE != ret) {
goto finally; }
267 ret = F_ERR_INVALID_OBJECT;
268 printf_s(
"unmatch model\r\n");
278 printf_s(
"pred(original): %d\r\n", ret);
279 if (F_ERR_NONE != ret) {
goto finally; }
281 hmodel, scores, n_scores, score_thresh, &result_cls_ids, &result_scores, &num_pred_labels
283 printf_s(
"postproc(original): %d\r\n", ret);
284 if (F_ERR_NONE != ret) {
goto finally; }
285 if (NULL != result_cls_ids && NULL != result_scores) {
287 for (i_result = 0; i_result < num_pred_labels; i_result++) {
288 printf_s(
" label%d: %.6e\r\n", result_cls_ids[i_result], result_scores[i_result]);
293 if (NULL != result_cls_ids) {
294 fnOAL_free(result_cls_ids);
295 result_cls_ids = NULL;
297 if (NULL != result_scores) {
298 fnOAL_free(result_scores);
299 result_scores = NULL;
307 ret = fnFIE_img_get_params(hsrc, &ch, &type, &step, &w, &h);
308 if (F_ERR_NONE != ret) {
goto finally; }
309 hfiltered = fnFIE_img_root_alloc(type, ch, w, h);
310 if (NULL == hfiltered) { ret = F_ERR_NOMEMORY;
goto finally; }
311 ret = fnFIE_average(hsrc, hfiltered, 0, 0);
312 if (F_ERR_NONE != ret) {
goto finally; }
316 printf_s(
"pred(average): %d\r\n", ret);
317 if (F_ERR_NONE != ret) {
goto finally; }
319 hmodel, scores, n_scores, score_thresh, &result_cls_ids, &result_scores, &num_pred_labels
321 printf_s(
"postproc(average): %d\r\n", ret);
322 if (F_ERR_NONE != ret) {
goto finally; }
323 if (NULL != result_cls_ids && NULL != result_scores) {
325 for (i_result = 0; i_result < num_pred_labels; i_result++) {
326 printf_s(
" label%d: %.6e\r\n", result_cls_ids[i_result], result_scores[i_result]);
335 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
336 if (NULL != hfiltered) { fnFIE_free_object(hfiltered); }
337 if (NULL != scores) { fnOAL_free(scores); }
338 if (NULL != result_cls_ids) { fnOAL_free(result_cls_ids); }
339 if (NULL != result_scores) { fnOAL_free(result_scores); }
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_postproc_multi_label_cls(const H_MODEL hmodel, const FLOAT *scores, const size_t num_scores, const FLOAT threshold, UINT **score_ids, FLOAT **score_values, size_t *num_pred_labels)
推論結果の加工 ( マルチラベル画像分類 )
Definition: prediction_cpp.cpp:2471
INT FVALGAPI fnPDL_get_model_category(const H_MODEL hmodel, MODEL_CATEGORY *model_category)
モデルの種別の取得
Definition: prediction_cpp.cpp:1937
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
@ MULTI_LABEL_CLASSIFICATION
Definition: fv_pdl.h:64