tensorflow / lattice

Lattice methods in TensorFlow
Apache License 2.0
518 stars 94 forks source link

Cannot save keras model with tensorflow lattice layers #47

Closed devavratTomar closed 4 years ago

devavratTomar commented 4 years ago

Saving the model having keras tfl layers creates the following problem.

`/usr/local/lib/python3.6/dist-packages/h5py/_hl/group.py in setitem(self, name, obj) 371 372 if isinstance(obj, HLObject): --> 373 h5o.link(obj.id, self.id, name, lcpl=lcpl, lapl=self._lapl) 374 375 elif isinstance(obj, SoftLink):

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/h5o.pyx in h5py.h5o.link()

RuntimeError: Unable to create link (name already exists)`

The error is reproduced in the colab example here. https://colab.research.google.com/drive/1tknejj9CtM27bHGktsZSTnvLvH3eCgG8

wbakst commented 4 years ago

Hi! I looked through the colab that you linked but couldn't find any instances of model saving. Could you post a screenshot or code snippet that is causing the error so I can try to reproduce it on my end and see what's going on?

devavratTomar commented 4 years ago

Hi, Sorry I tried to debug the problem. The error is now reproducible on the colab. image image

devavratTomar commented 4 years ago

I think the problem is that we give same name to the weights for all the instances of a layer. That's why h5 complains that the key is already present while saving the weights

devavratTomar commented 4 years ago

https://github.com/tensorflow/lattice/blob/master/tensorflow_lattice/python/pwl_calibration_layer.py#L34

The names of weights are the same for all layers.

wbakst commented 4 years ago

This is indeed the case. Thank you for pointing this out! I am going to work on a fix now.

mmilanifard commented 4 years ago

Thanks for reporting the issue. Turns out we should not explicitly call the inner layer .build() during the build for the ParallelCombination layer. The next release will fix this issue.

mmilanifard commented 4 years ago

Fixed in 2.0.4.