1# Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15"""Tests for backend_config.""" 16from __future__ import absolute_import 17from __future__ import division 18from __future__ import print_function 19 20from tensorflow.python import keras 21from tensorflow.python.framework import test_util 22from tensorflow.python.platform import test 23 24 25@test_util.run_all_in_graph_and_eager_modes 26class BackendConfigTest(test.TestCase): 27 28 def test_backend(self): 29 self.assertEqual(keras.backend.backend(), 'tensorflow') 30 31 def test_espilon(self): 32 epsilon = 1e-2 33 keras.backend_config.set_epsilon(epsilon) 34 self.assertEqual(keras.backend_config.epsilon(), epsilon) 35 keras.backend_config.set_epsilon(1e-7) 36 self.assertEqual(keras.backend_config.epsilon(), 1e-7) 37 38 def test_floatx(self): 39 floatx = 'float64' 40 keras.backend_config.set_floatx(floatx) 41 self.assertEqual(keras.backend_config.floatx(), floatx) 42 keras.backend_config.set_floatx('float32') 43 self.assertEqual(keras.backend_config.floatx(), 'float32') 44 45 def test_image_data_format(self): 46 image_data_format = 'channels_first' 47 keras.backend_config.set_image_data_format(image_data_format) 48 self.assertEqual(keras.backend_config.image_data_format(), 49 image_data_format) 50 keras.backend_config.set_image_data_format('channels_last') 51 self.assertEqual(keras.backend_config.image_data_format(), 'channels_last') 52 53 54if __name__ == '__main__': 55 test.main() 56