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

Saving, load and testing for cyclegan_keras #6

Open
daniezest opened this issue May 20, 2018 · 6 comments
Open

Saving, load and testing for cyclegan_keras #6

daniezest opened this issue May 20, 2018 · 6 comments

Comments

@daniezest
Copy link

How do I save the model of cyclegan_keras?
Also how do i test the trained model?

Thanks!

@tjwei
Copy link
Owner

tjwei commented May 24, 2018

You use the methods mentioned here https://keras.io/getting-started/faq/#how-can-i-save-a-keras-model
to save/load keras models and/or weights.
The generators are netGB and netGA. The function showG shows how to use functions cycleA_generate and cycleA_generate to transform an image using trained models.

@daniezest
Copy link
Author

Thank you for the help.
I noticed that you tried your video swapping on CycleGAN-lasagne-fber.ipynb
Is it any different from cyclegan_keras?

I don't seem to be getting good generation loss for video swapping on cyclegan_keras.

Thanks!

@tjwei
Copy link
Owner

tjwei commented May 29, 2018

The keras version uses a unet as generator while the lasagne one uses resnet.

@rishab-sharma
Copy link

I was also trying to save the model, but I don't seem to find a model object in there to do model.save().
Can you please point which line in CGAN-keras
must be tweaked to save the model, and where is the model object to save iteratively.

@tjwei
Copy link
Owner

tjwei commented Jul 18, 2018

The generating models are defined in these lines.

netGB = UNET_G(imageSize, nc_in, nc_out, ngf)
netGA = UNET_G(imageSize, nc_out, nc_in, ngf)

You can save them after they are trained.

@viniciusarruda
Copy link

Just add this snippet at the end of the code:

def save_model(model, filepath):
    # serialize model to JSON
    model_json = model.to_json()
    with open("{}.json".format(filepath), "w") as json_file:
        json_file.write(model_json)
    # serialize weights to HDF5
    model.save_weights("{}.h5".format(filepath))

save_model(netDA, 'your/output/path/' + 'netDA')
save_model(netDB, 'your/output/path/' + 'netDB')
save_model(netGA, 'your/output/path/' + 'netGA')
save_model(netGB, 'your/output/path/' + 'netGB')

And you can load the model and than generate fake images with the trained model with this code I've made.

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

4 participants