NCPU自定義Pre-process和Post-process的範例
在document中提到可以自訂義NCPU的前後處理在user_pre_process.c及user_post_process.c中,但是從kneron plus中並未發現這些檔案,請問是否可以提供範例檔案?
The discussion has been closed due to inactivity. To continue with the topic, please feel free to post a new discussion.
Comments
Hi Richard,
user_pre_process.c和user_post_process.c都在這個路徑: kneron_plus\firmware_development\KL520\firmware\build\solution_kdp2_user_ex\main_ncpu,不過只有KL520的範例,不好意思! 因為KL720的NCPU要用Xtensa Xplorer去修改,會需要下載Xtensa Xplorer並且購買Xtensa Xplorer的license。有Xtensa Xplorer後,可以從kneron_plus/firmware_development/KL720/firmware/build/ncpu_bin去打開project。
Preprocess和postprocess也可以在host端(kneron_plus的程式裡面)寫。Preprocess可以參考kl720_demo_generic_data_inference (先對檔案做preprocess的動作,再去用kp_generic_data_inference_send去做推論),而postprocess可以參考kl720_demo_generic_image_inference_post_yolo。
Update:
KL720的preprocess/postprocess範例檔案,可以參考kneron_plus/firmware_development/KL720/firmware/platform/kl720/ncpu/ncpu_main/src裡的pre_post_proc_template.c
Hi Maria,
我們有keil, 但沒有Xtensa Xplorer的license (基本上不可能購買), 在這個狀況, 我們要如何繼續進行?
Hi Jack,
如果是這樣的話,可以請您跟我們業務聯絡,向業務提想要借Xtensa授權,他可以幫助您安排,謝謝!
Hi Maria,
我們在進行customized inference single model時遇到
inference failed, error = 111 (Device hardware preprocess cannot handle the specified model input size)
之前有詢問過此問題是因為model的input size超出限制,可以使用kp_generic_data_inference_send及kp_generic_data_inference_receive解決,但是如果使用kp_customized_inference_send及kp_customized_inference_receive時,需要修改哪個部分才可以解決此問題?
Hi Richard,
這個限制是HW inproc的限制,如果您需要使用HW inproc模型輸入就不能超過這個限制:
您也可以在customized inference去使用BypassPreproc來迴避這個問題。
Hi Maria,
請問需要進行什麼設置才可以在customized inference去使用BypassPreproc,並接上在NCPU的post process之後返回結果?
意思是我要修改kp_customized_inference_send這個function嗎?
Hi Richard,
BypassPreproc是將處理好的檔案直接拿去推論 (PLUS V1.x會用bypass_pre_proc,V2會用generic_data_inference)
Generic inference會將buffer的input送去推論:
要在customized inference時,可以參考kl720_demo_customize_inf_single_model,將input放在img_buf裡,再送去推論,所以需要把customized inference的參數都設定好。也會需要用Keil在firmware裡新增customized inference的function,model ID,etc.
如果postprocess寫好放在NCPU裡面,會需要在NCPU改動一些檔案(像是加上在customized inference用到的model ID與對應的postprocess)。
這個文檔上有範例,說要改PLUS與firmware的哪一些地方: Create Single Model Example for KL720 - Document Center (kneron.com)
Hi Maria,
我嘗試照你說的方法將處理好的影像放在img_buf裡,並改了scpu firmware裡customized inference的function設置如下
還是會出現inference failed, error = 111,請問我哪個部分改錯了呢? 或者可以提供範例嗎?
Hi Richard,
那些被註解掉的inf_config.image_list[0].image_width的設定,在inference會需要用到,所以可以把註解拿掉。如果這樣還是會有errors,可能是因為在kneron_plus端輸入的input格式不符合KL720的標準。
範例除了demo_customize_inf_single_model.c以外,也有middleware資料夾裡的kdp2_inf_generic_raw.c可以提供您參考。
這個和您之前用的kp_generic_data_inference_send類似,輸入都是raw input
Hi Maria,
我試著將範例kl720_demo_customize_inf_single_model.c改成使用BypassPreproc的方式,但是發現推理完通過NCPU後處理回傳的結果中的box的x1,y1,x2,y2的值都會變成0,但是score和class都是對的,情形如下:
未修改成BypassPreproc的結果
修改成BypassPreproc的結果
請幫忙確認是否還有哪裡修改的有問題,附上修改的kl720_demo_customize_inf_single_model.c及demo_customize_inf_single_model.c,謝謝。
Hi Richard,
如果要直接使用我們firmware既有的postprocess,會需要知道source image的preprocess資訊 (如果有用firmware既有的preprocess,在hw inproc時會自動填寫) 才能在postprocess中做對應的座標轉換。
用BypassPreproc就代表您需要自行去調整並限制postprocess這邊的座標轉換方式,所以有可能需要自行透過給予user-defined data來告訴postprocess現在的source image長寬,然後做對應的座標轉換。不過這個會要改動在NCPU上的postprocess,所以需要自己在firmware或是kneron_plus上寫postprocess,postprocess才能照著preprocess的資訊去做座標轉換。