HarmonyOS 鸿蒙Next mindspore lite转换模型失败 Convert failed. Ret: Common error code

发布于 1周前 作者 songsunli 来自 鸿蒙OS

HarmonyOS 鸿蒙Next mindspore lite转换模型失败 Convert failed. Ret: Common error code

cke_481.png

环境ubuntu22.04,我确认满足文档写明的依赖:

GCC >= 7.3.0

CMake >= 3.18.3

Git >= 2.28.0

需要转换的模型是YOLO11.ONNX,请大神帮忙看看咋解决?

4 回复
更新:先把yolov8n.pt转成mindir格式,再把mindir转成ms格式;but,端侧推理时出来的score很小,没有超过0.01的。。同一张图片在PC上使用yolo官方模型推理结果有4个目标的score超过0.8,这咋弄,推理引擎我也看不到它是咋计算的呀…… 附上我转换的模型和推理代码:
import { mindSporeLite } from '@kit.MindSporeLiteKit'
import Logger from '../common/utils/Logger';
// 封装工具类
export default async function modelPredict(
  modelBuffer: ArrayBuffer, inputsBuffer: ArrayBuffer[]): Promise<mindSporeLite.MSTensor[]> {

let context: mindSporeLite.Context = {}; context.target = [‘cpu’]; context.cpu = {} context.cpu.threadNum = 2; context.cpu.threadAffinityMode = 1; context.cpu.precisionMode = ‘enforce_fp32’; let msLiteModel: mindSporeLite.Model = await mindSporeLite.loadModelFromBuffer(modelBuffer, context); let modelInputs: mindSporeLite.MSTensor[] = msLiteModel.getInputs(); for (let i = 0; i < inputsBuffer.length; i++) { let inputBuffer = inputsBuffer[i]; if (inputBuffer != null) { modelInputs[i].setData(inputBuffer as ArrayBuffer); } } Logger.info(’=========MS_LITE_LOG: MS_LITE predict start=====’); let modelOutputs: mindSporeLite.MSTensor[] = await msLiteModel.predict(modelInputs); return modelOutputs; }

// 以下是主要推理代码 const startTime = new Date().getTime() // predict modelPredict(modelBuffer.buffer.slice(0), inputs).then(outputs => { Logger.info(’=========MS_LITE_LOG: MS_LITE predict success=====’); for (let i = 0; i < outputs.length; i++) { let out = new Float32Array(outputs[i].getData()); const x_factor: number = info.size.width / 640; const y_factor: number = info.size.height / 640; // 矩阵转置 np.transpose(np.squeeze(out)) let row: number[][] = new Array(84) for (let i = 0; i < 8400; i++) { let temp: number[] = [] for (let j = 0; j < 84; j++) { temp[j] = out[i + j * 8400] } row[i] = temp; }

              <span class="hljs-keyword">this</span>.maxArray = [];
              <span class="hljs-keyword">this</span>.maxIndexArray = [];
              <span class="hljs-keyword">this</span>.bboxes = [];
              <span class="hljs-keyword">let</span> maxScore: number = <span class="hljs-number">0</span>
              <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">8400</span>; i++) {
                <span class="hljs-keyword">const</span> classes_scores = row[i].slice(<span class="hljs-number">4</span>);
                <span class="hljs-keyword">const</span> max_score: number = <span class="hljs-built_in">Math</span>.max(...classes_scores)
                maxScore = max_score &gt; maxScore ? max_score : maxScore
                <span class="hljs-keyword">if</span> (max_score &gt; <span class="hljs-keyword">this</span>.confidence_thres) {
                  <span class="hljs-keyword">const</span> x: number = row[i][<span class="hljs-number">0</span>];
                  <span class="hljs-keyword">const</span> y: number = row[i][<span class="hljs-number">1</span>];
                  <span class="hljs-keyword">const</span> w: number = row[i][<span class="hljs-number">2</span>];
                  <span class="hljs-keyword">const</span> h: number = row[i][<span class="hljs-number">3</span>];
                  <span class="hljs-keyword">const</span> left: number = ~~((x - w / <span class="hljs-number">2</span>) * x_factor)
                  <span class="hljs-keyword">const</span> top: number = ~~((y - h / <span class="hljs-number">2</span>) * y_factor)
                  <span class="hljs-keyword">const</span> width: number = ~~(w * x_factor)
                  <span class="hljs-keyword">const</span> height: number = ~~(h * y_factor)

                  <span class="hljs-keyword">const</span> class_id = classes_scores.findIndex(vo =&gt; vo === max_score)
                  <span class="hljs-keyword">this</span>.maxIndexArray.push(class_id)
                  <span class="hljs-keyword">this</span>.maxArray.push(max_score)
                  <span class="hljs-keyword">this</span>.bboxes.push([left, top, width, height])
                }
              }

              Logger.info(<span class="hljs-string">'MAX_LOG: '</span> + maxScore);
            }
            <span class="hljs-keyword">this</span>.cost = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime() - startTime
            Logger.info(<span class="hljs-string">'=========MS_LITE_LOG END========='</span>);
          })</code></pre></div></div>
cke_181.png

直接使用 官方pt模型也报错。

https://www.mindspore.cn/lite/docs/zh-CN/r2.4.0/converter/converter_tool.html
补充,参照这份文档下载了win11程序,设置环境变量之后,报一样的错误,这次换了yolov8n.onnx模型:

cke_1512.png
cke_1243.png

在面对HarmonyOS鸿蒙系统中的MindSpore Lite模型转换失败的问题时,首先需要确认几个关键点:

  1. 模型兼容性:确保你尝试转换的模型格式与MindSpore Lite支持的格式兼容。不支持的格式可能会导致转换失败。

  2. 版本匹配:检查MindSpore Lite的版本是否与你的HarmonyOS系统版本相匹配。版本不匹配也可能导致转换过程中出现问题。

  3. 转换工具与参数:确保你使用的转换工具(如Model Converter)正确无误,并且转换参数设置正确。错误的参数设置或工具使用不当均可能导致转换失败。

  4. 资源限制:确认设备或环境是否有足够的资源(如内存、存储空间)来完成模型转换。资源不足也可能导致转换失败。

  5. 错误代码解析:你提到的“Common error code”较为模糊,建议查看MindSpore Lite的官方文档或日志输出,找到具体的错误代码或描述,以便更精确地定位问题。

如果上述检查均无误,但问题依旧存在,可能是更复杂的系统或软件问题。此时,建议直接联系官网客服以获取专业的技术支持。官网地址是:https://www.itying.com/category-93-b0.html

回到顶部