rembg使用onnxruntime-gpu总结

针对不同显卡在cuda11.x和12.x上使用的分享

安装rembg[gpu,cli]时
1
环境:

       p40 24G,
       Ubuntu 22.04.4 LTS
       python 3.10.12
       NVIDIA-SMI: 535.183.06,
       nvcc: release 12.2, V12.2.140,
       cudnn:9.2.1
       部署后,需要部署TensorRT,部署TensorRT-10.2.0.19
       onnxruntime-gpu:1.18.1,安装的适配cuda12.x的版本

运行:rembg i -m u2net dog.jpg dog-u2net.jpg
结果:TensorRT报错
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : TensorRT EP failed to create engine from network for fused node: TensorrtExecutionProvider_TRTKernel_graph_torch-jit-export_9754103867505355785_0_0
预估:可能与onnxruntime安装的支持cuda12.x的版本有关
解决: 重新安装rembg:

   pip install onnxruntime-gpu --extra-index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-12/pypi/simple/
   pip install rembg[gpu] --no-deps
   pip install numpy opencv-python-headless pillow pooch pymatting scikit-image scipy tqdm
安装后确认:
   import  onnxruntime as ort
   print(f"onnxruntime device: {ort.get_device()}") # output: GPU
   print(f'ort avail providers: {ort.get_available_providers()}') # output: ['CUDAExecutionProvider', 'CPUExecutionProvider']
   ort_session = ort.InferenceSession('/root/.u2net/u2net.onnx', providers=["CUDAExecutionProvider"])
   print(ort_session.get_providers())
通过代码运行:
   python3 -c "from rembg import remove, new_session; from PIL import Image; output = remove(Image.open('dog.jpg'), session=new_session('u2net', ['CUDAExecutionProvider'])); output.save('dog-u2net.jpg')"
通过代码运行后正常,运行中gpu被使用,但是通过命令行运行依然报上面的错误,主要还是在代码中集成居多,命令行问题预估是版本不一致可能性很高。

2
环境:

       a100 40G,
       python 3.10.12
       Ubuntu 22.04.3 LTS
       NVIDIA-SMI: 535.113.01,
       nvcc: release release 11.8, V11.8.89,
       cudnn:8.9.7.29
       部署后,需要部署TensorRT,部署TensorRT-10.2.0.19
       onnxruntime-gpu:1.18.1,安装的适配cuda11.8的版本

运行:rembg i -m u2net dog.jpg dog-u2net.jpg
结果:命令运行可正常输出结果,运行中gpu被使用,代码中运行也正常。

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huotianyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值