- dev_update_off ()
- query_available_dl_devices (['runtime', 'runtime'], ['gpu', 'cpu'], DLDeviceHandles)
- if (|DLDeviceHandles| == 0)
- throw ('No supported device found to continue this example.')
- endif
- DLDevice := DLDeviceHandles[0]
- PreprocessParamFileName := 'F:/model/model_训练-241224-113117_dl_preprocess_params.hdict'
- RetrainedModelFileName := 'F:/model/model_训练-241224-113117.hdl'
- BatchSizeInference := 1
- MinConfidence := 0.5
- MaxOverlap := 0.2
- MaxOverlapClassAgnostic := 0.7
- read_dl_model (RetrainedModelFileName, DLModelHandle)
- set_dl_model_param (DLModelHandle, 'batch_size', BatchSizeInference)
- set_dl_model_param (DLModelHandle, 'device', DLDevice)
- set_dl_model_param (DLModelHandle, 'min_confidence', MinConfidence)
- set_dl_model_param (DLModelHandle, 'max_overlap', MaxOverlap)
- set_dl_model_param (DLModelHandle, 'max_overlap_class_agnostic', MaxOverlapClassAgnostic)
- read_dict (PreprocessParamFileName, [], [], DLPreprocessParam)
- get_dl_model_param (DLModelHandle, 'class_names', ClassNames)
- get_dl_model_param (DLModelHandle, 'class_ids', ClassIDs)
- list_files ('F:/新项目1_images','files',ImageFiles)
- for Ind := 0 to |ImageFiles| - 1 by 1
- read_image (Image, ImageFiles[Ind])
- get_image_size(Image, Width, Height)
- gen_dl_samples_from_images (Image, DLSampleBatch)
- preprocess_dl_samples (DLSampleBatch, DLPreprocessParam)
- apply_dl_model (DLModelHandle, DLSampleBatch, [], DLResultBatch)
- dev_display(Image)
- for SampleIndex := 0 to BatchSizeInference - 1 by 1
- DLResult := DLResultBatch[SampleIndex]
- get_dict_tuple (DLResult, 'bbox_row1', BboxRow1)
- get_dict_tuple (DLResult, 'bbox_col1', BboxCol1)
- get_dict_tuple (DLResult, 'bbox_row2', BboxRow2)
- get_dict_tuple (DLResult, 'bbox_col2', BboxCol2)
- get_dict_tuple (DLResult, 'bbox_confidence', BboxConfidences)
- get_dict_tuple (DLResult,'bbox_class_name',classname)
- zoomX := Width / 256.0
- zoomY := Height / 256.0
- BboxRow1 := zoomY * BboxRow1
- BboxCol1 := zoomX * BboxCol1
- BboxRow2 := zoomY * BboxRow2
- BboxCol2 := zoomX * BboxCol2
- gen_rectangle2_contour_xld (BboxRectangle, 0.5 * (BboxRow1 + BboxRow2), 0.5 * (BboxCol1 + BboxCol2),0,0.5 * (BboxCol1 - BboxCol2),0.5 * (BboxRow1 - BboxRow2) )
- dev_display(BboxRectangle)
- dev_disp_text (classname,'image',BboxRow2, BboxCol1,'red', 'box_color', '#ffffff77')
- dev_disp_text (BboxConfidences,'image',BboxRow1, BboxCol1,'black', 'box_color', '#ffffff77')
- dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
- stop ()
- endfor
- endfor
复制代码
|