I am trying to convert Fastai pkl file to pytorch file but it’s throwing error.

Please tell how to convert it.

What is the error thrown? How are you attempting to export your fastai model?

Hey hi, Thanks for the reply:

I followed these steps:

learn_gen is the learner

- learn_gen.export()
- model = torch.load(‘P.pkl’) #P.pkl is the pkl file exported

model_dict = model.state_dict()

model.load_state_dict(model_dict)

3.model(input_image)

But this does not work

Please help me resolve this error. I could not find any sorce on the web.

Can you post the stack trace with the log of the error?

@dubesar I am not sure if the above method you described is a valid solution. But I do know that one of options to move your fastai model to pytorch is by creating a model definition in PyTorch and then loading the weights from the fastai model.

You can save the fastai model weights by accessing learn.model.state_dict.

Did you try this solution yourself and see it work?

I used learn.model to input the image to make a predict, and it fails. The output value from learn.model is so different than learn’s output value.

This is what you need,