load_weights() now properly closes file
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.
@@ -1215,6 +1215,10 @@ class Network(Layer):
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.
