From f09b9b0ab706cfe25994a7ed35066e61e5af5d8f Mon Sep 17 00:00:00 2001 From: nikochiko Date: Mon, 18 Nov 2019 23:36:54 +0530 Subject: [PATCH 01/15] Revert "Update save.py" This reverts commit fdadd0e5e524df6488cd763c4ab7595d469ed1ef. --- tensorflow/python/keras/saving/save.py | 44 +++++--------------------- 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/tensorflow/python/keras/saving/save.py b/tensorflow/python/keras/saving/save.py index 9f7f5778afe..4be3aa0bbda 100644 --- a/tensorflow/python/keras/saving/save.py +++ b/tensorflow/python/keras/saving/save.py @@ -23,7 +23,6 @@ import os import six from tensorflow.python import tf2 -from tensorflow.python.keras.engine.network import _is_hdf5_filepath from tensorflow.python.keras.saving import hdf5_format from tensorflow.python.keras.saving.saved_model import load as saved_model_load from tensorflow.python.keras.saving.saved_model import save as saved_model_save @@ -37,6 +36,9 @@ except ImportError: h5py = None # pylint: enable=g-import-not-at-top +_HDF5_EXTENSIONS = ['.h5', '.hdf5', '.keras'] + + # TODO(kathywu): Remove this when Keras SavedModel is not experimental. _KERAS_SAVED_MODEL_STILL_EXPERIMENTAL = True @@ -90,42 +92,12 @@ def save_model(model, """ from tensorflow.python.keras.engine import sequential # pylint: disable=g-import-not-at-top - if type(filepath) != str and not isinstance(filepath, h5py.File): - raise ValueError( - 'Expected `filepath` to be a String or `h5py.File` object. Got' - 'unsupported value %s of type %s' - % (filepath, type(filepath))) + default_format = 'tf' if tf2.enabled() else 'h5' + save_format = save_format or default_format - filepath_is_h5py_file = h5py is not None and isinstance(filepath, h5py.File) - filepath_is_h5 = type(filepath) == str and _is_hdf5_filepath(filepath) - if save_format is None: - if (filepath_is_h5 or - (filepath_is_h5py_file)): - save_format = 'h5' - else: - save_format = 'tf' if tf2.enabled() else 'h5' - else: - user_format = save_format.lower().strip() - if user_format in ('tensorflow', 'tf'): - save_format = 'tf' - elif user_format in ('hdf5', 'h5', 'keras'): - save_format = 'h5' - else: - raise ValueError( - 'Unknown format "%s". Was expecting one of {"tf", "h5"}.' % ( - save_format,)) - if save_format == 'tf' and filepath_is_h5: - raise ValueError( - ('`save` got save_format="tf"/"tensorflow", but the ' - 'filepath ("%s") looks like an HDF5 file. Omit the ".h5"/".keras" ' - 'when saving in TensorFlow format.') - % filepath) - if save_format == 'tf' and filepath_is_h5py_file: - raise ValueError( - '`save` got save_format="tf"/"tensorflow", but the given `filepath`' - 'is an `h5py.File` object.') - - if save_format == 'h5': + if (save_format == 'h5' or + (h5py is not None and isinstance(filepath, h5py.File)) or + os.path.splitext(filepath)[1] in _HDF5_EXTENSIONS): # TODO(b/130258301): add utility method for detecting model type. if (not model._is_graph_network and # pylint:disable=protected-access not isinstance(model, sequential.Sequential)): From ae86fd4b96ee934a8af239b5d01381bba8a470f1 Mon Sep 17 00:00:00 2001 From: nikochiko Date: Wed, 20 Nov 2019 15:48:54 +0530 Subject: [PATCH 02/15] Update docstring for tf.ensure_shape Update docstring Enhance example. --- tensorflow/python/ops/check_ops.py | 42 ++++++++++++++++++------------ 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/tensorflow/python/ops/check_ops.py b/tensorflow/python/ops/check_ops.py index 34106f61fd8..68546d792a8 100644 --- a/tensorflow/python/ops/check_ops.py +++ b/tensorflow/python/ops/check_ops.py @@ -144,7 +144,7 @@ def _unary_assert_doc(sym, sym_name): Raises: InvalidArgumentError: if the check can be performed immediately and - `x {sym}` is False. The check can be performed immediately during + `x {sym}` is False. The check can be performed immediately during eager execution or if `x` is statically known. """.format( sym=sym, sym_name=cap_sym_name, opname=opname) @@ -207,7 +207,7 @@ def _binary_assert_doc(sym): Raises: InvalidArgumentError: if the check can be performed immediately and - `x {sym} y` is False. The check can be performed immediately during + `x {sym} y` is False. The check can be performed immediately during eager execution or if `x` and `y` are statically known. """.format( sym=sym, opname=opname) @@ -2107,24 +2107,30 @@ def ensure_shape(x, shape, name=None): """Updates the shape of a tensor and checks at runtime that the shape holds. For example: - ```python - x = tf.compat.v1.placeholder(tf.int32) - print(x.shape) - ==> TensorShape(None) - y = x * 2 - print(y.shape) - ==> TensorShape(None) + + >>> # tf.placeholder() is not compatible with eager execution + ... + >>> tf.compat.v1.disable_eager_execution() + >>> x = tf.compat.v1.placeholder(tf.int32) + >>> print(x.shape) + TensorShape(None) + >>> y = x * 2 + >>> print(y.shape) + TensorShape(None) y = tf.ensure_shape(y, (None, 3, 3)) print(y.shape) - ==> TensorShape([Dimension(None), Dimension(3), Dimension(3)]) + TensorShape([None, 3, 3]) - with tf.compat.v1.Session() as sess: - # Raises tf.errors.InvalidArgumentError, because the shape (3,) is not - # compatible with the shape (None, 3, 3) - sess.run(y, feed_dict={x: [1, 2, 3]}) + >>> with tf.compat.v1.Session() as sess: + >>> sess.run(y, feed_dict={x: [1, 2, 3]}) + Traceback (most recent call last): + ... + InvalidArgumentError: Shape of tensor mul [3] is not compatible with + expected shape [?,3,3]. - ``` + The above example raises `tf.errors.InvalidArgumentError`, + because the shape (3,) is not compatible with the shape (None, 3, 3) NOTE: This differs from `Tensor.set_shape` in that it sets the static shape of the resulting tensor and enforces it at runtime, raising an error if the @@ -2140,8 +2146,10 @@ def ensure_shape(x, shape, name=None): name: A name for this operation (optional). Defaults to "EnsureShape". Returns: - A `Tensor`. Has the same type and contents as `x`. At runtime, raises a - `tf.errors.InvalidArgumentError` if `shape` is incompatible with the shape + A `Tensor`. Has the same type and contents as `x`. + + Raises: + tf.errors.InvalidArgumentError: If `shape` is incompatible with the shape of `x`. """ if not isinstance(shape, tensor_shape.TensorShape): From c6281f660b3f593054737de0bc9388113181aa4d Mon Sep 17 00:00:00 2001 From: nikochiko Date: Thu, 21 Nov 2019 00:06:38 +0530 Subject: [PATCH 03/15] Make requested changes --- tensorflow/python/ops/array_ops.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tensorflow/python/ops/array_ops.py b/tensorflow/python/ops/array_ops.py index 6a18d08f22f..b31c28deb28 100644 --- a/tensorflow/python/ops/array_ops.py +++ b/tensorflow/python/ops/array_ops.py @@ -444,7 +444,7 @@ def broadcast_dynamic_shape(shape_x, shape_y): >>> shape_x = [1, 2, 3] >>> shape_y = [5, 1, 3] - >>> broadcast_dynamic_shape(shape_x, shape_y) + >>> tf.broadcast_dynamic_shape(shape_x, shape_y) Args: @@ -479,7 +479,7 @@ def broadcast_static_shape(shape_x, shape_y): >>> shape_x = tf.TensorShape([1, 2, 3]) >>> shape_y = tf.TensorShape([5, 1 ,3]) - >>> broadcast_static_shape(shape_x, shape_y) + >>> tf.broadcast_static_shape(shape_x, shape_y) TensorShape([Dimension(5), Dimension(2), Dimension(3)]) Args: @@ -1556,12 +1556,12 @@ def boolean_mask(tensor, mask, name="boolean_mask", axis=None): # 1-D example tensor = [0, 1, 2, 3] mask = np.array([True, False, True, False]) - boolean_mask(tensor, mask) # [0, 2] + tf.boolean_mask(tensor, mask) # [0, 2] # 2-D example tensor = [[1, 2], [3, 4], [5, 6]] mask = np.array([True, False, True]) - boolean_mask(tensor, mask) # [[1, 2], [5, 6]] + tf.boolean_mask(tensor, mask) # [[1, 2], [5, 6]] ``` Args: @@ -1640,12 +1640,12 @@ def boolean_mask_v2(tensor, mask, axis=None, name="boolean_mask"): >>> tensor = [0, 1, 2, 3] # 1-D example >>> mask = np.array([True, False, True, False]) - >>> boolean_mask(tensor, mask) + >>> tf.boolean_mask(tensor, mask) >>> tensor = [[1, 2], [3, 4], [5, 6]] # 2-D example >>> mask = np.array([True, False, True]) - >>> boolean_mask(tensor, mask) + >>> tf.boolean_mask(tensor, mask) Args: @@ -3175,7 +3175,7 @@ def edit_distance(hypothesis, truth, normalize=True, name="edit_distance"): ... [1, 1, 0]], ... ["a", "b", "c", "a"], ... (2, 2, 2)) - >>> edit_distance(hypothesis, truth, normalize=True) + >>> tf.edit_distance(hypothesis, truth, normalize=True) From d6cff22e271692d770ebc94a8aec6b83e2d533b9 Mon Sep 17 00:00:00 2001 From: nikochiko Date: Thu, 21 Nov 2019 14:47:02 +0530 Subject: [PATCH 04/15] Make requested changes - Shapes from lists to tuples - TensorShapes to `TensorShape([...])` --- tensorflow/python/ops/array_ops.py | 21 +++++++++++---------- tensorflow/python/ops/check_ops.py | 10 ++++------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/tensorflow/python/ops/array_ops.py b/tensorflow/python/ops/array_ops.py index b31c28deb28..a345d290f69 100644 --- a/tensorflow/python/ops/array_ops.py +++ b/tensorflow/python/ops/array_ops.py @@ -442,8 +442,8 @@ def broadcast_dynamic_shape(shape_x, shape_y): Example: - >>> shape_x = [1, 2, 3] - >>> shape_y = [5, 1, 3] + >>> shape_x = (1, 2, 3) + >>> shape_y = (5, 1, 3) >>> tf.broadcast_dynamic_shape(shape_x, shape_y) @@ -469,8 +469,9 @@ def broadcast_static_shape(shape_x, shape_y): `TensorShape` which is the shape of the result of a broadcasting op applied in tensors of shapes `shape_x` and `shape_y`. - For example, if shape_x is [1, 2, 3] and shape_y is [5, 1, 3], the result is a - TensorShape whose value is [5, 2, 3]. + For example, if shape_x is `TensorShape([1, 2, 3])` and shape_y is + `TensorShape([5, 1, 3])`, the result is a TensorShape whose value is + `TensorShape([5, 2, 3])`. This is useful when validating the result of a broadcasting operation when the tensors have statically known shapes. @@ -3160,8 +3161,8 @@ def edit_distance(hypothesis, truth, normalize=True, name="edit_distance"): For example: Given the following input, - * `hypothesis` is a `tf.SparseTensor` of shape `[2, 1, 1]` - * `truth` is a `tf.SparseTensor` of shape `[2, 2, 2]` + * `hypothesis` is a `tf.SparseTensor` of shape `(2, 1, 1)` + * `truth` is a `tf.SparseTensor` of shape `(2, 2, 2)` >>> hypothesis = tf.SparseTensor( ... [[0, 0, 0], @@ -3180,7 +3181,7 @@ def edit_distance(hypothesis, truth, normalize=True, name="edit_distance"): array([[inf, 1. ], [0.5, 1. ]], dtype=float32)> - The operaton returns a dense Tensor of shape `[2, 2]` with + The operaton returns a dense Tensor of shape `(2, 2)` with edit distances normalized by `truth` lengths. **Note**: It is possible to calculate edit distance between two @@ -3190,14 +3191,14 @@ def edit_distance(hypothesis, truth, normalize=True, name="edit_distance"): For the following inputs, ```python - # 'hypothesis' is a tensor of shape `[2, 1]` with variable-length values: + # 'hypothesis' is a tensor of shape `(2, 1)` with variable-length values: hypothesis = tf.SparseTensor( [[0, 0], [1,0]], ["a", "b"], (2, 1)) - # 'truth' is a tensor of shape `[2, 2]` with variable-length values: + # 'truth' is a tensor of shape `(2, 2)` with variable-length values: truth = tf.SparseTensor( [[0, 1], [1, 0], @@ -3207,7 +3208,7 @@ def edit_distance(hypothesis, truth, normalize=True, name="edit_distance"): normalize = True - # The output would be a dense Tensor of shape `[2,]`, with edit distances + # The output would be a dense Tensor of shape `(2,)`, with edit distances noramlized by 'truth' lengths. # output => array([0., 0.5], dtype=float32) ``` diff --git a/tensorflow/python/ops/check_ops.py b/tensorflow/python/ops/check_ops.py index 68546d792a8..c76f3939f1e 100644 --- a/tensorflow/python/ops/check_ops.py +++ b/tensorflow/python/ops/check_ops.py @@ -2117,13 +2117,11 @@ def ensure_shape(x, shape, name=None): >>> y = x * 2 >>> print(y.shape) TensorShape(None) - - y = tf.ensure_shape(y, (None, 3, 3)) - print(y.shape) - TensorShape([None, 3, 3]) - + >>> y = tf.ensure_shape(y, (None, 3, 3)) + >>> print(y.shape) + TensorShape([Dimension(None), Dimension(3), Dimension(3)]) >>> with tf.compat.v1.Session() as sess: - >>> sess.run(y, feed_dict={x: [1, 2, 3]}) + >>> sess.run(y, feed_dict={x: [1, 2, 3]}) Traceback (most recent call last): ... InvalidArgumentError: Shape of tensor mul [3] is not compatible with From 9ccf3973b0af7232e83d18a8ea6c6fc27632f0fc Mon Sep 17 00:00:00 2001 From: nikochiko Date: Tue, 26 Nov 2019 21:47:35 +0530 Subject: [PATCH 05/15] Minor changes Made few more minor changes to documentation of `tf.extract_volume_patches` and `tf.fill` --- .../api_def_ExtractVolumePatches.pbtxt | 8 +++---- tensorflow/python/ops/array_ops.py | 21 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/tensorflow/core/api_def/base_api/api_def_ExtractVolumePatches.pbtxt b/tensorflow/core/api_def/base_api/api_def_ExtractVolumePatches.pbtxt index 9c4015eaa4c..32a3c33dc35 100644 --- a/tensorflow/core/api_def/base_api/api_def_ExtractVolumePatches.pbtxt +++ b/tensorflow/core/api_def/base_api/api_def_ExtractVolumePatches.pbtxt @@ -34,13 +34,13 @@ END description: < Date: Sat, 14 Dec 2019 22:23:21 +0530 Subject: [PATCH 06/15] Update example to use tf.function --- tensorflow/python/ops/check_ops.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/tensorflow/python/ops/check_ops.py b/tensorflow/python/ops/check_ops.py index e53a00bc232..ed28b1b093a 100644 --- a/tensorflow/python/ops/check_ops.py +++ b/tensorflow/python/ops/check_ops.py @@ -2121,25 +2121,16 @@ def ensure_shape(x, shape, name=None): For example: - >>> # tf.placeholder() is not compatible with eager execution - ... - >>> tf.compat.v1.disable_eager_execution() - >>> x = tf.compat.v1.placeholder(tf.int32) - >>> print(x.shape) - TensorShape(None) - >>> y = x * 2 - >>> print(y.shape) - TensorShape(None) - >>> y = tf.ensure_shape(y, (None, 3, 3)) - >>> print(y.shape) - TensorShape([Dimension(None), Dimension(3), Dimension(3)]) - >>> with tf.compat.v1.Session() as sess: - >>> sess.run(y, feed_dict={x: [1, 2, 3]}) + >>> @tf.function(input_signature=[tf.TensorSpec(dtype=tf.float32, shape=None)]) + >>> def f(tensor): + >>> return tf.ensure_shape(x, [3, 3]) + >>> + >>> f(tf.zeros([3, 3])) # Passes + >>> f([1, 2, 3]) # fails Traceback (most recent call last): - ... - InvalidArgumentError: Shape of tensor mul [3] is not compatible with - expected shape [?,3,3]. - + ... + InvalidArgumentError: Shape of tensor x [3] is not compatible with expected shape [3,3]. + The above example raises `tf.errors.InvalidArgumentError`, because the shape (3,) is not compatible with the shape (None, 3, 3) From 6d6411b339ef2b14f38c57e38c05b2f24122364a Mon Sep 17 00:00:00 2001 From: nikochiko Date: Tue, 17 Dec 2019 16:50:45 +0530 Subject: [PATCH 07/15] Fix sanity build errors --- tensorflow/python/ops/array_ops.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tensorflow/python/ops/array_ops.py b/tensorflow/python/ops/array_ops.py index 52c265608fe..65a55b5b2bd 100644 --- a/tensorflow/python/ops/array_ops.py +++ b/tensorflow/python/ops/array_ops.py @@ -490,10 +490,10 @@ setdiff1d.__doc__ = gen_array_ops.list_diff.__doc__ def broadcast_dynamic_shape(shape_x, shape_y): """Computes the shape of a broadcast given symbolic shapes. - When `shape_x` and `shape_y` are Tensors representing shapes (i.e. the result of - calling tf.shape on another Tensor) this computes a Tensor which is the shape - of the result of a broadcasting op applied in tensors of shapes `shape_x` and - `shape_y`. + When `shape_x` and `shape_y` are Tensors representing shapes (i.e. the result + of calling tf.shape on another Tensor) this computes a Tensor which is the + shape of the result of a broadcasting op applied in tensors of shapes + `shape_x` and `shape_y`. This is useful when validating the result of a broadcasting operation when the tensors do not have statically known shapes. @@ -503,7 +503,8 @@ def broadcast_dynamic_shape(shape_x, shape_y): >>> shape_x = (1, 2, 3) >>> shape_y = (5, 1, 3) >>> tf.broadcast_dynamic_shape(shape_x, shape_y) - + Args: shape_x: A rank 1 integer `Tensor`, representing the shape of x. @@ -1732,7 +1733,8 @@ def boolean_mask_v2(tensor, mask, axis=None, name="boolean_mask"): >>> tensor = [[1, 2], [3, 4], [5, 6]] # 2-D example >>> mask = np.array([True, False, True]) >>> tf.boolean_mask(tensor, mask) - + Args: tensor: N-D Tensor. From 2f3f3ee15bbc837a22b33c6177e064b5b92d5fec Mon Sep 17 00:00:00 2001 From: nikochiko Date: Tue, 17 Dec 2019 16:58:07 +0530 Subject: [PATCH 08/15] Fix pylint, wrap at 80 chars --- tensorflow/python/ops/array_ops.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tensorflow/python/ops/array_ops.py b/tensorflow/python/ops/array_ops.py index 65a55b5b2bd..16dda049420 100644 --- a/tensorflow/python/ops/array_ops.py +++ b/tensorflow/python/ops/array_ops.py @@ -503,8 +503,8 @@ def broadcast_dynamic_shape(shape_x, shape_y): >>> shape_x = (1, 2, 3) >>> shape_y = (5, 1, 3) >>> tf.broadcast_dynamic_shape(shape_x, shape_y) - + Args: shape_x: A rank 1 integer `Tensor`, representing the shape of x. @@ -1733,8 +1733,8 @@ def boolean_mask_v2(tensor, mask, axis=None, name="boolean_mask"): >>> tensor = [[1, 2], [3, 4], [5, 6]] # 2-D example >>> mask = np.array([True, False, True]) >>> tf.boolean_mask(tensor, mask) - + Args: tensor: N-D Tensor. From d25cff86db264b870439dbf2b6f37ae30096af0b Mon Sep 17 00:00:00 2001 From: Kaustubh Maske Patil <37668193+nikochiko@users.noreply.github.com> Date: Sat, 21 Dec 2019 20:25:12 +0530 Subject: [PATCH 09/15] Update array_ops.py --- tensorflow/python/ops/array_ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/ops/array_ops.py b/tensorflow/python/ops/array_ops.py index 16dda049420..d980babf99d 100644 --- a/tensorflow/python/ops/array_ops.py +++ b/tensorflow/python/ops/array_ops.py @@ -503,7 +503,7 @@ def broadcast_dynamic_shape(shape_x, shape_y): >>> shape_x = (1, 2, 3) >>> shape_y = (5, 1, 3) >>> tf.broadcast_dynamic_shape(shape_x, shape_y) - Args: From 6746a6b8317313d952c8c8083be2476c75d7cc23 Mon Sep 17 00:00:00 2001 From: Kaustubh Maske Patil <37668193+nikochiko@users.noreply.github.com> Date: Sat, 21 Dec 2019 20:26:41 +0530 Subject: [PATCH 10/15] Update array_ops.py --- tensorflow/python/ops/array_ops.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tensorflow/python/ops/array_ops.py b/tensorflow/python/ops/array_ops.py index d980babf99d..57d953481a9 100644 --- a/tensorflow/python/ops/array_ops.py +++ b/tensorflow/python/ops/array_ops.py @@ -1728,12 +1728,12 @@ def boolean_mask_v2(tensor, mask, axis=None, name="boolean_mask"): >>> tensor = [0, 1, 2, 3] # 1-D example >>> mask = np.array([True, False, True, False]) >>> tf.boolean_mask(tensor, mask) - + >>> tensor = [[1, 2], [3, 4], [5, 6]] # 2-D example >>> mask = np.array([True, False, True]) >>> tf.boolean_mask(tensor, mask) - Args: @@ -3459,7 +3459,7 @@ def edit_distance(hypothesis, truth, normalize=True, name="edit_distance"): ... ["a", "b", "c", "a"], ... (2, 2, 2)) >>> tf.edit_distance(hypothesis, truth, normalize=True) - From 6a89b01c85893ecba281447e4d54c77889cd4d83 Mon Sep 17 00:00:00 2001 From: nikochiko Date: Sat, 4 Jan 2020 13:01:11 +0530 Subject: [PATCH 11/15] Fix docstrings --- tensorflow/python/ops/array_ops.py | 7 ++++--- tensorflow/python/ops/check_ops.py | 14 +++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tensorflow/python/ops/array_ops.py b/tensorflow/python/ops/array_ops.py index 57d953481a9..a208272a7e2 100644 --- a/tensorflow/python/ops/array_ops.py +++ b/tensorflow/python/ops/array_ops.py @@ -540,7 +540,7 @@ def broadcast_static_shape(shape_x, shape_y): >>> shape_x = tf.TensorShape([1, 2, 3]) >>> shape_y = tf.TensorShape([5, 1 ,3]) >>> tf.broadcast_static_shape(shape_x, shape_y) - TensorShape([Dimension(5), Dimension(2), Dimension(3)]) + TensorShape([5, 2, 3]) Args: shape_x: A `TensorShape` @@ -1733,8 +1733,9 @@ def boolean_mask_v2(tensor, mask, axis=None, name="boolean_mask"): >>> tensor = [[1, 2], [3, 4], [5, 6]] # 2-D example >>> mask = np.array([True, False, True]) >>> tf.boolean_mask(tensor, mask) - + Args: tensor: N-D Tensor. diff --git a/tensorflow/python/ops/check_ops.py b/tensorflow/python/ops/check_ops.py index ed28b1b093a..2088dea7c12 100644 --- a/tensorflow/python/ops/check_ops.py +++ b/tensorflow/python/ops/check_ops.py @@ -1595,7 +1595,7 @@ def assert_shapes_v2(shapes, data=None, summarize=None, message=None, >>> n = 10 >>> q = 3 >>> d = 7 - >>> x = tf.zeros([n,q]) + >>> x = tf.zeros([n,q]) >>> y = tf.ones([n,d]) >>> param = tf.Variable([1.0, 2.0, 3.0]) >>> scalar = 1.0 @@ -1605,9 +1605,9 @@ def assert_shapes_v2(shapes, data=None, summarize=None, message=None, ... (param, ('Q',)), ... (scalar, ()), ... ]) - + >>> tf.debugging.assert_shapes([ - ... (x, ('N', 'D')), + ... (x, ('N', 'D')), ... (y, ('N', 'D')) ... ]) Traceback (most recent call last): @@ -2121,16 +2121,16 @@ def ensure_shape(x, shape, name=None): For example: - >>> @tf.function(input_signature=[tf.TensorSpec(dtype=tf.float32, shape=None)]) - >>> def f(tensor): - >>> return tf.ensure_shape(x, [3, 3]) + >>> @tf.function(input_signature=[tf.TensorSpec(shape=None, dtype=tf.float32)]) + ... def f(tensor): + ... return tf.ensure_shape(tensor, [3, 3]) >>> >>> f(tf.zeros([3, 3])) # Passes >>> f([1, 2, 3]) # fails Traceback (most recent call last): ... InvalidArgumentError: Shape of tensor x [3] is not compatible with expected shape [3,3]. - + The above example raises `tf.errors.InvalidArgumentError`, because the shape (3,) is not compatible with the shape (None, 3, 3) From aee9e604872ecb6bdd15cd6a1864b2d1108b671b Mon Sep 17 00:00:00 2001 From: Kaustubh Maske Patil <37668193+nikochiko@users.noreply.github.com> Date: Sun, 12 Jan 2020 10:41:37 +0530 Subject: [PATCH 12/15] Fix doctest for ensure_shape --- tensorflow/python/ops/check_ops.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tensorflow/python/ops/check_ops.py b/tensorflow/python/ops/check_ops.py index 2088dea7c12..d38b3958205 100644 --- a/tensorflow/python/ops/check_ops.py +++ b/tensorflow/python/ops/check_ops.py @@ -2126,6 +2126,10 @@ def ensure_shape(x, shape, name=None): ... return tf.ensure_shape(tensor, [3, 3]) >>> >>> f(tf.zeros([3, 3])) # Passes + >>> f([1, 2, 3]) # fails Traceback (most recent call last): ... From 26e4ac1d76b43d9cf5288c914985e42fd0bfdbbf Mon Sep 17 00:00:00 2001 From: Mihai Maruseac Date: Mon, 6 Apr 2020 16:50:17 +0000 Subject: [PATCH 13/15] Update tensorflow/python/ops/array_ops.py --- tensorflow/python/ops/array_ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/ops/array_ops.py b/tensorflow/python/ops/array_ops.py index 9367374717e..fc29aafb7de 100644 --- a/tensorflow/python/ops/array_ops.py +++ b/tensorflow/python/ops/array_ops.py @@ -3507,7 +3507,7 @@ def edit_distance(hypothesis, truth, normalize=True, name="edit_distance"): For example: Given the following input, - * `hypothesis` is a `tf.SparseTensor` of shape `(2, 1, 1)` + * `hypothesis` is a `tf.SparseTensor` of shape `[2, 1, 1]` * `truth` is a `tf.SparseTensor` of shape `(2, 2, 2)` >>> hypothesis = tf.SparseTensor( From 05edf7e11bb3d91f0e2b75e67914c2379cf0cd89 Mon Sep 17 00:00:00 2001 From: Mihai Maruseac Date: Mon, 6 Apr 2020 16:50:26 +0000 Subject: [PATCH 14/15] Update tensorflow/python/ops/array_ops.py --- tensorflow/python/ops/array_ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/ops/array_ops.py b/tensorflow/python/ops/array_ops.py index fc29aafb7de..004bbeac7f6 100644 --- a/tensorflow/python/ops/array_ops.py +++ b/tensorflow/python/ops/array_ops.py @@ -3527,7 +3527,7 @@ def edit_distance(hypothesis, truth, normalize=True, name="edit_distance"): array([[inf, 1. ], [0.5, 1. ]], dtype=float32)> - The operaton returns a dense Tensor of shape `(2, 2)` with + The operaton returns a dense Tensor of shape `[2, 2]` with edit distances normalized by `truth` lengths. **Note**: It is possible to calculate edit distance between two From 28769b2b746570883ae8a57e042f50c4defba2b5 Mon Sep 17 00:00:00 2001 From: Mihai Maruseac Date: Mon, 6 Apr 2020 16:50:35 +0000 Subject: [PATCH 15/15] Update tensorflow/python/ops/array_ops.py --- tensorflow/python/ops/array_ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/ops/array_ops.py b/tensorflow/python/ops/array_ops.py index 004bbeac7f6..e508165a820 100644 --- a/tensorflow/python/ops/array_ops.py +++ b/tensorflow/python/ops/array_ops.py @@ -3508,7 +3508,7 @@ def edit_distance(hypothesis, truth, normalize=True, name="edit_distance"): Given the following input, * `hypothesis` is a `tf.SparseTensor` of shape `[2, 1, 1]` - * `truth` is a `tf.SparseTensor` of shape `(2, 2, 2)` + * `truth` is a `tf.SparseTensor` of shape `[2, 2, 2]` >>> hypothesis = tf.SparseTensor( ... [[0, 0, 0],