测试om模型的时候使用resnet50.om模型报错,RuntimeError: (Code = 1007, Message = "memory allocation error")
收藏回复举报
测试om模型的时候使用resnet50.om模型报错,RuntimeError: (Code = 1007, Message = "memory allocation error")
新人帖
发表于2025-11-14 17:13:17
0 查看

加载推理om模型很有问题,测试acl也是,想问一下我应该使用什么才能在华为服务器的npu卡下面进行加速推理模型,有没有合适的案例框架可以尝试,谢谢

以下是我的设备信息

  • 驱动版本:24.1.rc3

  • Ascend HAL 版本:7.35.23

  • mindxsdk-nxvision_7.1

  • Linux 300I-Duo-12-47 5.4.0-216-generic  aarch64 GNU/Linux   310P3

    测试以下代码的时候

    import numpy as np  # 用于对多维数组进行计算

    import cv2  # 图片处理三方库,用于对图片进行前后处理

    from mindx.sdk import Tensor  # mxVision 中的 Tensor 数据结构

    from mindx.sdk import base  # mxVision 推理接口

    from mindx.sdk.base import post  # post.Resnet50PostProcess 为 resnet50 后处理接口

    from mindx.sdk.base import log  # mxVision  日志接口

    def process():

        '''初始化资源和变量'''

        base.mx_init()  # 初始化 mxVision 资源

        pic_path = 'data/test.jpg'  # 单张图片

        model_path = "model/resnet50.om"  # 模型路径

        device_id = 0  # 指定运算的Device

        config_path='utils/resnet50.cfg'  # 后处理配置文件

        label_path='utils/resnet50_clsidx_to_labels.names'  # 类别标签文件

        img_size = 256

        '''前处理'''

        img_bgr = cv2.imread(pic_path)

        img_rgb = img_bgr[:,:,::-1]

        img = cv2.resize(img_rgb, (img_size, img_size))  # 缩放到目标大小

        hw_off = (img_size - 224) // 2  # 对图片进行切分,取中间区域

        crop_img = img[hw_off:img_size - hw_off, hw_off:img_size - hw_off, :]

        img = crop_img.astype("float32")  # 转为 float32 数据类型

        img[:, :, 0] -= 104  # 常数 104,117,123 用于将图像转换到Caffe模型需要的颜色空间

        img[:, :, 1] -= 117

        img[:, :, 2] -= 123

        img = np.expand_dims(img, axis=0)  # 扩展第一维度,适应模型输入

        img = img.transpose([0, 3, 1, 2])  # 将 (batch,height,width,channels) 转为 (batch,channels,height,width)

        img = np.ascontiguousarray(img)  # 将内存连续排列

        img = Tensor(img) # 将numpy转为转为Tensor类

        '''模型推理'''

        model = base.model(modelPath=model_path, deviceId=device_id)  # 初始化 base.model 类

        output = model.infer([img])[0]  # 执行推理。输入数据类型:List[base.Tensor], 返回模型推理输出的 List[base.Tensor]

        output.to_host()

        '''后处理'''

        postprocessor = post.Resnet50PostProcess(config_path=config_path, label_path=label_path)  # 获取后处理对象

        pred = postprocessor.process([output])[0][0]  # 利用sdk接口进行后处理,pred:<ClassInfo classId=... confidence=... className=...>

        confidence = pred.confidence  # 获取类别置信度

        className = pred.className  # 获取类别名称

        print('{}: {}'.format(className, confidence))  # 打印出结果  

        '''保存推理图片'''

        img_res = cv2.putText(img_bgr, f'{className}: {confidence:.2f}', (20, 20), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1)  # 将预测的类别与置信度添加到图片

        cv2.imwrite('result.png', img_res)

        print('save infer result success')

    if __name__ == "__main__":

        base.mx_init()  # 初始化 mxVision 资源

        process()

        base.mx_deinit()  # 去初始化 mxVision 资源

最后爆出的错误信息

Begin to initialize Log.

WARNING: Logging before InitGoogleLogging() is written to STDERR

I20251114 17:02:10.530218 281472986571200 FileUtils.cpp:510] Check Owner permission: Current permission is 7, but required no greater than 6.

The output directory of logs file exist.

I20251114 17:02:10.530591 281472986571200 FileUtils.cpp:354] The input file is empty

I20251114 17:02:10.530617 281472986571200 FileUtils.cpp:510] Check Other group permission: Current permission is 4, but required no greater than 0.

Save logs information to specified directory.

E20251114 17:02:10.544812 281472986571200 FileUtils.cpp:506] Check Owner permission failed: Current permission is 7, but required no greater than 6. (Code = 1001, Message = "General Failed") 

E20251114 17:02:10.545192 281472986571200 LogManager.hpp:139] Invalid logging.conf file! (Code = 1004, Message = "Invalid parameter") 

E20251114 17:02:10.545231 281472986571200 GlobalInit.cpp:67] Init log rotate thread failed. (Code = 1004, Message = "Invalid parameter") 

E20251114 17:02:10.545324 281472986571200 FileUtils.cpp:506] Check Owner permission failed: Current permission is 7, but required no greater than 6. (Code = 1001, Message = "General Failed") 

E20251114 17:02:10.545360 281472986571200 LogManager.hpp:139] Invalid logging.conf file! (Code = 1004, Message = "Invalid parameter") 

E20251114 17:02:10.545391 281472986571200 GlobalInit.cpp:67] Init log rotate thread failed. (Code = 1004, Message = "Invalid parameter") 

E20251114 17:02:10.582126 281472986571200 FileUtils.cpp:506] Check Owner permission failed: Current permission is 7, but required no greater than 6. (Code = 1001, Message = "General Failed") 

E20251114 17:02:10.582208 281472986571200 DeviceManager.cpp:36] Invalid lib file! (Code = 1001, Message = "General Failed") 

E20251114 17:02:10.582244 281472986571200 DeviceManager.cpp:166] Check user permission failed, please check the owner of process. (Code = 1001, Message = "General Failed") 

E20251114 17:02:10.582275 281472986571200 DeviceManager.cpp:290] Init device failed. (Code = 1001, Message = "General Failed") 

E20251114 17:02:10.582305 281472986571200 MxOmModelDesc.cpp:78] Model setDevice failed, please check the state of device. (Code = 1001, Message = "General Failed") 

E20251114 17:02:10.582337 281472986571200 Model.cpp:58] MxModel init failed. (Code = 1001, Message = "General Failed") 

E20251114 17:02:10.610692 281472986571200 MxOmModelDesc.cpp:368] Failed to unload model. (Calling Function = aclmdlUnload, Code = 145003, Message = "ACL error, please refer to the document of CANN.") 

E20251114 17:02:10.610784 281472986571200 PyModel.cpp:41] Failed to create model_ object. (Code = 1007, Message = "memory allocation error") 

Traceback (most recent call last):

  File "/home/hkzy/workspace/test_model/resnet50_sdk_python_sample/main.py", line 54, in <module>

    process()

  File "/home/hkzy/workspace/test_model/resnet50_sdk_python_sample/main.py", line 36, in process

    model = base.model(modelPath=model_path, deviceId=device_id)  # 初始化 base.model 类

  File "/home/hkzy/.local/lib/python3.10/site-packages/mindx/sdk/base/base.py", line 2215, in model

    return _base.model(modelPath, deviceId)

RuntimeError:  (Code = 1007, Message = "memory allocation error") 

我要发帖子