-
Notifications
You must be signed in to change notification settings - Fork 899
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
Convert SimSwap .pth model to .onnx #437
Comments
There is more to this than just that model so you won't just be able to replace the inswapper_128 with this anyway. Your best bet is to create a new plugin for your UI using this instead of trying to change roop to work like you want it. |
I did a bit of digging into the repo and managed to find where the appropriate model is declared and etc by looking at train.py. I cloned the repo, got the .pth and put it inside checkpoints, then made a symlink to the .pth file inside checkpoints/simswap and then I made this convert.py script that I put in the root of the repo.
I had to modify BaseModel so that its forward function can take self and *args otherwise it would complain about being passed two parameters when I exported the model.
convert.py seems to run fine and even exports a .onnx now but the file only weighs 36 bytes unfortunately... I'm not too sure what's in that file but I don't think it will be of any use. I'm still learning a lot about tensors, tensorflow and machine learning. From what I gathered though, .onnx files typically contain inference functions as well while .pth files only contain the weights for a trained model. This can result in some incompatibility if converted. So from what I understand, it is feasible to convert the weights into the onnx format but the resulting onnx file will be missing some crucial inference functions thus rendering it useless? Maybe my little script will put someone on the right path. |
Who ever landed here, thank me later: https://huggingface.co/netrunner-exe/Insight-Swap-models-onnx/tree/main |
Thanks man I used this to make a quick & dirty implementation of simswap for comfyui: https://github.com/TaiTair/comfyui-simswap |
Hi, I wanted to convert the pretrained SimSwap 512 .pth model to .onnx file format.
I'm not so much into Python, so I don't really know what to do. From what I understand, the code to do so looks something like this:
For a pretrained typical torch model, the code where
torch_model =
is something likemodels.resnet50(pretrained=True)
but for custom model is required custom model class likeModelClass()
in the code. I don't know what to write or where to find the custom model class for the SimSwap 512 model.The text was updated successfully, but these errors were encountered: