0

I have used transfer learning of pytorch to trained a model. It has an extension of .pth. I want to use it to recognize object in video. I have always been using opencv in video processing so I want to use it this time too. However, the dnn module from opencv does not accept model with .pth extension. Can I generate model with pytorch that can be accepted by opencv? Or can I use model with .pth in opencv?

Here's how I saved the trained model

torch.save(the_model.state_dict(), PATH)

I have read that post How should I save the model of PyTorch if I want it loadable by OpenCV dnn module but it is not helpful

Sghwhw
  • 117
  • 1
  • 16

1 Answers1

0

You could always try exporting using onnx, which looks like it could be read by OpenCV

  • Also, possibly a duplicate of https://stackoverflow.com/questions/45929573/how-should-i-save-the-model-of-pytorch-if-i-want-it-loadable-by-opencv-dnn-modul?rq=1 – Mathieu Mitchell Apr 17 '19 at 05:54
  • I have tried this https://pytorch.org/docs/stable/onnx.html but I dont really understand the way to apply it. Can you give me an example please? – Sghwhw Apr 17 '19 at 06:02