sdv-dev / CTGAN

Conditional GAN for generating synthetic tabular data.
Other
1.26k stars 285 forks source link

Saving a CTGAN model #44

Closed diegobodner closed 4 years ago

diegobodner commented 4 years ago

Description

I would like to save in disk a CTGAN trained model. I did it in the past using TGAN using tgan.save command.

What I Did

It seems it's not possible to save models

Thanks for your jelp
mistborn17 commented 4 years ago

@diegobodner , did saving as pickle work?

oregonpillow commented 4 years ago

Hi @diegobodner, You need to import torch explicitly somewhere.

assuming you called your instance of the synthesiser 'ctgan' then it's pretty simple:

torch.save(ctgan,'my_awesome_model')
loaded_model = torch.load('my_awesome_model')
sample = loaded_model.sample(500)

Here's an example: https://colab.research.google.com/drive/1YBxeOlsATKt6zesv_O3HPCPR-G8sPPib

however, I'm currently getting ImportError: cannot import name '_is_url' error now when returned the sampled pandas data frame. Not sure if this is unique to the ColabNotebook I'm running in.

diegobodner commented 4 years ago

Many thanks!!

torch.save(ctgan,'my_awesome_model') works well.

Best regards

kveerama commented 4 years ago

Thanks @oregonpillow. Closing this for now.

RedBlue01 commented 6 months ago

Hi @diegobodner, You need to explicitly somewhere.import torch

assuming you called your instance of the synthesiser 'ctgan' then it's pretty simple:

torch.save(ctgan,'my_awesome_model')
loaded_model = torch.load('my_awesome_model')
sample = loaded_model.sample(500)

Here's an example: https://colab.research.google.com/drive/1YBxeOlsATKt6zesv_O3HPCPR-G8sPPib

however, I'm currently getting error now when returned the sampled pandas data frame. Not sure if this is unique to the ColabNotebook I'm running in.ImportError: cannot import name '_is_url'

I can't thank you enough.