From db1e40b9c5ad3c6acc36b0d33e08058787b11725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cjaketae=E2=80=9D?= Date: Wed, 11 Mar 2020 08:29:05 +0900 Subject: [PATCH] Edited docstrings, added unit test, and fixed minor typos --- tensorflow/python/keras/applications/densenet.py | 4 +++- .../python/keras/applications/imagenet_utils.py | 16 +++++++++++++--- .../keras/applications/imagenet_utils_test.py | 5 +++++ .../keras/applications/inception_resnet_v2.py | 4 +++- .../python/keras/applications/inception_v3.py | 4 +++- .../python/keras/applications/mobilenet.py | 4 +++- .../python/keras/applications/mobilenet_v2.py | 4 +++- tensorflow/python/keras/applications/nasnet.py | 4 +++- tensorflow/python/keras/applications/resnet.py | 4 +++- .../python/keras/applications/resnet_v2.py | 4 +++- tensorflow/python/keras/applications/vgg16.py | 4 +++- tensorflow/python/keras/applications/vgg19.py | 3 ++- 12 files changed, 47 insertions(+), 13 deletions(-) diff --git a/tensorflow/python/keras/applications/densenet.py b/tensorflow/python/keras/applications/densenet.py index 9b11c342536..2dfd1482fbf 100644 --- a/tensorflow/python/keras/applications/densenet.py +++ b/tensorflow/python/keras/applications/densenet.py @@ -393,7 +393,9 @@ def decode_predictions(preds, top=5): preprocess_input.__doc__ = imagenet_utils.PREPROCESS_INPUT_DOC.format( - mode='', ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_TORCH) + mode='', + ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_TORCH, + error=imagenet_utils.PREPROCESS_INPUT_ERROR_DOC) decode_predictions.__doc__ = imagenet_utils.decode_predictions.__doc__ DOC = """ diff --git a/tensorflow/python/keras/applications/imagenet_utils.py b/tensorflow/python/keras/applications/imagenet_utils.py index 4b73b1c9bf9..5de98527cf4 100644 --- a/tensorflow/python/keras/applications/imagenet_utils.py +++ b/tensorflow/python/keras/applications/imagenet_utils.py @@ -66,7 +66,7 @@ PREPROCESS_INPUT_DOC = """ {ret} Raises: - ValueError: In case of unknown `mode` or `data_format` argument. + {error} """ PREPROCESS_INPUT_MODE_DOC = """ @@ -82,12 +82,21 @@ PREPROCESS_INPUT_MODE_DOC = """ ImageNet dataset. """ +PREPROCESS_INPUT_DEFAULT_ERROR_DOC = """ + ValueError: In case of unknown `mode` or `data_format` argument. + """ + +PREPROCESS_INPUT_ERROR_DOC = """ + ValueError: In case of unknown `data_format` argument. + """ + + PREPROCESS_INPUT_RET_DOC_TF = """ The inputs pixel values are scaled between -1 and 1, sample-wise.""" PREPROCESS_INPUT_RET_DOC_TORCH = """ The input pixels values are scaled between 0 and 1 and each channel is - normalized with respect to the InageNet dataset.""" + normalized with respect to the ImageNet dataset.""" PREPROCESS_INPUT_RET_DOC_CAFFE = """ The images are converted from RGB to BGR, then each color channel is @@ -114,7 +123,8 @@ def preprocess_input(x, data_format=None, mode='caffe'): preprocess_input.__doc__ = PREPROCESS_INPUT_DOC.format( - mode=PREPROCESS_INPUT_MODE_DOC, ret='') + mode=PREPROCESS_INPUT_MODE_DOC, ret='', + error=PREPROCESS_INPUT_DEFAULT_ERROR_DOC) @keras_export('keras.applications.imagenet_utils.decode_predictions') diff --git a/tensorflow/python/keras/applications/imagenet_utils_test.py b/tensorflow/python/keras/applications/imagenet_utils_test.py index f37ae8c188c..7f7698606d7 100644 --- a/tensorflow/python/keras/applications/imagenet_utils_test.py +++ b/tensorflow/python/keras/applications/imagenet_utils_test.py @@ -29,6 +29,11 @@ from tensorflow.python.platform import test class TestImageNetUtils(keras_parameterized.TestCase): def test_preprocess_input(self): + # Test invalid mode check + x = np.random.uniform(0, 255, (10, 10, 3)) + with self.assertRaises(ValueError): + utils.preprocess_input(x, mode='some_unknown_mode') + # Test image batch with float and int image input x = np.random.uniform(0, 255, (2, 10, 10, 3)) xint = x.astype('int32') diff --git a/tensorflow/python/keras/applications/inception_resnet_v2.py b/tensorflow/python/keras/applications/inception_resnet_v2.py index 7f338f82597..51b52eaf3d6 100644 --- a/tensorflow/python/keras/applications/inception_resnet_v2.py +++ b/tensorflow/python/keras/applications/inception_resnet_v2.py @@ -412,5 +412,7 @@ def decode_predictions(preds, top=5): preprocess_input.__doc__ = imagenet_utils.PREPROCESS_INPUT_DOC.format( - mode='', ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_TF) + mode='', + ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_TF, + error=imagenet_utils.PREPROCESS_INPUT_ERROR_DOC) decode_predictions.__doc__ = imagenet_utils.decode_predictions.__doc__ diff --git a/tensorflow/python/keras/applications/inception_v3.py b/tensorflow/python/keras/applications/inception_v3.py index fa44becfe48..6a130b8ba49 100644 --- a/tensorflow/python/keras/applications/inception_v3.py +++ b/tensorflow/python/keras/applications/inception_v3.py @@ -440,5 +440,7 @@ def decode_predictions(preds, top=5): preprocess_input.__doc__ = imagenet_utils.PREPROCESS_INPUT_DOC.format( - mode='', ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_TF) + mode='', + ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_TF, + error=imagenet_utils.PREPROCESS_INPUT_ERROR_DOC) decode_predictions.__doc__ = imagenet_utils.decode_predictions.__doc__ diff --git a/tensorflow/python/keras/applications/mobilenet.py b/tensorflow/python/keras/applications/mobilenet.py index d935282f98a..806fafd42c4 100644 --- a/tensorflow/python/keras/applications/mobilenet.py +++ b/tensorflow/python/keras/applications/mobilenet.py @@ -473,5 +473,7 @@ def decode_predictions(preds, top=5): preprocess_input.__doc__ = imagenet_utils.PREPROCESS_INPUT_DOC.format( - mode='', ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_TF) + mode='', + ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_TF, + error=imagenet_utils.PREPROCESS_INPUT_ERROR_DOC) decode_predictions.__doc__ = imagenet_utils.decode_predictions.__doc__ diff --git a/tensorflow/python/keras/applications/mobilenet_v2.py b/tensorflow/python/keras/applications/mobilenet_v2.py index bdd21c3da62..7dc0fd907eb 100644 --- a/tensorflow/python/keras/applications/mobilenet_v2.py +++ b/tensorflow/python/keras/applications/mobilenet_v2.py @@ -506,5 +506,7 @@ def decode_predictions(preds, top=5): preprocess_input.__doc__ = imagenet_utils.PREPROCESS_INPUT_DOC.format( - mode='', ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_TF) + mode='', + ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_TF, + error=imagenet_utils.PREPROCESS_INPUT_ERROR_DOC) decode_predictions.__doc__ = imagenet_utils.decode_predictions.__doc__ diff --git a/tensorflow/python/keras/applications/nasnet.py b/tensorflow/python/keras/applications/nasnet.py index 3da415dbb12..238f3c9c64d 100644 --- a/tensorflow/python/keras/applications/nasnet.py +++ b/tensorflow/python/keras/applications/nasnet.py @@ -819,5 +819,7 @@ def decode_predictions(preds, top=5): preprocess_input.__doc__ = imagenet_utils.PREPROCESS_INPUT_DOC.format( - mode='', ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_TF) + mode='', + ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_TF, + error=imagenet_utils.PREPROCESS_INPUT_ERROR_DOC) decode_predictions.__doc__ = imagenet_utils.decode_predictions.__doc__ diff --git a/tensorflow/python/keras/applications/resnet.py b/tensorflow/python/keras/applications/resnet.py index 3e33bb04bdd..1713e823b1c 100644 --- a/tensorflow/python/keras/applications/resnet.py +++ b/tensorflow/python/keras/applications/resnet.py @@ -553,7 +553,9 @@ def decode_predictions(preds, top=5): preprocess_input.__doc__ = imagenet_utils.PREPROCESS_INPUT_DOC.format( - mode='', ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_CAFFE) + mode='', + ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_CAFFE, + error=imagenet_utils.PREPROCESS_INPUT_ERROR_DOC) decode_predictions.__doc__ = imagenet_utils.decode_predictions.__doc__ DOC = """ diff --git a/tensorflow/python/keras/applications/resnet_v2.py b/tensorflow/python/keras/applications/resnet_v2.py index 2e1ee272c4b..aa52d0047f0 100644 --- a/tensorflow/python/keras/applications/resnet_v2.py +++ b/tensorflow/python/keras/applications/resnet_v2.py @@ -164,7 +164,9 @@ def decode_predictions(preds, top=5): preprocess_input.__doc__ = imagenet_utils.PREPROCESS_INPUT_DOC.format( - mode='', ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_CAFFE) + mode='', + ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_TF, + error=imagenet_utils.PREPROCESS_INPUT_ERROR_DOC) decode_predictions.__doc__ = imagenet_utils.decode_predictions.__doc__ DOC = """ diff --git a/tensorflow/python/keras/applications/vgg16.py b/tensorflow/python/keras/applications/vgg16.py index 534d2cff6be..b1f3cbfa52e 100644 --- a/tensorflow/python/keras/applications/vgg16.py +++ b/tensorflow/python/keras/applications/vgg16.py @@ -262,5 +262,7 @@ def decode_predictions(preds, top=5): preprocess_input.__doc__ = imagenet_utils.PREPROCESS_INPUT_DOC.format( - mode='', ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_CAFFE) + mode='', + ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_CAFFE, + error=imagenet_utils.PREPROCESS_INPUT_ERROR_DOC) decode_predictions.__doc__ = imagenet_utils.decode_predictions.__doc__ diff --git a/tensorflow/python/keras/applications/vgg19.py b/tensorflow/python/keras/applications/vgg19.py index 81c90e1ebb4..90605d40b51 100644 --- a/tensorflow/python/keras/applications/vgg19.py +++ b/tensorflow/python/keras/applications/vgg19.py @@ -267,5 +267,6 @@ def decode_predictions(preds, top=5): preprocess_input.__doc__ = imagenet_utils.PREPROCESS_INPUT_DOC.format( - mode='', ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_CAFFE) + mode='', ret=imagenet_utils.PREPROCESS_INPUT_RET_DOC_CAFFE, + error=imagenet_utils.PREPROCESS_INPUT_ERROR_DOC) decode_predictions.__doc__ = imagenet_utils.decode_predictions.__doc__