parameters: (op)
return_statement: return [tensor_shape.TensorShape(output_shape)]
docstring: Shape function for a MaxPool op.
  
    This op has one input:
  
    * input, a 4D tensor with shape = [batch_size, rows, cols, depth_in]
  
    The output is a 4D tensor with shape = [batch_size, out_rows,
    out_cols, depth_out], where out_rows, out_cols, and depth_out depend
    on the value of the op's "ksize", "strides", and "padding" attrs.
  
    Args:
      op: A MaxPool Operation.
  
    Returns:
      A single-element list containing the Shape of the MaxPool output.
  
    Raises:
      ValueError: If the shape of the input is invalid or incompatible with
        the values of the attrs.
docstring_summary: Shape function for a MaxPool op.
docstring_tokens: Shape function for a MaxPool op .
function: def max_pool_shape(op):
    """Shape function for a MaxPool op.
  
    This op has one input:
  
    * input, a 4D tensor with shape = [batch_size, rows, cols, depth_in]
  
    The output is a 4D tensor with shape = [batch_size, out_rows,
    out_cols, depth_out], where out_rows, out_cols, and depth_out depend
    on the value of the op's "ksize", "strides", and "padding" attrs.
  
    Args:
      op: A MaxPool Operation.
  
    Returns:
      A single-element list containing the Shape of the MaxPool output.
  
    Raises:
      ValueError: If the shape of the input is invalid or incompatible with
        the values of the attrs.
    """
    input_shape = op.inputs[0].get_shape().with_rank(4)
    try:
      data_format = op.get_attr("data_format")
    except ValueError:
      data_format = None
  
    if data_format == b"NCHW":
      # Convert input shape to the default NHWC for inference.
      input_shape = [input_shape[0], input_shape[2], input_shape[3],
                     input_shape[1]]
  
    if data_format == b"NCHW":
      ksize_b, ksize_d, ksize_r, ksize_c = op.get_attr("ksize")
      stride_b, stride_d, stride_r, stride_c = op.get_attr("strides")
    else:
      ksize_b, ksize_r, ksize_c, ksize_d = op.get_attr("ksize")
      stride_b, stride_r, stride_c, stride_d = op.get_attr("strides")
  
    batch_size = input_shape[0]
    in_rows = input_shape[1]
    in_cols = input_shape[2]
    depth = input_shape[3]
  
    if ksize_b != 1:
      raise ValueError("Current implementation does not support pooling "
                       "in the batch dimension.")
    if stride_b != 1:
      raise ValueError("Current implementation does not support strides "
                       "in the batch dimension.")
  
    if not ((ksize_r == 1 and ksize_c == 1) or ksize_d == 1):
      raise ValueError("MaxPooling supports exactly one of pooling across depth "
                       "or pooling across width/height.")
  
    # TODO(mrry,shlens): Raise an error if the stride would cause
    # information in the input to be ignored. This will require a change
    # in the kernel implementation.
    if ksize_d == 1:
      padding = op.get_attr("padding")
      out_rows, out_cols = get2d_conv_output_size(in_rows, in_cols, ksize_r,
                                                  ksize_c, stride_r, stride_c,
                                                  padding)
      output_shape = [batch_size, out_rows, out_cols, depth]
    else:
      if depth % ksize_d > 0:
        raise ValueError("Depthwise max pooling requires the depth window "
                         "to evenly divide the input depth.")
      if stride_d != ksize_d:
        raise ValueError("Depthwise max pooling requires the depth window "
                         "to equal the depth stride.")
      output_shape = [batch_size, in_rows, in_cols, depth // ksize_d]
  
    if data_format == b"NCHW":
      # Convert output shape back to NCHW.
      output_shape = [output_shape[0], output_shape[3], output_shape[1],
                      output_shape[2]]
    return [tensor_shape.TensorShape(output_shape)]
function_tokens: def max_pool_shape ( op ) : input_shape = op . inputs [ 0 ] . get_shape ( ) . with_rank ( 4 ) try : data_format = op . get_attr ( "data_format" ) except ValueError : data_format = None if data_format == b"NCHW" : # Convert input shape to the default NHWC for inference. input_shape = [ input_shape [ 0 ] , input_shape [ 2 ] , input_shape [ 3 ] , input_shape [ 1 ] ] if data_format == b"NCHW" : ksize_b , ksize_d , ksize_r , ksize_c = op . get_attr ( "ksize" ) stride_b , stride_d , stride_r , stride_c = op . get_attr ( "strides" ) else : ksize_b , ksize_r , ksize_c , ksize_d = op . get_attr ( "ksize" ) stride_b , stride_r , stride_c , stride_d = op . get_attr ( "strides" ) batch_size = input_shape [ 0 ] in_rows = input_shape [ 1 ] in_cols = input_shape [ 2 ] depth = input_shape [ 3 ] if ksize_b != 1 : raise ValueError ( "Current implementation does not support pooling " "in the batch dimension." ) if stride_b != 1 : raise ValueError ( "Current implementation does not support strides " "in the batch dimension." ) if not ( ( ksize_r == 1 and ksize_c == 1 ) or ksize_d == 1 ) : raise ValueError ( "MaxPooling supports exactly one of pooling across depth " "or pooling across width/height." ) # TODO(mrry,shlens): Raise an error if the stride would cause # information in the input to be ignored. This will require a change # in the kernel implementation. if ksize_d == 1 : padding = op . get_attr ( "padding" ) out_rows , out_cols = get2d_conv_output_size ( in_rows , in_cols , ksize_r , ksize_c , stride_r , stride_c , padding ) output_shape = [ batch_size , out_rows , out_cols , depth ] else : if depth % ksize_d > 0 : raise ValueError ( "Depthwise max pooling requires the depth window " "to evenly divide the input depth." ) if stride_d != ksize_d : raise ValueError ( "Depthwise max pooling requires the depth window " "to equal the depth stride." ) output_shape = [ batch_size , in_rows , in_cols , depth // ksize_d ] if data_format == b"NCHW" : # Convert output shape back to NCHW. output_shape = [ output_shape [ 0 ] , output_shape [ 3 ] , output_shape [ 1 ] , output_shape [ 2 ] ] return [ tensor_shape . TensorShape ( output_shape ) ]