5int smp_panseg_simple(
const char* model_name,
const char* img_name)
19 ret = fnFIE_load_img_file(img_name, &hsrc, F_COLOR_IMG_TYPE_UC8);
20 printf_s(
"img: %d\r\n", ret);
21 if (F_ERR_NONE != ret) {
goto finally; }
27 printf_s(
"lic : %d\r\n", ret);
28 if (F_ERR_NONE != ret) {
goto finally; }
34 printf_s(
"failed to create handle\r\n");
37 else { printf_s(
"handle created\r\n"); }
41 printf_s(
"load: %d\r\n", ret);
42 if (F_ERR_NONE != ret) {
goto finally; }
46 printf_s(
"par : %d category=%d\r\n", ret, model_category);
47 if (F_ERR_NONE != ret) {
goto finally; }
49 ret = F_ERR_INVALID_OBJECT;
50 printf_s(
"unmatch model\r\n");
56 printf_s(
"ret : %d backend=%d\r\n", ret, model_backend);
57 if (F_ERR_NONE != ret) {
goto finally; }
61 printf_s(
"par : %d ch=%d w=%d h=%d\r\n", ret, ch, w, h);
62 if (F_ERR_NONE != ret) {
goto finally; }
71 if (F_ERR_NONE != ret) {
goto finally; }
74 hdst = fnFIE_img_root_alloc(F_IMG_US16, 2, w, h);
77 printf_s(
"hdst allocation error\r\n");
83 printf_s(
"pred: %d\r\n", ret);
84 if (F_ERR_NONE != ret) {
goto finally; }
87 DOUBLE maxs[2] = {0, 0};
88 DOUBLE mins[2] = {0, 0};
93 ret = fnFIE_img_minmaxdens(hdst, mins, maxs);
94 if (F_ERR_NONE != ret) {
goto finally; }
97 max_cate_id = (INT)maxs[0];
99 if (0 == max_cate_id) { printf_s(
"all pixels are background\r\n"); }
101 else { printf_s(
"there are some masks, largest category id = %d\r\n", max_cate_id); }
104 instance_num = (INT)maxs[1];
105 printf_s(
"there are %d masks\r\n", instance_num);
116 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
117 if (NULL != hdst) { fnFIE_free_object(hdst); }
123int smp_panseg_benchmark(
const char* model_name,
const char* img_name,
const int bench_iter)
126 std::chrono::system_clock::time_point start, end;
128 INT ret = F_ERR_NONE;
138 ret = fnFIE_load_img_file(img_name, &hsrc, F_COLOR_IMG_TYPE_UC8);
139 printf_s(
"img: %d\r\n", ret);
140 if (F_ERR_NONE != ret) {
goto finally; }
144 printf_s(
"lic : %d\r\n", ret);
145 if (F_ERR_NONE != ret) {
goto finally; }
149 if (NULL == hmodel) {
150 ret = F_ERR_NOMEMORY;
151 printf_s(
"failed to create handle\r\n");
154 else { printf_s(
"handle created\r\n"); }
158 printf_s(
"load: %d\r\n", ret);
159 if (F_ERR_NONE != ret) {
goto finally; }
163 printf_s(
"par : %d category=%d\r\n", ret, model_category);
164 if (F_ERR_NONE != ret) {
goto finally; }
166 ret = F_ERR_INVALID_OBJECT;
167 printf_s(
"unmatch model\r\n");
172 hdst = fnFIE_img_root_alloc(F_IMG_US16, 2, fnFIE_img_get_width(hsrc), fnFIE_img_get_height(hsrc));
174 ret = F_ERR_NOMEMORY;
175 printf_s(
"hdst allocation error\r\n");
179 printf_s(
"--- start ---\r\n");
180 printf_s(
"ret, elapsed[msec], scores\r\n");
182 for (
int i = 0; i < bench_iter; i++) {
186 start = std::chrono::system_clock::now();
192 end = std::chrono::system_clock::now();
194 if (F_ERR_NONE != ret) {
195 printf_s(
"pred. err: %d\r\n", ret);
200 elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / (double)1000;
203 printf_s(
"%04d, %.3e\r\n", i, elapsed);
205 printf_s(
"--- finish ---\r\n");
213 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
214 if (NULL != hdst) { fnFIE_free_object(hdst); }
220int smp_panseg_with_fie(
const char* model_name,
const char* img_name,
const INT category_num)
222 INT ret = F_ERR_NONE;
225 FHANDLE hdst_cate = NULL;
226 FHANDLE hdst_inst = NULL;
227 FHANDLE hdst_cate_tmp = NULL;
228 FHANDLE hdst_inst_tmp = NULL;
229 INT instance_num = 0;
230 FHANDLE hmask = NULL;
241 ret = fnFIE_load_img_file(img_name, &hsrc, F_COLOR_IMG_TYPE_UC8);
242 printf_s(
"img: %d\r\n", ret);
243 if (F_ERR_NONE != ret) {
goto finally; }
249 printf_s(
"lic : %d\r\n", ret);
250 if (F_ERR_NONE != ret) {
goto finally; }
254 if (NULL == hmodel) {
255 ret = F_ERR_NOMEMORY;
256 printf_s(
"failed to create handle\r\n");
259 else { printf_s(
"handle created\r\n"); }
263 printf_s(
"load: %d\r\n", ret);
264 if (F_ERR_NONE != ret) {
goto finally; }
268 printf_s(
"par : %d category=%d\r\n", ret, model_category);
269 if (F_ERR_NONE != ret) {
goto finally; }
271 ret = F_ERR_INVALID_OBJECT;
272 printf_s(
"unmatch model\r\n");
277 ret = fnFIE_img_get_params(hsrc, &ch, &type, &step, &w, &h);
278 if (F_ERR_NONE != ret) {
goto finally; }
279 hdst = fnFIE_img_root_alloc(F_IMG_US16, 2, w, h);
281 ret = F_ERR_NOMEMORY;
282 printf_s(
"hdst allocation error\r\n");
288 printf_s(
"pred: %d\r\n", ret);
289 if (F_ERR_NONE != ret) {
goto finally; }
292 hdst_cate = fnFIE_img_child_alloc_single_ch(hdst, 0, 0, 0, w, h);
293 if (NULL == hdst_cate) {
294 ret = F_ERR_NOMEMORY;
295 printf_s(
"child image allocation error\r\n");
298 hdst_inst = fnFIE_img_child_alloc_single_ch(hdst, 1, 0, 0, w, h);
299 if (NULL == hdst_inst) {
300 ret = F_ERR_NOMEMORY;
301 printf_s(
"child image allocation error\r\n");
307 DOUBLE maxs[1] = {0};
308 DOUBLE mins[1] = {0};
309 ret = fnFIE_img_minmaxdens(hdst_inst, mins, maxs);
310 if (F_ERR_NONE != ret) {
goto finally; }
311 instance_num = (INT)maxs[0];
315 hmask = fnFIE_img_root_alloc(F_IMG_BIN, 1, w, h);
317 ret = F_ERR_NOMEMORY;
318 printf_s(
"hmask allocation error\r\n");
324 DOUBLE maxs[1] = {0};
325 DOUBLE mins[1] = {0};
327 hdst_cate_tmp = fnFIE_img_root_alloc(F_IMG_BIN, 1, w, h);
328 if (NULL == hdst_cate_tmp) {
329 ret = F_ERR_NOMEMORY;
330 printf_s(
"hdst_cate_tmp allocation error\r\n");
333 hdst_inst_tmp = fnFIE_img_root_alloc(F_IMG_US16, 1, w, h);
334 if (NULL == hdst_inst_tmp) {
335 ret = F_ERR_NOMEMORY;
336 printf_s(
"hdst_inst_tmp allocation error\r\n");
341 for (
int i_cate = 1; i_cate <= category_num; i_cate++) {
343 ret = fnFIE_band_threshold(hdst_cate, hdst_cate_tmp, (DOUBLE)i_cate, (DOUBLE)i_cate);
344 if (F_ERR_NONE != ret) {
continue; }
347 ret = fnFIE_img_clear(hdst_inst_tmp, 0);
348 if (F_ERR_NONE != ret) {
continue; }
349 ret = fnFIE_img_mask(hdst_inst, hdst_cate_tmp, hdst_inst_tmp);
350 if (F_ERR_NONE != ret) {
continue; }
353 for (
int i_inst = 1; i_inst <= instance_num; i_inst++) {
354 ret = fnFIE_band_threshold(hdst_inst_tmp, hmask, (DOUBLE)i_inst, (DOUBLE)i_inst);
355 if (F_ERR_NONE != ret) {
continue; }
356 printf_s(
"category=%d, instance=%d: hmask written\r\n", i_cate, i_inst);
359 ret = fnFIE_img_minmaxdens(hmask, mins, maxs);
360 if (F_ERR_NONE != ret) {
continue; }
361 if (0 == maxs[0]) {
continue; }
371 DOUBLE maxs[1] = {0};
372 DOUBLE mins[1] = {0};
374 hdst_cate_tmp = fnFIE_img_root_alloc(F_IMG_US16, 1, w, h);
375 if (NULL == hdst_cate_tmp) {
376 ret = F_ERR_NOMEMORY;
377 printf_s(
"hcate_tmp allocation error\r\n");
385 for (
int i_inst = 1; i_inst <= instance_num; i_inst++) {
387 ret = fnFIE_band_threshold(hdst_inst, hmask, (DOUBLE)i_inst, (DOUBLE)i_inst);
388 if (F_ERR_NONE != ret) {
continue; }
391 ret = fnFIE_img_clear(hdst_cate_tmp, 0);
392 if (F_ERR_NONE != ret) {
continue; }
393 ret = fnFIE_img_mask(hdst_cate, hmask, hdst_cate_tmp);
394 if (F_ERR_NONE != ret) {
continue; }
395 printf_s(
"instance=%d: hmask written\r\n", i_inst);
398 ret = fnFIE_img_minmaxdens(hdst_cate_tmp, mins, maxs);
399 if (F_ERR_NONE != ret) {
continue; }
400 if (0 == maxs[0]) {
continue; }
401 if (category_num < maxs[0]) {
continue; }
415 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
416 if (NULL != hdst) { fnFIE_free_object(hdst); }
417 if (NULL != hdst_cate) { fnFIE_free_object(hdst_cate); }
418 if (NULL != hdst_inst) { fnFIE_free_object(hdst_inst); }
419 if (NULL != hdst_cate_tmp) { fnFIE_free_object(hdst_cate_tmp); }
420 if (NULL != hdst_inst_tmp) { fnFIE_free_object(hdst_inst_tmp); }
421 if (NULL != hmask) { fnFIE_free_object(hmask); }
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
VOID FVALGAPI fnPDL_dispose(H_MODEL hmodel)
モデルハンドルの解放
Definition: prediction_cpp.cpp:2556
INT FVALGAPI fnPDL_set_panoptic_deeplab_infer_params(const H_MODEL hmodel, UINT stuff_area, DOUBLE threshold, INT nms_kernel, USHORT request_instance_num)
Panoptic Segmentation の推論パラメータの設定
Definition: prediction_cpp.cpp:2146
INT FVALGAPI fnPDL_load_model(const CHAR *filename, H_MODEL hmodel)
モデルの読み込み
Definition: prediction_cpp.cpp:1810
INT FVALGAPI fnPDL_predict_segmentation(const H_MODEL hmodel, const FHANDLE hsrc, FHANDLE hdst)
推論の実行 ( セグメンテーション )
Definition: prediction_cpp.cpp:2347
VOID * H_MODEL
モデルハンドル
Definition: fv_pdl.h:18
H_MODEL *FVALGAPI fnPDL_create_handle()
モデルハンドルの生成
Definition: prediction_cpp.cpp:1755
@ PANOPTIC_SEGMENTATION
Definition: fv_pdl.h:60