Skip to content

Commit

Permalink
load_weights() now properly closes file (keras-team#13048)
Browse files Browse the repository at this point in the history
In certain use cases, load_weights() would cause OSError if called repeatedly on many different files. The proposed addition will now make sure the HDF5 files are closed before exiting.
  • Loading branch information
bthorsted authored and fchollet committed Jul 3, 2019
1 parent d952f0c commit f06524c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions keras/engine/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,10 @@ def load_weights(self, filepath, by_name=False,
else:
saving.load_weights_from_hdf5_group(
f, self.layers, reshape=reshape)
if hasattr(f, 'close'):
f.close()
elif hasattr(f.file, 'close'):
f.file.close()

def _updated_config(self):
"""Util hared between different serialization methods.
Expand Down

0 comments on commit f06524c

Please sign in to comment.