Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A simple ckpt to pt model convertor #306

Open
jiaxue-ai opened this issue Mar 30, 2024 · 0 comments
Open

A simple ckpt to pt model convertor #306

jiaxue-ai opened this issue Mar 30, 2024 · 0 comments

Comments

@jiaxue-ai
Copy link

Hi,

I wrote a simple ckpt to pt model convertor, in case anyone needs it


import os
import yaml
from saicinpainting.training.trainers import load_checkpoint
from omegaconf import OmegaConf

lama_model_path = '/LaMa_models/lama-places/lama-fourier/'

train_config_path = os.path.join(lama_model_path, 'config.yaml')
with open(train_config_path, 'r') as f:
    train_config = OmegaConf.create(yaml.safe_load(f))

train_config.training_model.predict_only = True
train_config.visualizer.kind = 'noop'

checkpoint_path = os.path.join(lama_model_path,
                                'models',
                                'best.ckpt')
model = load_checkpoint(train_config, checkpoint_path, strict=False, map_location='cpu')
model.freeze()
with torch.no_grad():
    typical_input = torch.zeros([1, 4, 512, 512])
    # print(model.generator(typical_input).shape)
    traced_cell = torch.jit.trace(model.generator, (typical_input))
torch.jit.save(traced_cell, os.path.join(lama_model_path, 'lama-model-best.pt'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant