他的回复:
buffer_method = {"in": acl.mdl.get_input_size_by_index,"out": acl.mdl.get_output_size_by_index}ACL_DYNAMIC_TENSOR_NAME = "ascend_mbatch_shape_data"以下是固定 batch size 的. buffer 申請(推理有成功)# _gen_data_bufferinput_data, output_data = [], []# -> "in"func = buffer_method["in"]temp_buffer_size = func(model_desc,0) # (224*224*3) * batch sizetemp_buffer, ret = acl.rt.malloc(temp_buffer_size,ACL_MEM_MALLOC_HUGE_FIRST)input_data.append({"buffer": temp_buffer,"size": temp_buffer_size})以下是我根據文檔修改成 動態batch size# _gen_data_bufferinput_data, output_data = [], []# -> "in"func = buffer_method["in"]idx, ret = acl.mdl.get_input_index_by_name(model_desc,ACL_DYNAMIC_TENSOR_NAME)temp_buffer_size = func(model_desc, idx) # 8 ?# temp_buffer_size *= 150528temp_buffer, ret = acl.rt.malloc(temp_buffer_size,ACL_MEM_MALLOC_HUGE_FIRST)input_data.append({"buffer": temp_buffer,"size": temp_buffer_size})temp_buffer_size 在抓動態的.om 時候會變成兩項,所以根據 get_input_index_by_name 只抓到 8在執行以下就會出錯,ret = 100000ret = acl.mdl.set_dynamic_batch_size(model_id,load_input_dataset,index,batch_size=8)測試碼 如附件主要想請問網上是否都沒有 動態batch 的 python碼(classification)可以參考嗎?不然用描述的好像有點模糊-------------updateindex, ret = acl.mdl.get_input_index_by_name(model_desc,"data")最後嘗試 set_dynamic_size 前抓 “data" 就正常了