AlexanderLutsenko / nobuco

Pytorch to Keras/Tensorflow/TFLite conversion made intuitive
MIT License
272 stars 17 forks source link

Convert pretrained .torch model (including weights) #34

Open CarlosNacher opened 7 months ago

CarlosNacher commented 7 months ago

Hi, I am new to your library and would quickly like to know if I could convert a pre-trained torch model to keras. I mean, from what I see in the README, what is converted is the model code, but if we have the weights in the .torch model, how do we put them to the new keras model?

Maybe this question is very obvious, but I don't see the direct way to do it.

Thanks in advance

AlexanderLutsenko commented 7 months ago

Hi! To trace a model, we need to perform inference on it. Do you have the inference script?

CarlosNacher commented 7 months ago

Hi! What do you exactly mean? I have my model.pt (trained) and also, yes, I have some script that loads the torch model, the data, preprocesses data, does inference, etc. But why is the inference script needed to transfer the weights from one (torch) model to another (tf) one?

Thank you for your response!

happyTonakai commented 5 months ago

I think nobuco converts a torch model to a keras model without losing the parameters. You can try to figure out the outputs with a same input.

johndpope commented 1 month ago

it's possible to translate the weights https://github.com/johndpope/IMF/blob/feat/tensorflow-cips/tf-export.py https://github.com/johndpope/IMF/blob/feat/tensorflow-cips/tf-export2.py

https://github.com/AlexanderLutsenko/nobuco/pull/66 https://github.com/johndpope/nobuco/blob/master/examples/multihead-attention.py