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

Function avg_pool_shape

tensorflow/python/framework/common_shapes.py:356–421  ·  view source on GitHub ↗

Shape function for an AvgPool op. This op has one input: * input, a 4D tensor with shape = [batch_size, rows, cols, depth] 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 "ksize", "strides",

(op)

Source from the content-addressed store, hash-verified

354
355
356def avg_pool_shape(op):
357 """Shape function for an AvgPool op.
358
359 This op has one input:
360
361 * input, a 4D tensor with shape = [batch_size, rows, cols, depth]
362
363 The output is a 4D tensor with shape = [batch_size, out_rows,
364 out_cols, depth_out], where out_rows and out_cols depend on the
365 value of the op's "ksize", "strides", and "padding" attrs.
366
367 Args:
368 op: An AvgPool Operation.
369
370 Returns:
371 A single-element list containing the Shape of the AvgPool output.
372
373 Raises:
374 ValueError: If the shape of the input is invalid or incompatible with
375 the values of the attrs.
376 """
377 input_shape = op.inputs[0].get_shape().with_rank(4)
378 try:
379 data_format = op.get_attr("data_format")
380 except ValueError:
381 data_format = None
382
383 if data_format == b"NCHW":
384 # Convert input shape to the default NHWC for inference.
385 input_shape = [input_shape[0], input_shape[2], input_shape[3],
386 input_shape[1]]
387
388 if data_format == b"NCHW":
389 ksize_b, ksize_d, ksize_r, ksize_c = op.get_attr("ksize")
390 stride_b, stride_d, stride_r, stride_c = op.get_attr("strides")
391 else:
392 ksize_b, ksize_r, ksize_c, ksize_d = op.get_attr("ksize")
393 stride_b, stride_r, stride_c, stride_d = op.get_attr("strides")
394
395 batch_size = input_shape[0]
396 in_rows = input_shape[1]
397 in_cols = input_shape[2]
398 depth = input_shape[3]
399
400 if ksize_b != 1 or ksize_d != 1:
401 raise ValueError("Current implementation does not support pooling "
402 "in the batch and depth dimensions.")
403 if stride_b != 1 or stride_d != 1:
404 raise ValueError("Current implementation does not support strides "
405 "in the batch and depth dimensions.")
406
407 # TODO(mrry,shlens): Raise an error if the stride would cause
408 # information in the input to be ignored. This will require a change
409 # in the kernel implementation.
410 padding = op.get_attr("padding")
411
412 out_rows, out_cols = get2d_conv_output_size(in_rows, in_cols, ksize_r,
413 ksize_c, stride_r, stride_c,

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