parameters: (op)
return_statement: return [tensor_shape.TensorShape(output_shape)]
docstring: Shape function for a Conv2D op.
  
    This op has two inputs:
  
    * input, a 4D tensor with shape = [batch_size, rows, cols, depth_in]
    * filter, a 4D tensor with shape =  [filter_rows, filter_cols,
      depth_in, depth_out]
  
    The output is a 4D tensor with shape = [batch_size, out_rows,
    out_cols, depth_out], where out_rows and out_cols depend on the
    value of the op's "padding" and "strides" attrs.
  
    Args:
      op: A Conv2D Operation.
  
    Returns:
      A list containing the Shape of the Conv2D output.
  
    Raises:
      ValueError: If the shapes of the input or filter are incompatible.
docstring_summary: Shape function for a Conv2D op.
docstring_tokens: Shape function for a Conv2D op .
function: def conv2d_shape(op):
    """Shape function for a Conv2D op.
  
    This op has two inputs:
  
    * input, a 4D tensor with shape = [batch_size, rows, cols, depth_in]
    * filter, a 4D tensor with shape =  [filter_rows, filter_cols,
      depth_in, depth_out]
  
    The output is a 4D tensor with shape = [batch_size, out_rows,
    out_cols, depth_out], where out_rows and out_cols depend on the
    value of the op's "padding" and "strides" attrs.
  
    Args:
      op: A Conv2D Operation.
  
    Returns:
      A list containing the Shape of the Conv2D output.
  
    Raises:
      ValueError: If the shapes of the input or filter are incompatible.
    """
    input_shape = op.inputs[0].get_shape().with_rank(4)
    filter_shape = op.inputs[1].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]]
  
    batch_size = input_shape[0]
    in_rows = input_shape[1]
    in_cols = input_shape[2]
  
    filter_rows = filter_shape[0]
    filter_cols = filter_shape[1]
    depth_out = filter_shape[3]
    # Check that the input depths are compatible.
    input_shape[3].assert_is_compatible_with(filter_shape[2])
  
    if data_format == b"NCHW":
      stride_b, stride_d, stride_r, stride_c = op.get_attr("strides")
    else:
      stride_b, stride_r, stride_c, stride_d = op.get_attr("strides")
  
    if stride_b != 1 or stride_d != 1:
      raise ValueError("Current implementation does not yet support "
                       "strides in the batch and depth dimensions.")
    # 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.
    padding = op.get_attr("padding")
    out_rows, out_cols = get2d_conv_output_size(in_rows, in_cols, filter_rows,
                                                filter_cols, stride_r, stride_c,
                                                padding)
  
    output_shape = [batch_size, out_rows, out_cols, depth_out]
    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 conv2d_shape ( op ) : input_shape = op . inputs [ 0 ] . get_shape ( ) . with_rank ( 4 ) filter_shape = op . inputs [ 1 ] . 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 ] ] batch_size = input_shape [ 0 ] in_rows = input_shape [ 1 ] in_cols = input_shape [ 2 ] filter_rows = filter_shape [ 0 ] filter_cols = filter_shape [ 1 ] depth_out = filter_shape [ 3 ] # Check that the input depths are compatible. input_shape [ 3 ] . assert_is_compatible_with ( filter_shape [ 2 ] ) if data_format == b"NCHW" : stride_b , stride_d , stride_r , stride_c = op . get_attr ( "strides" ) else : stride_b , stride_r , stride_c , stride_d = op . get_attr ( "strides" ) if stride_b != 1 or stride_d != 1 : raise ValueError ( "Current implementation does not yet support " "strides in the batch and depth dimensions." ) # 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. padding = op . get_attr ( "padding" ) out_rows , out_cols = get2d_conv_output_size ( in_rows , in_cols , filter_rows , filter_cols , stride_r , stride_c , padding ) output_shape = [ batch_size , out_rows , out_cols , depth_out ] 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 ) ]