Saving, load and testing for cyclegan_keras
How do I save the model of cyclegan_keras? Also how do i test the trained model?
Thanks!
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.
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!
The keras version uses a unet as generator while the lasagne one uses resnet.
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.
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.
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.