Hello,
I have a model whose architecture is found by a search method. Many such models are saved as checkpoints, but it’s challenging to restore and run them again because the exact architecture was programmatically determined. Each time I would want to load one of the checkpoints, it would require re-writing by hand the model architecture to exactly fit the particular one of the checkpoint file.
It would be wonderful if there were a way to do this:
module = SomeModule()
checkpoint = torch.load(checkpoint_file)
module.restoreArchitecture(checkpoint["architecture"])
module.load_state_dict(checkpoint["state"])

In principle this could be done by saving the architecture configuration and building a parser, though it would get hairy for custom objects and expressions, where markup isn’t as expressive as code.
Is there a canonical way of doing this?
It seems a reasonably popular request:

  
    
    
    Load pretrained model without creating architecture manually vision
  
  
    How to load a base network such as Resnet152 or efficient net model. Do I need to recreate the architecture and copy the pretrained weights to my architecture?. Is there a way to use the model without creating the architecture and copying the parameters?
  



  
    
    
    How to save/load Torch models? 
  
  
    Is there any way to load a trained model without declaring the class definition before ? 
I want the model architecture as well as parameters to be loaded.
  



  
      stackoverflow.com
  
  
      
    
  

  How to save model architecture in PyTorch?



  pytorch



  asked by
  
  
    M.Z.
  
  on 12:33AM - 05 Jan 20 UTC