Avoid race condition in creating checkpoint directories (#530)

* Avoid race condition in creating checkpoint directories

In multi-GPU training, several processes run the code that creates checkpoint dirs. This fix avoids a probably rare situation (but it happened to me) where another process created a dir between the `exists` check and the `makedirs` call.

* Remove the now unneeded check for dir existence
This commit is contained in:
Tanel Alumäe 2019-11-21 20:27:39 +02:00 committed by William Falcon
parent c1ecca418e
commit 539d7bcb44
1 changed files with 1 additions and 2 deletions

View File

@ -198,8 +198,7 @@ class ModelCheckpoint(Callback):
self.monitor = monitor
self.verbose = verbose
self.filepath = filepath
if not os.path.exists(filepath):
os.makedirs(filepath)
os.makedirs(filepath, exist_ok=True)
self.save_top_k = save_top_k
self.save_weights_only = save_weights_only
self.period = period