PyTorch-YOLOv3 icon indicating copy to clipboard operation
PyTorch-YOLOv3 copied to clipboard

convert this project's .pth to darknet's .weights

Open LifeIsSoSolong opened this issue 5 years ago • 8 comments

I want to convert this project's .pth to darknet's .weights ,anyone else have some advice? I try to load .pth to model, and then save modle's para to .weights , but I use it in darknet's get None detect result.

LifeIsSoSolong avatar Sep 02 '19 01:09 LifeIsSoSolong

I want to convert this project's .pth to darknet's .weights ,anyone else have some advice? I try to load .pth to model, and then save modle's para to .weights , but I use it in darknet's get None detect result.

maybe onnx?

JsBlueCat avatar Oct 20 '19 14:10 JsBlueCat

I want to convert this project's .pth to darknet's .weights ,anyone else have some advice? I try to load .pth to model, and then save modle's para to .weights , but I use it in darknet's get None detect result.

Here is the answer. https://kevin970401.github.io/etc/2018/12/26/converting-models.html

blackCmd avatar Oct 27 '20 03:10 blackCmd

create a new python file, import all requirements and copy the following lines in them

model = Darknet("your .cfg file")

model.load_state_dict(torch.load("your_ckpt.pth", map_location=torch.device('cpu'))) # for loading model on cpu

model.save_weights(savedfile='your_ckpt.weights', cutoff=0) print("successfully converted .pth to .weights")

Hope it helps you

aarkey81 avatar Nov 09 '20 15:11 aarkey81

I want to convert this project's .pth to darknet's .weights ,anyone else have some advice? I try to load .pth to model, and then save modle's para to .weights , but I use it in darknet's get None detect result.

Create a new python file, import all requirements and copy the following lines in them

model = Darknet("your .cfg file")

model.load_state_dict(torch.load("your_ckpt.pth", map_location=torch.device('cpu'))) # for loading model on cpu

model.save_weights(savedfile='your_ckpt.weights', cutoff=0) print("successfully converted .pth to .weights")

Hope it helps you

aarkey81 avatar Nov 09 '20 16:11 aarkey81

I want to convert this project's .pth to darknet's .weights ,anyone else have some advice? I try to load .pth to model, and then save modle's para to .weights , but I use it in darknet's get None detect result.

maybe onnx?

Create a new python file, import all requirements and copy the following lines in them

model = Darknet("your .cfg file")

model.load_state_dict(torch.load("your_ckpt.pth", map_location=torch.device('cpu'))) # for loading model on cpu

model.save_weights(savedfile='your_ckpt.weights', cutoff=0) print("successfully converted .pth to .weights")

Hope it helps you

aarkey81 avatar Nov 09 '20 16:11 aarkey81

We should add this file as a script to this git. With some command-line arguments.

Flova avatar Jan 11 '21 00:01 Flova

Hi, which model to import while doing this? Can anyone guide me on this? I am unable to import Darknet, is there anything else, i can try? @Flova @aarkey81

ktanay20 avatar Mar 06 '23 09:03 ktanay20

I think you mean that the Darknet python module import fails right?

Make sure you ran poetry shell in your terminal if you use poetry.

Afterward, you should be able to import it like this:

from pytorchyolo.models import Darknet

Flova avatar Mar 06 '23 14:03 Flova