MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / max_pool_shape

Function max_pool_shape

tensorflow/python/framework/common_shapes.py:424–501  ·  view source on GitHub ↗

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

(op)

Source from the content-addressed store, hash-verified

422
423
424def max_pool_shape(op):
425 """Shape function for a MaxPool op.
426
427 This op has one input:
428
429 * input, a 4D tensor with shape = [batch_size, rows, cols, depth_in]
430
431 The output is a 4D tensor with shape = [batch_size, out_rows,
432 out_cols, depth_out], where out_rows, out_cols, and depth_out depend
433 on the value of the op's "ksize", "strides", and "padding" attrs.
434
435 Args:
436 op: A MaxPool Operation.
437
438 Returns:
439 A single-element list containing the Shape of the MaxPool output.
440
441 Raises:
442 ValueError: If the shape of the input is invalid or incompatible with
443 the values of the attrs.
444 """
445 input_shape = op.inputs[0].get_shape().with_rank(4)
446 try:
447 data_format = op.get_attr("data_format")
448 except ValueError:
449 data_format = None
450
451 if data_format == b"NCHW":
452 # Convert input shape to the default NHWC for inference.
453 input_shape = [input_shape[0], input_shape[2], input_shape[3],
454 input_shape[1]]
455
456 if data_format == b"NCHW":
457 ksize_b, ksize_d, ksize_r, ksize_c = op.get_attr("ksize")
458 stride_b, stride_d, stride_r, stride_c = op.get_attr("strides")
459 else:
460 ksize_b, ksize_r, ksize_c, ksize_d = op.get_attr("ksize")
461 stride_b, stride_r, stride_c, stride_d = op.get_attr("strides")
462
463 batch_size = input_shape[0]
464 in_rows = input_shape[1]
465 in_cols = input_shape[2]
466 depth = input_shape[3]
467
468 if ksize_b != 1:
469 raise ValueError("Current implementation does not support pooling "
470 "in the batch dimension.")
471 if stride_b != 1:
472 raise ValueError("Current implementation does not support strides "
473 "in the batch dimension.")
474
475 if not ((ksize_r == 1 and ksize_c == 1) or ksize_d == 1):
476 raise ValueError("MaxPooling supports exactly one of pooling across depth "
477 "or pooling across width/height.")
478
479 # TODO(mrry,shlens): Raise an error if the stride would cause
480 # information in the input to be ignored. This will require a change
481 # in the kernel implementation.

Callers

nothing calls this directly

Calls 4

get2d_conv_output_sizeFunction · 0.85
with_rankMethod · 0.80
get_shapeMethod · 0.45
get_attrMethod · 0.45

Tested by

no test coverage detected