diff options
author | 2017-04-11 10:32:40 -0800 | |
---|---|---|
committer | 2017-04-11 11:48:22 -0700 | |
commit | 59d82b9133616c88af00340260f475d7e2af4c59 (patch) | |
tree | 341194dfd0268447991697f575a6071d9651090a | |
parent | 4e69ce821b5d6f579223f4adaf2987460767ab0e (diff) |
Gracefully exit on writing config file.
Change: 152837817
-rw-r--r-- | tensorflow/contrib/keras/python/keras/backend.py | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/tensorflow/contrib/keras/python/keras/backend.py b/tensorflow/contrib/keras/python/keras/backend.py index d149138796..b35ee5db09 100644 --- a/tensorflow/contrib/keras/python/keras/backend.py +++ b/tensorflow/contrib/keras/python/keras/backend.py @@ -3627,21 +3627,24 @@ if os.path.exists(_config_path): set_image_data_format(_image_data_format) # Save config file. -if os.access(_keras_base_dir, os.W_OK): - if not os.path.exists(_keras_dir): - try: - os.makedirs(_keras_dir) - except OSError: - # Except potential race conditions - # in multi-threaded environments. - pass - - if not os.path.exists(_config_path): - _config = { - 'floatx': floatx(), - 'epsilon': epsilon(), - 'backend': 'tensorflow', - 'image_data_format': image_data_format() - } +if not os.path.exists(_keras_dir): + try: + os.makedirs(_keras_dir) + except OSError: + # Except permission denied and potential race conditions + # in multi-threaded environments. + pass + +if not os.path.exists(_config_path): + _config = { + 'floatx': floatx(), + 'epsilon': epsilon(), + 'backend': 'tensorflow', + 'image_data_format': image_data_format() + } + try: with open(_config_path, 'w') as f: f.write(json.dumps(_config, indent=4)) + except IOError: + # Except permission denied. + pass |