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

Function ComputeConvSizes

tensorflow/lite/kernels/internal/test_util.cc:23–65  ·  view source on GitHub ↗

this is a copied from an internal function in propagate_fixed_sizes.cc

Source from the content-addressed store, hash-verified

21
22// this is a copied from an internal function in propagate_fixed_sizes.cc
23bool ComputeConvSizes(const RuntimeShape& input_shape, int output_depth,
24 int filter_width, int filter_height, int stride,
25 int dilation_width_factor, int dilation_height_factor,
26 PaddingType padding_type, RuntimeShape* output_shape,
27 int* pad_width, int* pad_height) {
28 const int input_width = input_shape.Dims(2);
29 const int input_height = input_shape.Dims(1);
30 const int batch = input_shape.Dims(0);
31
32 int dilated_filter_width = dilation_width_factor * (filter_width - 1) + 1;
33 int dilated_filter_height = dilation_height_factor * (filter_height - 1) + 1;
34
35 int output_height = 0;
36 int output_width = 0;
37 if (padding_type == PaddingType::kValid) {
38 // Official TF is
39 // ceil((input_height - (dilated_filter_height - 1)) / stride),
40 // implemented as
41 // floor(
42 // (input_height - (dilated_filter_height - 1) + (stride - 1)) / stride).
43 output_height = (input_height + stride - dilated_filter_height) / stride;
44 output_width = (input_width + stride - dilated_filter_width) / stride;
45 } else if (padding_type == PaddingType::kSame) {
46 output_height = (input_height + stride - 1) / stride;
47 output_width = (input_width + stride - 1) / stride;
48 } else {
49 return false;
50 }
51
52 if (output_width <= 0 || output_height <= 0) {
53 return false;
54 }
55
56 *pad_height = std::max(
57 0, ((output_height - 1) * stride + dilated_filter_height - input_height) /
58 2);
59 *pad_width = std::max(
60 0,
61 ((output_width - 1) * stride + dilated_filter_width - input_width) / 2);
62
63 output_shape->BuildFrom({batch, output_height, output_width, output_depth});
64 return true;
65}
66
67std::mt19937& RandomEngine() {
68 static std::mt19937 engine;

Callers 3

TryTestOneDepthwiseConvFunction · 0.70
TryTestDepthwiseConvFunction · 0.70

Calls 3

DimsMethod · 0.80
BuildFromMethod · 0.80
maxFunction · 0.50

Tested by

no test coverage detected