Model convert 問題

我目前在處理模型轉換時,但遇到以下幾個問題

1.     接著再處理E2E Simulator Check (Floating Point),跳出Not enough input node names specified錯誤 (如附件1),

程式碼為inf_results = ktc.kneron_inference(input_data, onnx_file=edit_optimized_onnx_output_path, input_names=['input'], platform=530)

input_names 已修改為模型input 卻還是錯誤,

請問這部分如何處理 ?


2. 我使用530或720做IP Evaluation,

則會有warning 顯示The last layer should not be the CPU node! layer [BatchNormalization_29] (如附件2),

請問這該如何處理 ? 是否會影響後續轉換 ?

而如果使用 520 則會顯示 HardwareNotSupport (如附件3)。

網路架構只有convolution、relu、batchnormalization,

後面有的transpose、softmax移除後也同樣失敗,


Comments

  • @arthurwu

    Hi arthurwu,

    不知道您是否有過  (3.1.5 ONNX Optimization) ,如果有的話是否可以提供您的 model 讓我們看看 model structure 與您的 Scripts。

  • @Andy Hsieh

    我有過(3.1.5 ONNX Optimization) ,程式碼跟model以附在附件中

    另外想請教 附件中有另一個 epoch19_optimized_edited_temp.onnx 請問這個只有移除softmax 也可以嗎 ?

    謝謝


  • @arthurwu

    Hi arthurwu,

    我看過您的 model 之後,您的 layer 間的 shape 都只有三維,您可能要想辦法讓您的 layer 間的 shape 變成四維。(BCHW)

    順道一提,您輸入的 batchsize,必須是 1。

    變成四維之後,移除 softmax layer, 您的問題可能也都會一起解決。


  • @Andy Hsieh

    Hi Andy Hsieh,

    最前面第一個問題

    處理E2E Simulator Check (Floating Point),跳出Not enough input node names specified錯誤 (如附件1),

    程式碼為inf_results = ktc.kneron_inference(input_data, onnx_file=edit_optimized_onnx_output_path, input_names=['input'], platform=530)

    input_names 已修改為模型input 卻還是錯誤,

    請問這部分如何處理 ?

    (備註 : 這部分為使用530且已經通過IP Evaluation)

  • edited March 2022

    @arthurwu

    Hi arthurwu,

    目前您的問題可以分為兩個部分回答:

    (1)您使用的 platform=530 通過 IP Evaluation 應該也是有出現 Warning。

    因為您本身 layer 間的 shape 只有三維,所以可能會造成有 warning 顯示。

    您在處理 E2E Simulator Check (Floating Point) 跳出 Not enough input node names specified 錯誤的原因跟您 model layer 間的 shape 只有三維也有關係。

    inf_results = ktc.kneron_inference(input_data, onnx_file=edit_optimized_onnx_output_path, input_names=['input'], platform=530)

    如果您輸入的 input_names 已修改為模型上的 "input" 這是對的, 但是您的 input_data 的 input (shape & size) 可能跟您 model 的 input (shape & size) 不合,您必須對您的 input_data 做 preprocess。

    (2)目前 platform=530 對應的 hardware 還沒有正式 release,如果您需要較高的支援,建議您先使用 platform=720。

  • @Andy Hsieh

    Hi Andy Hsieh,


    1. 使用 platform=720 通過 IP Evaluation 也是有出現 Warning

    請問這部分會影響後續執行嗎?


    2. 已確認 input_data size 跟 模型相同 (也有在 onnx 上確認皆為 23 * 80 * 434)

     E2E Simulator Check (Floating Point) 跳出 Not enough input node names specified 錯誤,

    請問是有其他建議可解決方法 ? 還是只能重新訓練一個4維模型 ?


    謝謝

  • edited March 2022

    @arthurwu

    Hi arthurwu,

    1. 使用 platform=720 通過 IP Evaluation 也是有出現 Warning

    請問這部分會影響後續執行嗎?

    Ans:

    會影響後續的執行,對於不支持的 operators type,無法在 Kneron NPU 上面使用。


    2. 已確認 input_data size 跟 模型相同 (也有在 onnx 上確認皆為 23 * 80 * 434)

     E2E Simulator Check (Floating Point) 跳出 Not enough input node names specified 錯誤,

    請問是有其他建議可解決方法 ? 還是只能重新訓練一個4維模型 ?

    Ans:

    因為架構限制,沒有其他解決辦法😥,所以您可能需要想辦法讓您的 layer 間的 shape 變成 4 維。


  • @Andy Hsieh

    Hi Andy Hsieh,

    因我處理的資料為語音,並非影像

    就上面所說需要4維空間的資料,請問每個維度間有其他限制嗎 ?

    例如一定要為 (batch, channels, height, width) 或是 channels一定要 <=4 等限制

  • @arthurwu

    Hi arthurwu,

    每個維度間 (batch, channels, height, width) ,要注意的是,目前 batch 必須 == 1,其他的沒有限制喔,如果有疑慮的話一樣可以利用 IP Evaluation 來看看是否有 Warnning 的出現。


  • @Andy Hsieh

    Hi Andy Hsieh,

    我已經將模型改成4 dimension

    但是同樣在處理E2E Simulator Check (Floating Point),跳出Not enough input node names specified錯誤,

    程式碼為inf_results = ktc.kneron_inference(inference_data, onnx_file=edit_optimized_onnx_output_path, input_names=['input'], platform=720)

     請問這部分該如何處理 ?


    程式碼、onnx模型以及測試檔在以下附件中


  • @arthurwu

    Hi arthurwu,

    Sorry for the late reply.

    目前我有查看過您的跳出的錯誤,我已經把您的問題提交到相關部門,繼續針對您的問題進行測試,等有消息會再通知您。

  • edited April 2022

    @arthurwu

    Hi arthurwu,

    1. kneron_inference (eg. inference_data) 的 input shape 需要 channel last。
    2. kneron_inference (eg. inference_data) 的 input 需要給 list of numpy。


    您可以試著將您的 infernce_datat , 先 transpose shape並改成 list of numpy 的形式跑看看 (如下)

        inference_data = np.load(inference_data_path)
        inference_data = np.expand_dims(inference_data, axis=2)
        inference_data = np.transpose(inference_data, (1, 2, 0))
        inf_results = ktc.kneron_inference([inference_data], onnx_file=edit_optimized_onnx_output_path, input_names=['input'], platform=720)
    
  • @Andy Hsieh

    Hi Andy Hsieh,

    根據您的建議已經可以執行 inference

    做完inference後再做cut off 部分的處理。而後處理所使用的參數來自原始ONNX檔。

    但是在E2E simulater(Floating Point)的結果就與原始model輸出有明顯差異,請問這部分該如何處理 ?


  • @arthurwu

    Hi arthurwu,

    我這裡根據您提供附件想重現您提出的問題,我想請教您一下您 Scripts 中我遇到的幾點問題。

    1. Step4 inference_data_path[0] 是指哪個 inference data。
    2. 您在 Step5 量化的 inference_data_path 是讀取哪些 data 來量化您的 model。量化模型時,會用與模型相關的 data 去做量化。

    還有想請教您一下,您的描述中,E2E simulater (Floating Point) 的結果就與原始 model 輸出有明顯差異指的是 E2E simulater Kneron inference (Floating point) 與 Kneron onnx inference 輸出有明顯差異嗎?

  • @Andy Hsieh

    Hi Andy Hsieh,

    抱歉我資料沒有說明清楚,在此重新上傳附件

    1. Step4 inference_data_path[0] 是指哪個 inference data。

    • 附件內有一個 inference_data.npy ,就是執行inference用的inference data

    2. 您在 Step5 量化的 inference_data_path 是讀取哪些 data 來量化您的 model。量化模型時,會用與模型相關的 data 去做量化

    • 附件內有一個 train_npy_ori 資料夾,使用此資料夾中的資料做量化 ,inference data就是取自這資料中的第一筆train0.npy

    3. E2E simulater (Floating Point) 的結果就與原始 model 輸出有明顯差異指的是 E2E simulater Kneron inference (Floating point) 與 Kneron onnx inference 輸出有明顯差異嗎?

    • 原始model的結果我取自onnxruntime執行onnx model的結果(oirginal_model_results.npy )。
    • 在與 E2E simulater 的結果做比較時,是對輸出德最後一維做argmax後做比對,看對應的結果是否相同
    • ex:oirginal_model_results.npy 的結果是 (1, 150, 220),對最後一維做argmax的到(1, 150)輸出,再做比較



  • @arthurwu

    Hi arthurwu,

    我這裡根據您提供附件重現您提出的問題,這裡有發現,您使用原始 model 並使用 onnxruntime 執行 onnx inference 與 Kneron E2E Simulator 的 onnx inference 有明顯差異的原因是 Kneron E2E Simulator 的 onnx inference input 與 ouput shape 與 onnxRT 有所不同,你只要改回來並請您將 inference_data = inference_data.astype('float16') 註解掉,應該就可以發現沒有差異性了。

    Kneron Tool Chain 是 channel last

    OnnxRT 是 channel first


    這裡提供連結給您參考:


    不好意思這邊也想請教您,您的 Scripts 中 inference data 使用 astype("16") [inference_data = inference_data.astype('float16')] 不知道您是否有甚麼需求或原因?

  • @Andy Hsieh

    Hi Andy Hsieh,

    1. Kneron E2E Simulator 的 onnx inference input 與 ouput shape 與 onnxRT 有所不同

    • Kneron E2E Simulator 輸出為 1 x 150 x 1 x 500,我在後處理的部分有先squeeze變成 150 x 500,再做matmul (500 x 220)跟add 變成 150 x 220,並對此結果做logsoftmax。再與onnxruntime結果比較時,對最後一維取argmax,得到150個值
    • onnxruntime輸出結果為 1 x 150 x 220。同樣先做squeeze再對最後一維做argmax,同樣得到150個值
    • 將上述兩個做比較發現兩者結果有蠻大落差

    2. inference_data = inference_data.astype('float16') 註解掉,後結果同樣有差異


    差異如附件所示(內有Kneron E2E Simulator以及onnxruntime輸出結果)


  • @arthurwu

    Hi arthurwu,

    我這裡幫您檢查,流程如下:

    1. OnnxRT infernce:使用您提供的 epoch19_4d3.onnx 為 model,inference_data.npy 為您的 input data,將 input data 去做推論得到結果 C [shape (1, 150, 220)]。
    2. Kneron E2E Simulator:使用您 Script (kneron_model_convert.py) 生成出來的 epoch19_4d3_optimized_edited.onnx 為 model,inference_data.npy 為您的 input data,將 input data 去做推論得到結果 A [shape (1, 150, 1, 500)]),並將結果 A [shape (1, 150, 1, 500)] 先轉置成結果 B [shape (1, 500, 150, 1)],最後再用結果 B 使用您提供 post-process Script (kneron_post_process.py) 去做 post-process 會得到結果 C [shape (150, 220)]

    這兩個結果 C 相比,結果是沒有很大的差異的。(如附圖)

    (左邊為 OnnxRT 得到的結果,右邊為 Kneron onnx inference 做 post-process 得到的結果)


    如果您那邊兩個做比較,發現兩者結果有蠻大落差,您可能檢查一下您的 model 與 input data。

The discussion has been closed due to inactivity. To continue with the topic, please feel free to post a new discussion.