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);
26 printf_s(
"lic : %d\r\n", ret);
30 if (NULL == hmodel) { printf_s(
"failed to create handle\r\n"); }
31 else { printf_s(
"handle created\r\n"); }
35 printf_s(
"load: %d\r\n", ret);
39 printf_s(
"par : %d category=%d\r\n", ret, model_category);
44 printf_s(
"ret : %d backend=%d\r\n", ret, model_backend);
48 printf_s(
"par : %d ch=%d w=%d h=%d\r\n", ret, ch, w, h);
59 hdst = fnFIE_img_root_alloc(F_IMG_US16, 2, w, h);
60 if (NULL == hdst) { printf_s(
"hdst allocation error"); }
64 printf_s(
"pred: %d\r\n", ret);
65 if (F_ERR_NONE == ret) {
67 DOUBLE* maxs = (DOUBLE*)fnOAL_calloc(
sizeof(DOUBLE), 2);
68 DOUBLE* mins = (DOUBLE*)fnOAL_calloc(
sizeof(DOUBLE), 2);
73 ret = fnFIE_img_minmaxdens(hdst, mins, maxs);
76 max_cate_id = (INT)maxs[0];
78 if (0 == max_cate_id) { printf_s(
"all pixels are background"); }
80 else { printf_s(
"there are some masks, largest category id = %d\r\n", max_cate_id); }
81 if (NULL != maxs) { fnOAL_free(maxs); }
82 if (NULL != mins) { fnOAL_free(mins); }
85 instance_num = (INT)maxs[1];
86 printf_s(
"there are %d masks", instance_num);
95 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
96 if (NULL != hdst) { fnFIE_free_object(hdst); }
102int smp_panseg_benchmark(
const char* model_name,
const char* img_name,
const int bench_iter)
105 std::chrono::system_clock::time_point start, end;
107 INT ret = F_ERR_NONE;
117 ret = fnFIE_load_img_file(img_name, &hsrc, F_COLOR_IMG_TYPE_UC8);
118 printf_s(
"img: %d\r\n", ret);
119 if (F_ERR_NONE != ret) {
goto finally; }
123 printf_s(
"lic : %d\r\n", ret);
127 if (NULL == hmodel) { printf_s(
"failed to create handle\r\n"); }
128 else { printf_s(
"handle created\r\n"); }
132 printf_s(
"load: %d\r\n", ret);
136 printf_s(
"par : %d category=%d\r\n", ret, model_category);
140 hdst = fnFIE_img_root_alloc(F_IMG_US16, 2, fnFIE_img_get_width(hsrc), fnFIE_img_get_height(hsrc));
141 if (NULL == hdst) { printf_s(
"hdst allocation error"); }
143 printf_s(
"--- start ---\r\n");
144 printf_s(
"ret, elapsed[msec], scores\r\n");
146 for (
int i = 0; i < bench_iter; i++) {
150 start = std::chrono::system_clock::now();
156 end = std::chrono::system_clock::now();
158 if (F_ERR_NONE != ret) {
159 printf_s(
"pred. err: %d\r\n", ret);
164 elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / (double)1000;
167 printf_s(
"%04d, %.3e\r\n", i, elapsed);
169 printf_s(
"--- finish ---\r\n");
176 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
177 if (NULL != hdst) { fnFIE_free_object(hdst); }
183int smp_panseg_with_fie(
const char* model_name,
const char* img_name,
const INT category_num)
185 INT ret = F_ERR_NONE;
188 FHANDLE hdst_cate = NULL;
189 FHANDLE hdst_inst = NULL;
190 FHANDLE hdst_cate_tmp = NULL;
191 FHANDLE hdst_inst_tmp = NULL;
192 INT instance_num = 0;
193 FHANDLE hmask = NULL;
207 ret = fnFIE_load_img_file(img_name, &hsrc, F_COLOR_IMG_TYPE_UC8);
208 printf_s(
"img: %d\r\n", ret);
214 printf_s(
"lic : %d\r\n", ret);
218 if (NULL == hmodel) { printf_s(
"failed to create handle\r\n");
goto finally; }
219 else { printf_s(
"handle created\r\n"); }
223 printf_s(
"load: %d\r\n", ret);
224 if (F_ERR_NONE != ret) {
goto finally; }
228 printf_s(
"par : %d category=%d\r\n", ret, model_category);
232 hdst = fnFIE_img_root_alloc(F_IMG_US16, 2, w, h);
233 if (NULL == hdst) { printf_s(
"hdst allocation error");
goto finally; }
237 printf_s(
"pred(original): %d\r\n", ret);
238 if (F_ERR_NONE != ret) {
goto finally; }
241 hdst_cate = fnFIE_img_child_alloc_single_ch(hdst, 0, 0, 0, w, h);
242 hdst_inst = fnFIE_img_child_alloc_single_ch(hdst, 1, 0, 0, w, h);
246 maxs = (DOUBLE*)fnOAL_calloc(
sizeof(DOUBLE), 1);
247 mins = (DOUBLE*)fnOAL_calloc(
sizeof(DOUBLE), 1);
248 ret = fnFIE_img_minmaxdens(hdst_inst, mins, maxs);
249 if (F_ERR_NONE != ret) {
goto finally; }
250 instance_num = (INT)maxs[0];
254 hmask = fnFIE_img_root_alloc(F_IMG_BIN, 1, w, h);
255 if (NULL == hdst) { printf_s(
"hmask allocation error");
goto finally; }
259 hdst_cate_tmp = fnFIE_img_root_alloc(F_IMG_BIN, 1, w, h);
260 if (NULL == hdst_cate_tmp) { printf_s(
"hcate_tmp allocation error");
goto finally; }
261 hdst_inst_tmp = fnFIE_img_root_alloc(F_IMG_US16, 1, w, h);
262 if (NULL == hdst_inst_tmp) { printf_s(
"hinst_tmp allocation error");
goto finally; }
265 for (
int i_cate = 1; i_cate <= category_num; i_cate++) {
267 ret = fnFIE_band_threshold(hdst_cate, hdst_cate_tmp, (DOUBLE)i_cate, (DOUBLE)i_cate);
268 if (F_ERR_NONE != ret) {
continue; }
271 ret = fnFIE_img_clear(hdst_inst_tmp, 0);
272 if (F_ERR_NONE != ret) {
continue; }
273 ret = fnFIE_img_mask(hdst_inst, hdst_cate_tmp, hdst_inst_tmp);
274 if (F_ERR_NONE != ret) {
continue; }
277 for (
int i_inst = 0; i_inst <= instance_num; i_inst++) {
278 ret = fnFIE_band_threshold(hdst_inst_tmp, hmask, (DOUBLE)i_inst, (DOUBLE)i_inst);
279 if (F_ERR_NONE != ret) {
continue; }
282 ret = fnFIE_img_minmaxdens(hmask, mins, maxs);
283 if (F_ERR_NONE != ret) {
goto finally; }
284 if (0 == maxs[0]) {
continue; }
294 hdst_cate_tmp = fnFIE_img_root_alloc(F_IMG_US16, 1, w, h);
295 if (NULL == hdst_cate_tmp) { printf_s(
"hcate_tmp allocation error");
goto finally; }
301 for (
int i_inst = 0; i_inst <= instance_num; i_inst++) {
303 ret = fnFIE_band_threshold(hdst_inst, hmask, (DOUBLE)i_inst, (DOUBLE)i_inst);
304 if (F_ERR_NONE != ret) {
continue; }
307 ret = fnFIE_img_clear(hdst_cate_tmp, 0);
308 if (F_ERR_NONE != ret) {
continue; }
309 ret = fnFIE_img_mask(hdst_cate, hmask, hdst_cate_tmp);
310 if (F_ERR_NONE != ret) {
continue; }
313 ret = fnFIE_img_minmaxdens(hdst_cate_tmp, mins, maxs);
314 if (F_ERR_NONE != ret) {
goto finally; }
315 if (0 == maxs[0]) {
continue; }
316 if (category_num < maxs[0]) {
continue; }
329 if (NULL != hsrc) { fnFIE_free_object(hsrc); }
330 if (NULL != hdst) { fnFIE_free_object(hdst); }
331 if (NULL != hdst_cate) { fnFIE_free_object(hdst_cate); }
332 if (NULL != hdst_inst) { fnFIE_free_object(hdst_inst); }
333 if (NULL != hdst_cate_tmp) { fnFIE_free_object(hdst_cate); }
334 if (NULL != hdst_inst_tmp) { fnFIE_free_object(hdst_inst); }
335 if (NULL != hmask) { fnFIE_free_object(hmask); }
336 if (NULL != maxs) { fnOAL_free(maxs); }
337 if (NULL != mins) { fnOAL_free(mins); }
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
VOID FVALGAPI fnPDL_dispose(H_MODEL hmodel)
モデルハンドルの解放
Definition: prediction_cpp.cpp:2110
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:1837
INT FVALGAPI fnPDL_load_model(const CHAR *filename, H_MODEL hmodel)
モデルの読み込み
Definition: prediction_cpp.cpp:1501
INT FVALGAPI fnPDL_predict_segmentation(const H_MODEL hmodel, const FHANDLE hsrc, FHANDLE hdst)
推論の実行 ( セグメンテーション )
Definition: prediction_cpp.cpp:1989
VOID * H_MODEL
モデルハンドル
Definition: fv_pdl.h:18
H_MODEL *FVALGAPI fnPDL_create_handle()
モデルハンドルの生成
Definition: prediction_cpp.cpp:1446
@ SEMANTIC_SEGMENTATION
Definition: fv_pdl.h:58