0

I trained a model using this github repository. It's a CRNN[10] model and I want to use it now to make predictions. With what I've read, I need to excecute this:

model = TheModelClass(*args, **kwargs)
model.load_state_dict(torch.load(PATH))
model.eval()

To do that I need the model class of my network. How do I know what class I have? I tried torchvision.models.crnn() and torchvision.models.crnn10(), but both of these don't work. Can anyone tell me how I can load my model?

1

1 Answer 1

0

The Model class is given in the above GitHub repository. To use your trained model weights you can do this.

  1. Clone the above repo

  2. create your test file inside the repo

  3. Add this code to load the model

    from model import Model
    #create opt class with all these attributes: opt.imgH,opt.imgW,opt.num_fiducial, opt.input_channel,opt.output_channel,opt.hidden_size, opt.num_class,opt.batch_max_length,opt.Transformation,opt.FeatureExtraction,opt.SequenceModeling, opt.Prediction)
    model = Model(opt)
    model.load_state_dict(torch.load(PATH))
    model.eval()

Sign up to request clarification or add additional context in comments.

3 Comments

What exactly should be in this opt class. I now have class opt: def __init__(self): self.imgH self.imgW self.num_fiducial self.input_channel self.output_channel self.hidden_size self.num_class self.batch_max_length self.Transformation self.FeatureExtraction self.SequenceModeling self.Prediction which gives me the following error: in __init__ self.stages = {'Trans': opt.Transformation, 'Feat': opt.FeatureExtraction, AttributeError: type object 'opt' has no attribute 'Transformation'. Should this class inherit from another class?
I moved the model.pth file to another directory so I could use it there, but now I realise, I need that as well, so that solves part of the problem, but now I'm left with this
The above class looks like it has all thi input arguments needed. Now use the same input arguments that you used while training to initialize the model.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.