from tensorflow.python.framework import tensor_util

      x = ops.convert_to_tensor(x, name="x")
      def slice_shape(start_sum, size, name):
        """Closure to slice out shape."""
        start_sum = start_sum if start_sum else (
            array_ops.zeros((), dtype=dtypes.int32, name="zero"),)
        if (x.get_shape().ndims is not None and
            self._is_all_constant_helper(size, *start_sum)):
          start = sum(tensor_util.constant_value(s) for s in start_sum)
          stop = start + tensor_util.constant_value(size)
          slice_ = x.get_shape()[start:stop].as_list()
          if all(s is not None for s in slice_):
            return ops.convert_to_tensor(slice_, dtype=dtypes.int32, name=name)
          # Fall-through intended.
        return array_ops.slice(array_ops.shape(x), (sum(start_sum),), (size,))
      sample_ndims = self.get_sample_ndims(x, name=name)
      return (slice_shape((), sample_ndims,
