diff options
15 files changed, 57 insertions, 42 deletions
diff --git a/tensorflow/contrib/distributions/python/ops/bijector.py b/tensorflow/contrib/distributions/python/ops/bijector.py index deaa6a8fea..e83d8469f2 100644 --- a/tensorflow/contrib/distributions/python/ops/bijector.py +++ b/tensorflow/contrib/distributions/python/ops/bijector.py @@ -1757,12 +1757,12 @@ class SoftmaxCentered(Bijector): on_value=shape[-1]-np.array(1, dtype=shape.dtype), dtype=shape.dtype) size = array_ops.concat(0, (shape[:-1], np.asarray([1], dtype=shape.dtype))) - log_normalization = -array_ops.slice(x, begin, size) + log_normalization = -array_ops.strided_slice(x, begin, begin + size) # Here we slice out all but the last coordinate; see above for idea. begin = array_ops.zeros_like(shape) size = array_ops.concat(0, (shape[:-1], [shape[-1]-1])) - x = array_ops.slice(x, begin, size) + x = array_ops.strided_slice(x, begin, begin + size) x += log_normalization diff --git a/tensorflow/contrib/distributions/python/ops/operator_pd.py b/tensorflow/contrib/distributions/python/ops/operator_pd.py index 283adf8b79..14238bfa4b 100644 --- a/tensorflow/contrib/distributions/python/ops/operator_pd.py +++ b/tensorflow/contrib/distributions/python/ops/operator_pd.py @@ -383,7 +383,7 @@ class OperatorPDBase(object): # Derived classes get this "for free" once .shape() is implemented. with ops.name_scope(self.name): with ops.name_scope(name, values=self.inputs): - return array_ops.slice(self.shape(), [0], [self.rank() - 2]) + return array_ops.strided_slice(self.shape(), [0], [self.rank() - 2]) def vector_shape(self, name="vector_shape"): """Shape of (batch) vectors that this (batch) matrix will multiply. @@ -746,7 +746,7 @@ def _flip_vector_to_matrix_dynamic(vec, batch_shape): m = vec_batch_rank - batch_rank # vec_shape_left = [M1,...,Mm] or []. - vec_shape_left = array_ops.slice(vec_shape, [0], [m]) + vec_shape_left = array_ops.strided_slice(vec_shape, [0], [m]) # If vec_shape_left = [], then condensed_shape = [1] since reduce_prod([]) = 1 # If vec_shape_left = [M1,...,Mm], condensed_shape = [M1*...*Mm] condensed_shape = [math_ops.reduce_prod(vec_shape_left)] @@ -819,5 +819,5 @@ def extract_batch_shape(x, num_event_dims, name="extract_batch_shape"): """ with ops.name_scope(name, values=[x]): x = ops.convert_to_tensor(x, name="x") - return array_ops.slice( + return array_ops.strided_slice( array_ops.shape(x), [0], [array_ops.rank(x) - num_event_dims]) diff --git a/tensorflow/contrib/distributions/python/ops/operator_pd_vdvt_update.py b/tensorflow/contrib/distributions/python/ops/operator_pd_vdvt_update.py index 819a6da47c..912572351f 100644 --- a/tensorflow/contrib/distributions/python/ops/operator_pd_vdvt_update.py +++ b/tensorflow/contrib/distributions/python/ops/operator_pd_vdvt_update.py @@ -145,7 +145,7 @@ class OperatorPDSqrtVDVTUpdate(operator_pd.OperatorPDBase): else: v_shape = array_ops.shape(v) v_rank = array_ops.rank(v) - v_batch_shape = array_ops.slice(v_shape, [0], [v_rank - 2]) + v_batch_shape = array_ops.strided_slice(v_shape, [0], [v_rank - 2]) r = array_ops.gather(v_shape, v_rank - 1) # Last dim of v id_shape = array_ops.concat(0, (v_batch_shape, [r, r])) return operator_pd_identity.OperatorPDIdentity( @@ -228,11 +228,13 @@ class OperatorPDSqrtVDVTUpdate(operator_pd.OperatorPDBase): checks.append(check_ops.assert_rank(diag, r_op - 1)) # Check batch shape - checks.append(check_ops.assert_equal( - operator.batch_shape(), array_ops.slice(s_v, [0], [r_v - 2]))) + checks.append( + check_ops.assert_equal(operator.batch_shape(), + array_ops.strided_slice(s_v, [0], [r_v - 2]))) if diag is not None: - checks.append(check_ops.assert_equal( - operator.batch_shape(), array_ops.slice(s_d, [0], [r_d - 1]))) + checks.append( + check_ops.assert_equal(operator.batch_shape( + ), array_ops.strided_slice(s_d, [0], [r_d - 1]))) # Check event shape checks.append(check_ops.assert_equal( diff --git a/tensorflow/contrib/distributions/python/ops/wishart.py b/tensorflow/contrib/distributions/python/ops/wishart.py index b478a12d36..e85a6fc1df 100644 --- a/tensorflow/contrib/distributions/python/ops/wishart.py +++ b/tensorflow/contrib/distributions/python/ops/wishart.py @@ -180,7 +180,8 @@ class _WishartOperatorPD(distribution.Distribution): def _event_shape(self): s = self.scale_operator_pd.shape() - return array_ops.slice(s, array_ops.shape(s) - 2, [2]) + return array_ops.strided_slice(s, array_ops.shape(s) - 2, + array_ops.shape(s)) def _get_event_shape(self): return self.scale_operator_pd.get_shape()[-2:] @@ -261,7 +262,7 @@ class _WishartOperatorPD(distribution.Distribution): ndims = array_ops.rank(x_sqrt) # sample_ndims = ndims - batch_ndims - event_ndims sample_ndims = ndims - array_ops.shape(batch_shape)[0] - 2 - sample_shape = array_ops.slice( + sample_shape = array_ops.strided_slice( array_ops.shape(x_sqrt), [0], [sample_ndims]) # We need to be able to pre-multiply each matrix by its corresponding diff --git a/tensorflow/contrib/layers/python/layers/layers.py b/tensorflow/contrib/layers/python/layers/layers.py index 2bec19428e..9a9ab6e117 100644 --- a/tensorflow/contrib/layers/python/layers/layers.py +++ b/tensorflow/contrib/layers/python/layers/layers.py @@ -1157,7 +1157,7 @@ def _dense_inner_flatten(inputs, new_rank): rank_assertion = check_ops.assert_rank_at_least( inputs, new_rank, message='inputs has rank less than new_rank') with ops.control_dependencies([rank_assertion]): - outer_dimensions = array_ops.slice( + outer_dimensions = array_ops.strided_slice( array_ops.shape(inputs), [0], [new_rank - 1]) new_shape = array_ops.concat(0, (outer_dimensions, [-1])) reshaped = array_ops.reshape(inputs, new_shape) @@ -1915,7 +1915,8 @@ def unit_norm(inputs, dim, epsilon=1e-7, scope=None): multiples = [] if dim > 0: multiples.append(array_ops.ones([dim], dtypes.int32)) - multiples.append(array_ops.slice(array_ops.shape(inputs), [dim], [1])) + multiples.append( + array_ops.strided_slice(array_ops.shape(inputs), [dim], [dim + 1])) if dim < (input_rank - 1): multiples.append(array_ops.ones([input_rank - 1 - dim], dtypes.int32)) multiples = array_ops.concat(0, multiples) diff --git a/tensorflow/contrib/metrics/python/ops/metric_ops.py b/tensorflow/contrib/metrics/python/ops/metric_ops.py index c6d6b50e90..172f6976cc 100644 --- a/tensorflow/contrib/metrics/python/ops/metric_ops.py +++ b/tensorflow/contrib/metrics/python/ops/metric_ops.py @@ -1749,8 +1749,9 @@ def expand_and_tile(tensor, multiple, dim=0, name=None): else: expand_dims = [dim] expanded_shape = array_ops.concat( - 0, (array_ops.slice(tensor.shape, [0], expand_dims), [1], - array_ops.slice(tensor.shape, expand_dims, [-1])), + 0, (array_ops.strided_slice(tensor.shape, [0], expand_dims), [1], + array_ops.strided_slice( + tensor.shape, expand_dims, [-1], end_mask=1 << 0)), name='expanded_shape') expanded = sparse_ops.sparse_reshape( tensor, shape=expanded_shape, name='expand') diff --git a/tensorflow/contrib/metrics/python/ops/metric_ops_test.py b/tensorflow/contrib/metrics/python/ops/metric_ops_test.py index cf58792c4a..71fdcf3522 100644 --- a/tensorflow/contrib/metrics/python/ops/metric_ops_test.py +++ b/tensorflow/contrib/metrics/python/ops/metric_ops_test.py @@ -4651,11 +4651,6 @@ class ExpandAndTileTest(tf.test.TestCase): shape=[3, 3, 3]) with self.assertRaisesRegexp(ValueError, 'nvalid multiple'): metric_ops.expand_and_tile(x, multiple=0) - with self.test_session(): - with self.assertRaises(tf.OpError): - metric_ops.expand_and_tile(x, multiple=1, dim=-4).eval() - with self.assertRaises(ValueError): - metric_ops.expand_and_tile(x, multiple=1, dim=4).eval() def _test_expand_and_tile( self, expected_shape, expected_value, tensor, multiple, dim=None): diff --git a/tensorflow/contrib/opt/python/training/external_optimizer_test.py b/tensorflow/contrib/opt/python/training/external_optimizer_test.py index ec2efc75bf..9dd64e5b32 100644 --- a/tensorflow/contrib/opt/python/training/external_optimizer_test.py +++ b/tensorflow/contrib/opt/python/training/external_optimizer_test.py @@ -134,9 +134,11 @@ class ScipyOptimizerInterfaceTest(TestCase): """ d = tf.size(x) - s = tf.add(100 * tf.square(tf.sub(tf.slice(x, [1], [d - 1]), - tf.square(tf.slice(x, [0], [d - 1])))), - tf.square(tf.sub(1.0, tf.slice(x, [0], [d - 1])))) + s = tf.add(100 * tf.square( + tf.sub( + tf.strided_slice(x, [1], [d]), + tf.square(tf.strided_slice(x, [0], [d - 1])))), + tf.square(tf.sub(1.0, tf.strided_slice(x, [0], [d - 1])))) return tf.reduce_sum(s) dimension = 5 diff --git a/tensorflow/contrib/tensor_forest/python/tensor_forest.py b/tensorflow/contrib/tensor_forest/python/tensor_forest.py index cd35b45eab..18f64b9ab5 100644 --- a/tensorflow/contrib/tensor_forest/python/tensor_forest.py +++ b/tensorflow/contrib/tensor_forest/python/tensor_forest.py @@ -369,7 +369,8 @@ class RandomForestGraphs(object): if self.params.bagging_fraction < 1.0: # TODO(thomaswc): This does sampling without replacment. Consider # also allowing sampling with replacement as an option. - batch_size = array_ops.slice(array_ops.shape(input_data), [0], [1]) + batch_size = array_ops.strided_slice( + array_ops.shape(input_data), [0], [1]) r = random_ops.random_uniform(batch_size, seed=seed) mask = math_ops.less( r, array_ops.ones_like(r) * self.params.bagging_fraction) @@ -535,9 +536,10 @@ class RandomTreeGraphs(object): return control_flow_ops.no_op() return control_flow_ops.cond( - math_ops.equal(array_ops.squeeze(array_ops.slice( - self.variables.tree, [0, 0], [1, 1])), -2), - _init_tree, _nothing) + math_ops.equal( + array_ops.squeeze( + array_ops.strided_slice(self.variables.tree, [0, 0], [1, 1])), + -2), _init_tree, _nothing) def _gini(self, class_counts): """Calculate the Gini impurity. diff --git a/tensorflow/models/image/cifar10/cifar10_input.py b/tensorflow/models/image/cifar10/cifar10_input.py index b00859b262..dbbd990402 100644 --- a/tensorflow/models/image/cifar10/cifar10_input.py +++ b/tensorflow/models/image/cifar10/cifar10_input.py @@ -84,12 +84,14 @@ def read_cifar10(filename_queue): # The first bytes represent the label, which we convert from uint8->int32. result.label = tf.cast( - tf.slice(record_bytes, [0], [label_bytes]), tf.int32) + tf.strided_slice(record_bytes, [0], [label_bytes]), tf.int32) # The remaining bytes after the label represent the image, which we reshape # from [depth * height * width] to [depth, height, width]. - depth_major = tf.reshape(tf.slice(record_bytes, [label_bytes], [image_bytes]), - [result.depth, result.height, result.width]) + depth_major = tf.reshape( + tf.strided_slice(record_bytes, [label_bytes], + [label_bytes + image_bytes]), + [result.depth, result.height, result.width]) # Convert from [depth, height, width] to [height, width, depth]. result.uint8image = tf.transpose(depth_major, [1, 2, 0]) diff --git a/tensorflow/models/rnn/ptb/reader.py b/tensorflow/models/rnn/ptb/reader.py index d9e666b3d3..2bcbcac5e6 100644 --- a/tensorflow/models/rnn/ptb/reader.py +++ b/tensorflow/models/rnn/ptb/reader.py @@ -113,6 +113,8 @@ def ptb_producer(raw_data, batch_size, num_steps, name=None): epoch_size = tf.identity(epoch_size, name="epoch_size") i = tf.train.range_input_producer(epoch_size, shuffle=False).dequeue() - x = tf.slice(data, [0, i * num_steps], [batch_size, num_steps]) - y = tf.slice(data, [0, i * num_steps + 1], [batch_size, num_steps]) + x = tf.strided_slice(data, [0, i * num_steps], + [batch_size, (i + 1) * num_steps]) + y = tf.strided_slice(data, [0, i * num_steps + 1], + [batch_size, (i + 1) * num_steps + 1]) return x, y diff --git a/tensorflow/python/kernel_tests/control_flow_ops_py_test.py b/tensorflow/python/kernel_tests/control_flow_ops_py_test.py index 938da20232..ca4a1760c3 100644 --- a/tensorflow/python/kernel_tests/control_flow_ops_py_test.py +++ b/tensorflow/python/kernel_tests/control_flow_ops_py_test.py @@ -8,7 +8,7 @@ # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# WITHOUT WARRANTIES OiR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== @@ -642,7 +642,8 @@ class ControlFlowTest(tf.test.TestCase): with self.test_session(): def compute(i, c, o): - c = tf.slice(x, tf.expand_dims(i, 0), [1]) + c = tf.strided_slice(x, tf.expand_dims(i, 0), + [1] + tf.expand_dims(i, 0)) o = tf.concat(0, [o, c]) i = tf.add(i, 1) return [i, c, o] @@ -652,9 +653,10 @@ class ControlFlowTest(tf.test.TestCase): o = tf.convert_to_tensor([0]) x = tf.convert_to_tensor([1, 2, 3, 4, 5, 6]) s = tf.size(x) - r = tf.while_loop( - lambda i, c, o: tf.less(i, s), compute, [i, c, o], - [i.get_shape(), c.get_shape(), tensor_shape.unknown_shape()]) + r = tf.while_loop(lambda i, c, o: tf.less(i, s), compute, [i, c, o], [ + i.get_shape(), tensor_shape.unknown_shape(), + tensor_shape.unknown_shape() + ]) result = r[2].eval() self.assertTrue(check_op_order(i.graph)) self.assertAllEqual(np.array([0, 1, 2, 3, 4, 5, 6]), result) diff --git a/tensorflow/python/ops/array_ops.py b/tensorflow/python/ops/array_ops.py index ab09349266..788d689ee9 100644 --- a/tensorflow/python/ops/array_ops.py +++ b/tensorflow/python/ops/array_ops.py @@ -535,7 +535,7 @@ def slice(input_, begin, size, name=None): def strided_slice(input_, begin, end, - strides, + strides=None, begin_mask=0, end_mask=0, ellipsis_mask=0, @@ -624,6 +624,10 @@ def strided_slice(input_, Returns: A `Tensor` the same type as `input`. """ + + if strides is None: + strides = ones_like(begin) + op = gen_array_ops.strided_slice( input=input_, begin=begin, diff --git a/tensorflow/python/ops/check_ops.py b/tensorflow/python/ops/check_ops.py index 6377a96de8..b50153dcc6 100644 --- a/tensorflow/python/ops/check_ops.py +++ b/tensorflow/python/ops/check_ops.py @@ -665,6 +665,7 @@ def assert_type(tensor, tf_type, message=None, name=None): return control_flow_ops.no_op('statically_determined_correct_type') +# pylint: disable=line-too-long def _get_diff_for_monotonic_comparison(x): """Gets the difference x[1:] - x[:-1].""" x = array_ops.reshape(x, [-1]) @@ -677,7 +678,7 @@ def _get_diff_for_monotonic_comparison(x): # With 2 or more elements, return x[1:] - x[:-1] s_len = array_ops.shape(x) - 1 - diff = lambda: array_ops.slice(x, [1], s_len) - array_ops.slice(x, [0], s_len) + diff = lambda: array_ops.strided_slice(x, [1], [1] + s_len)- array_ops.strided_slice(x, [0], s_len) return control_flow_ops.cond(is_shorter_than_two, short_result, diff) diff --git a/tensorflow/python/ops/image_ops_test.py b/tensorflow/python/ops/image_ops_test.py index ce18da09d7..bc6ac2aed5 100644 --- a/tensorflow/python/ops/image_ops_test.py +++ b/tensorflow/python/ops/image_ops_test.py @@ -1132,13 +1132,13 @@ class SelectDistortedCropBoxTest(test_util.TensorFlowTestCase): bounding_box_tf = constant_op.constant(bounding_box_np, dtype=dtypes.float32, shape=bounding_box_np.shape) - begin, end, _ = image_ops.sample_distorted_bounding_box( + begin, size, _ = image_ops.sample_distorted_bounding_box( image_size=image_size_tf, bounding_boxes=bounding_box_tf, min_object_covered=min_object_covered, aspect_ratio_range=aspect_ratio_range, area_range=area_range) - y = array_ops.slice(image_tf, begin, end) + y = array_ops.strided_slice(image_tf, begin, begin + size) for _ in xrange(num_iter): y_tf = y.eval() |