https://www.tensorflow.org/beta/tutorials/generative/dcgan I am following this tutorial for a DCGAN and am trying to restore a model from the checkpoint I saved. But when I try to load the model, it gives me an error:
AssertionError: Nothing except the root object matched a checkpointed value. Typically this means that the checkpoint does not match the Python program. The following objects have no matching checkpointed value: [<tensorflow.python.keras.layers.advanced_activations.LeakyReLU object at 0x7f05b545fc88>, <tf.Variable 'conv2d_transpose_5/kernel:0' shape=(3, 3, 1, 64) dtype=float32, numpy=.......
I tried to modify the checkpoint by only keeping the generator part since that is all I need from here. After that, I do
latest = tf.train.latest_checkpoint(checkpoint_dir)
gen_mod = make_generator_model() #This is already defined in the code
gen_mod.load_weights(latest)
sample = gen_mod(noise,training=False)
which gives me the error. Is there a way to just load the generator part? What I want is to be able to generate images with the generator model from a given checkpoint.
Since, as you said, the DCGAN tutorial creates a snapshot of two models (a generator and a discriminator), load_weights
would have to select the weights relevant only to your generator and it lacks the context to do that.
Instead of trying to load the weights directly into a model, you can restore
the checkpoint and, from there, access the generator (or discriminator):
# from the DCGAN tutorial
checkpoint = tf.train.Checkpoint(
generator_optimizer=generator_optimizer,
discriminator_optimizer=discriminator_optimizer,
generator=generator,
discriminator=discriminator,
)
latest = tf.train.latest_checkpoint(checkpoint_dir)
checkpoint.restore(latest)
# classify an image
checkpoint.discriminator(training_images[0:2])
# generate an image
checkpoint.generator(noise)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With