message: Move noise_shape function to nn_ops.py
  so that is could potentially be used by layers.
diff: @@ -2142,6 +2142,28 @@ def xw_plus_b_v1(x, weights, biases, name=None): # pylint: disable=invalid-name
  mm = math_ops.matmul(x, weights)
  return bias_add_v1(mm, biases, name=name)
  +def _get_noise_shape(x, noise_shape):
  + # If noise_shape is none return immediately.
  + if noise_shape is None:
  + return array_ops.shape(x)
  +
  + try:
  + # Best effort to figure out the intended shape.
  + # If not possible, let the op to handle it.
  + noise_shape_ = tensor_shape.as_shape(noise_shape)
  + if (x.shape.dims is not None and
  + len(x.shape.dims) == len(noise_shape_.dims)):
  + new_dims = []
  + for i, dim in enumerate(x.shape.dims):
  + if noise_shape_.dims[i].value is None and dim.value is not None:
  + new_dims.append(dim.value)
  + else:
  + new_dims.append(noise_shape_.dims[i].value)
  + return tensor_shape.TensorShape(new_dims)
  + except (TypeError, ValueError):
  + return noise_shape
  +
  + return noise_shape
  def dropout(x, keep_prob, noise_shape=None, seed=None, name=None): # pylint: disable=invalid-name
  """Computes dropout.
  @@ -2193,30 +2215,7 @@ def dropout(x, keep_prob, noise_shape=None, seed=None, name=None): # pylint: di
  if tensor_util.constant_value(keep_prob) == 1:
  return x
  - def noise_shape_func(x, noise_shape):
  - # If noise_shape is none return immediately.
  - if noise_shape is None:
  - return array_ops.shape(x)
  -
  - try:
  - # Best effort to figure out the intended shape.
  - # If not possible, let the op to handle it.
  - noise_shape_ = tensor_shape.as_shape(noise_shape)
  - if (x.shape.dims is not None and
  - len(x.shape.dims) == len(noise_shape_.dims)):
  - new_dims = []
  - for i, dim in enumerate(x.shape.dims):
  - if noise_shape_.dims[i].value is None and dim.value is not None:
  - new_dims.append(dim.value)
  - else:
  - new_dims.append(noise_shape_.dims[i].value)
  - return tensor_shape.TensorShape(new_dims)
  - except Exception:
  - return noise_shape
  -
  - return noise_shape
  -
  - noise_shape = noise_shape_func(x, noise_shape)
  + noise_shape = _get_noise_shape(x, noise_shape)
  # uniform [keep_prob, 1.0 + keep_prob)
  random_tensor = keep_prob
  