From d8bb6569bc6c820b098fc0b56c3c1a7a318422a9 Mon Sep 17 00:00:00 2001 From: Yixing Fu Date: Fri, 5 Jun 2020 18:55:32 -0400 Subject: [PATCH 01/11] correct summing total blocks --- tensorflow/python/keras/applications/efficientnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/keras/applications/efficientnet.py b/tensorflow/python/keras/applications/efficientnet.py index e1413b08533..e3c1a261e80 100644 --- a/tensorflow/python/keras/applications/efficientnet.py +++ b/tensorflow/python/keras/applications/efficientnet.py @@ -334,7 +334,7 @@ def EfficientNet( blocks_args = copy.deepcopy(blocks_args) b = 0 - blocks = float(sum(args['repeats'] for args in blocks_args)) + blocks = float(sum(round_repeats(args['repeats']) for args in blocks_args)) for (i, args) in enumerate(blocks_args): assert args['repeats'] > 0 # Update block input and output filters based on depth multiplier. From 1363f0f6e89cdc73ca46d43475bdb35750ed2e50 Mon Sep 17 00:00:00 2001 From: Yixing Fu Date: Thu, 18 Jun 2020 19:28:34 -0400 Subject: [PATCH 02/11] add save load test for pathlib path --- tensorflow/python/keras/saving/save_test.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tensorflow/python/keras/saving/save_test.py b/tensorflow/python/keras/saving/save_test.py index 5c5846fe738..98d78735ad1 100644 --- a/tensorflow/python/keras/saving/save_test.py +++ b/tensorflow/python/keras/saving/save_test.py @@ -71,6 +71,12 @@ class TestSaveModel(test.TestCase, parameterized.TestCase): save.save_model(self.model, path) self.assert_saved_model(path) + @test_util.run_v2_only + def test_save_format_defaults_pathlib(self): + path = pathlib.Path(self.get_temp_dir()) / 'model_path' + save.save_model(self.model, path) + self.assert_saved_model(path) + @test_util.run_v2_only def test_save_hdf5(self): path = os.path.join(self.get_temp_dir(), 'model') @@ -81,6 +87,13 @@ class TestSaveModel(test.TestCase, parameterized.TestCase): 'requires the model to be a Functional model or a Sequential model.'): save.save_model(self.subclassed_model, path, save_format='h5') + @test_util.run_v2_only + def test_save_load_hdf5_pathlib(self): + if sys.version_info >= (3, 6): + path = pathlib.Path(self.get_temp_dir()) / 'model' + save.save_model(self.model, path, save_format='h5') + save.load_model(path) + @test_util.run_v2_only def test_save_tf(self): path = os.path.join(self.get_temp_dir(), 'model') From 1c72a6c65e1733b55286c6361142a39d699732dc Mon Sep 17 00:00:00 2001 From: Yixing Fu Date: Thu, 18 Jun 2020 19:53:22 -0400 Subject: [PATCH 03/11] convert export_dir as pathlike object to str in parse_saved_model --- tensorflow/python/saved_model/loader_impl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorflow/python/saved_model/loader_impl.py b/tensorflow/python/saved_model/loader_impl.py index 2df2bea428e..71f6ed16c9d 100644 --- a/tensorflow/python/saved_model/loader_impl.py +++ b/tensorflow/python/saved_model/loader_impl.py @@ -83,11 +83,11 @@ def parse_saved_model(export_dir): """ # Build the path to the SavedModel in pbtxt format. path_to_pbtxt = os.path.join( - compat.as_bytes(export_dir), + compat.as_bytes(compat.path_to_str(export_dir)), compat.as_bytes(constants.SAVED_MODEL_FILENAME_PBTXT)) # Build the path to the SavedModel in pb format. path_to_pb = os.path.join( - compat.as_bytes(export_dir), + compat.as_bytes(compat.path_to_str(export_dir)), compat.as_bytes(constants.SAVED_MODEL_FILENAME_PB)) # Parse the SavedModel protocol buffer. From 5f2e0240ee7977042e41d9c29c349a7b14301290 Mon Sep 17 00:00:00 2001 From: Yixing Fu Date: Thu, 18 Jun 2020 19:57:23 -0400 Subject: [PATCH 04/11] modify docstring --- tensorflow/python/saved_model/loader_impl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/saved_model/loader_impl.py b/tensorflow/python/saved_model/loader_impl.py index 71f6ed16c9d..06cd988130d 100644 --- a/tensorflow/python/saved_model/loader_impl.py +++ b/tensorflow/python/saved_model/loader_impl.py @@ -73,7 +73,7 @@ def parse_saved_model(export_dir): """Reads the savedmodel.pb or savedmodel.pbtxt file containing `SavedModel`. Args: - export_dir: Directory containing the SavedModel file. + export_dir: String or Pathlike, path to the directory containing the SavedModel file. Returns: A `SavedModel` protocol buffer. From c3ca4da9b46e3148bdb913d08fec3fd2727158e1 Mon Sep 17 00:00:00 2001 From: Yixing Fu Date: Thu, 18 Jun 2020 20:00:06 -0400 Subject: [PATCH 05/11] only test pathlib on python v>3.6 --- tensorflow/python/keras/saving/save_test.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tensorflow/python/keras/saving/save_test.py b/tensorflow/python/keras/saving/save_test.py index 98d78735ad1..66364666841 100644 --- a/tensorflow/python/keras/saving/save_test.py +++ b/tensorflow/python/keras/saving/save_test.py @@ -73,9 +73,10 @@ class TestSaveModel(test.TestCase, parameterized.TestCase): @test_util.run_v2_only def test_save_format_defaults_pathlib(self): - path = pathlib.Path(self.get_temp_dir()) / 'model_path' - save.save_model(self.model, path) - self.assert_saved_model(path) + if sys.version_info >= (3, 6): + path = pathlib.Path(self.get_temp_dir()) / 'model_path' + save.save_model(self.model, path) + self.assert_saved_model(path) @test_util.run_v2_only def test_save_hdf5(self): From 965b93f2ee2ecf6dc7152adc31a76802b0ede85f Mon Sep 17 00:00:00 2001 From: Yixing Fu Date: Thu, 18 Jun 2020 20:05:14 -0400 Subject: [PATCH 06/11] test pathlib path for save weights --- tensorflow/python/keras/saving/save_test.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tensorflow/python/keras/saving/save_test.py b/tensorflow/python/keras/saving/save_test.py index 66364666841..5b5da8c5047 100644 --- a/tensorflow/python/keras/saving/save_test.py +++ b/tensorflow/python/keras/saving/save_test.py @@ -119,6 +119,20 @@ class TestSaveModel(test.TestCase, parameterized.TestCase): save.save_model(self.model, path, save_format='tf') save.load_model(path) + @test_util.run_v2_only + def test_save_load_weights_tf_pathlib(self): + if sys.version_info >= (3, 6): + path = pathlib.Path(self.get_temp_dir()) / 'model' + self.model.save_weights(path, save_format='tf') + self.model.load_weights(path) + + @test_util.run_v2_only + def test_save_load_weights_hdf5_pathlib(self): + if sys.version_info >= (3, 6): + path = pathlib.Path(self.get_temp_dir()) / 'model' + self.model.save_weights(path, save_format='h5') + self.model.load_weights(path) + @combinations.generate(combinations.combine(mode=['graph', 'eager'])) def test_saving_with_dense_features(self): cols = [ From 55e33877b8f81b5ede6365456ed3aa89bbe16d8e Mon Sep 17 00:00:00 2001 From: Yixing Fu Date: Thu, 18 Jun 2020 20:37:52 -0400 Subject: [PATCH 07/11] Revert "test pathlib path for save weights" This reverts commit 965b93f2ee2ecf6dc7152adc31a76802b0ede85f. --- tensorflow/python/keras/saving/save_test.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tensorflow/python/keras/saving/save_test.py b/tensorflow/python/keras/saving/save_test.py index 5b5da8c5047..66364666841 100644 --- a/tensorflow/python/keras/saving/save_test.py +++ b/tensorflow/python/keras/saving/save_test.py @@ -119,20 +119,6 @@ class TestSaveModel(test.TestCase, parameterized.TestCase): save.save_model(self.model, path, save_format='tf') save.load_model(path) - @test_util.run_v2_only - def test_save_load_weights_tf_pathlib(self): - if sys.version_info >= (3, 6): - path = pathlib.Path(self.get_temp_dir()) / 'model' - self.model.save_weights(path, save_format='tf') - self.model.load_weights(path) - - @test_util.run_v2_only - def test_save_load_weights_hdf5_pathlib(self): - if sys.version_info >= (3, 6): - path = pathlib.Path(self.get_temp_dir()) / 'model' - self.model.save_weights(path, save_format='h5') - self.model.load_weights(path) - @combinations.generate(combinations.combine(mode=['graph', 'eager'])) def test_saving_with_dense_features(self): cols = [ From edc445eb184633f0ca10270bca6e9c0b834ab454 Mon Sep 17 00:00:00 2001 From: Yixing Fu Date: Thu, 18 Jun 2020 20:38:02 -0400 Subject: [PATCH 08/11] Revert "only test pathlib on python v>3.6" This reverts commit c3ca4da9b46e3148bdb913d08fec3fd2727158e1. --- tensorflow/python/keras/saving/save_test.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tensorflow/python/keras/saving/save_test.py b/tensorflow/python/keras/saving/save_test.py index 66364666841..98d78735ad1 100644 --- a/tensorflow/python/keras/saving/save_test.py +++ b/tensorflow/python/keras/saving/save_test.py @@ -73,10 +73,9 @@ class TestSaveModel(test.TestCase, parameterized.TestCase): @test_util.run_v2_only def test_save_format_defaults_pathlib(self): - if sys.version_info >= (3, 6): - path = pathlib.Path(self.get_temp_dir()) / 'model_path' - save.save_model(self.model, path) - self.assert_saved_model(path) + path = pathlib.Path(self.get_temp_dir()) / 'model_path' + save.save_model(self.model, path) + self.assert_saved_model(path) @test_util.run_v2_only def test_save_hdf5(self): From 10fb2155fb720f9e0e70d9e48a934383b4b42c91 Mon Sep 17 00:00:00 2001 From: Yixing Fu Date: Thu, 18 Jun 2020 20:38:08 -0400 Subject: [PATCH 09/11] Revert "modify docstring" This reverts commit 5f2e0240ee7977042e41d9c29c349a7b14301290. --- tensorflow/python/saved_model/loader_impl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/saved_model/loader_impl.py b/tensorflow/python/saved_model/loader_impl.py index 06cd988130d..71f6ed16c9d 100644 --- a/tensorflow/python/saved_model/loader_impl.py +++ b/tensorflow/python/saved_model/loader_impl.py @@ -73,7 +73,7 @@ def parse_saved_model(export_dir): """Reads the savedmodel.pb or savedmodel.pbtxt file containing `SavedModel`. Args: - export_dir: String or Pathlike, path to the directory containing the SavedModel file. + export_dir: Directory containing the SavedModel file. Returns: A `SavedModel` protocol buffer. From 9f0e739f5f1623b74c1835e9209c7c25b4c49380 Mon Sep 17 00:00:00 2001 From: Yixing Fu Date: Thu, 18 Jun 2020 20:38:15 -0400 Subject: [PATCH 10/11] Revert "convert export_dir as pathlike object to str in parse_saved_model" This reverts commit 1c72a6c65e1733b55286c6361142a39d699732dc. --- tensorflow/python/saved_model/loader_impl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorflow/python/saved_model/loader_impl.py b/tensorflow/python/saved_model/loader_impl.py index 71f6ed16c9d..2df2bea428e 100644 --- a/tensorflow/python/saved_model/loader_impl.py +++ b/tensorflow/python/saved_model/loader_impl.py @@ -83,11 +83,11 @@ def parse_saved_model(export_dir): """ # Build the path to the SavedModel in pbtxt format. path_to_pbtxt = os.path.join( - compat.as_bytes(compat.path_to_str(export_dir)), + compat.as_bytes(export_dir), compat.as_bytes(constants.SAVED_MODEL_FILENAME_PBTXT)) # Build the path to the SavedModel in pb format. path_to_pb = os.path.join( - compat.as_bytes(compat.path_to_str(export_dir)), + compat.as_bytes(export_dir), compat.as_bytes(constants.SAVED_MODEL_FILENAME_PB)) # Parse the SavedModel protocol buffer. From 5869f657624ece35544c3fe54f999b2e3f449305 Mon Sep 17 00:00:00 2001 From: Yixing Fu Date: Thu, 18 Jun 2020 20:38:24 -0400 Subject: [PATCH 11/11] Revert "add save load test for pathlib path" This reverts commit 1363f0f6e89cdc73ca46d43475bdb35750ed2e50. --- tensorflow/python/keras/saving/save_test.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tensorflow/python/keras/saving/save_test.py b/tensorflow/python/keras/saving/save_test.py index 98d78735ad1..5c5846fe738 100644 --- a/tensorflow/python/keras/saving/save_test.py +++ b/tensorflow/python/keras/saving/save_test.py @@ -71,12 +71,6 @@ class TestSaveModel(test.TestCase, parameterized.TestCase): save.save_model(self.model, path) self.assert_saved_model(path) - @test_util.run_v2_only - def test_save_format_defaults_pathlib(self): - path = pathlib.Path(self.get_temp_dir()) / 'model_path' - save.save_model(self.model, path) - self.assert_saved_model(path) - @test_util.run_v2_only def test_save_hdf5(self): path = os.path.join(self.get_temp_dir(), 'model') @@ -87,13 +81,6 @@ class TestSaveModel(test.TestCase, parameterized.TestCase): 'requires the model to be a Functional model or a Sequential model.'): save.save_model(self.subclassed_model, path, save_format='h5') - @test_util.run_v2_only - def test_save_load_hdf5_pathlib(self): - if sys.version_info >= (3, 6): - path = pathlib.Path(self.get_temp_dir()) / 'model' - save.save_model(self.model, path, save_format='h5') - save.load_model(path) - @test_util.run_v2_only def test_save_tf(self): path = os.path.join(self.get_temp_dir(), 'model')