# How to convert bestresult to onnx

**URL:** https://forum.opencv.org/t/how-to-convert-bestresult-to-onnx/6434
**Category:** Uncategorized
**Tags:** dnn, onnx
**Created:** [November 25, 2021, 11:03pm UTC](https://forum.opencv.org/t/how-to-convert-bestresult-to-onnx/6434 "2021-11-25T23:03:01Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jsxyhelu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/jsxyhelu/32/194_2.png) [@jsxyhelu](https://forum.opencv.org/u/jsxyhelu)
#### Post date: [November 25, 2021, 11:03pm UTC](https://forum.opencv.org/t/how-to-convert-bestresult-to-onnx/6434/1 "2021-11-25T23:03:02Z")

</div>

> **[GitHub - saic-mdal/lama: 🦙 LaMa Image Inpainting, Resolution-robust Large...](https://github.com/saic-mdal/lama)**
>
> 🦙 LaMa Image Inpainting, Resolution-robust Large Mask Inpainting with Fourier Convolutions, WACV 2022 - GitHub - saic-mdal/lama: 🦙 LaMa Image Inpainting, Resolution-robust Large Mask Inpainting w...

Lama Is a great inpaint model, open source code  
At present, it’s bestressult is in CKPT format, and I hope to convert it to onnx mode. I tried the code,

```auto
        model = load_checkpoint(train_config, checkpoint_path, strict=False, map_location='cpu')
        model.freeze()
        model.to(device)
        torch.save(model,'bestresult.pth')

        img = torch.rand(1,3,320,320,requires_grad=False)
        img = img.to(torch.device('cpu'))
        torch.onnx.export(model,img,'bestresult.onnx',opset_version=11)
        print('=====================best onnx result is saved!================')

```

but it reported an error. How can I solve it? thank you.

```auto

  [2021-11-26 06:25:35,036][__main__][CRITICAL] - Prediction failed due to too many indices for tensor of dimension 4:
Traceback (most recent call last):
  File "bin/predict.py", line 68, in main

```

---

<div class="post-metadata">

### Author: ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)
#### Post date: [November 26, 2021, 7:33am UTC](https://forum.opencv.org/t/how-to-convert-bestresult-to-onnx/6434/2 "2021-11-26T07:33:23Z")

</div>

and how do you get that error ?  
it’s not from opencv …

---

<div class="post-metadata">

### Author: ![jsxyhelu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/jsxyhelu/32/194_2.png) [@jsxyhelu](https://forum.opencv.org/u/jsxyhelu)
#### Post date: [November 28, 2021, 5:24am UTC](https://forum.opencv.org/t/how-to-convert-bestresult-to-onnx/6434/3 "2021-11-28T05:24:56Z")

</div>

OK,get it.Thanks the same.

---

<div class="post-metadata">

### Author: ![jsxyhelu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/jsxyhelu/32/194_2.png) [@jsxyhelu](https://forum.opencv.org/u/jsxyhelu)
#### Post date: [December 14, 2021, 6:05am UTC](https://forum.opencv.org/t/how-to-convert-bestresult-to-onnx/6434/4 "2021-12-14T06:05:21Z")

</div>

Mark！ 😁  
still unsoloved
