keras-io icon indicating copy to clipboard operation
keras-io copied to clipboard

CycleGan save error

Open antoine-l opened this issue 4 years ago • 1 comments
trafficstars

Hi,

I'm running the Colab of CycleGan as is (https://colab.research.google.com/github/keras-team/keras-io/blob/master/examples/generative/ipynb/cyclegan.ipynb) and have the following error:

ValueError Traceback (most recent call last) in () 42 tf.data.Dataset.zip((train_horses, train_zebras)), 43 epochs=1, ---> 44 callbacks=[plotter, model_checkpoint_callback], 45 )

7 frames /usr/local/lib/python3.7/dist-packages/keras/saving/saving_utils.py in raise_model_input_error(model) 86 'set. Usually, input shapes are automatically determined from calling' 87 ' .fit() or .predict(). To manually set the shapes, call ' ---> 88 'model.build(input_shape).'.format(model)) 89 90

ValueError: Model <main.CycleGan object at 0x7f1515ca2b50> cannot be saved because the input shapes have not been set. Usually, input shapes are automatically determined from calling .fit() or .predict(). To manually set the shapes, call model.build(input_shape).

I tried different fixes but they just gave me different errors:

  cycle_gan_model.compute_output_shape(input_shape=(None, 256, 256, 3))
  cycle_gan_model.build((None, 256, 256, 3))

What can I do to fix it?

Thank you!

antoine-l avatar Nov 03 '21 02:11 antoine-l

I solved the problem by adding a call method to the CycleGan class.

    def call(self, inputs, training=None, mask=None):
        return self.disc_X(inputs), self.disc_Y(inputs), self.gen_G(inputs), self.gen_F(inputs)

Then specify the input size like this.

  cycle_gan_model.compute_output_shape(input_shape=(None, 256, 256, 3))

ossan-tamago avatar Jun 14 '22 03:06 ossan-tamago

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

github-actions[bot] avatar May 08 '24 01:05 github-actions[bot]