Skip to content

Commit

Permalink
MaxUnpooling3DAttributes and functions for shape calculation.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 288687596
Change-Id: Icc3ebc21c564f88c89dbc9b203cc738c0def6e08
  • Loading branch information
tensorflower-gardener committed Jan 8, 2020
1 parent d8d6252 commit f947e4d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tensorflow/lite/delegates/gpu/common/operations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ int32_t CalculateSamePadding(const BHWC& input,
/*dilation=*/1, attr.strides.get<AxisT>());
}

template <Axis AxisT>
int32_t CalculateSamePadding(const BHWDC& input,
const MaxUnpooling3DAttributes& attr) {
return CalculateSamePadding(input.get<AxisT>(), attr.kernel.get<AxisT>(),
/*dilation=*/1, attr.strides.get<AxisT>());
}

Padding2D MakeSamePadding(const BHWC& input,
const ConvolutionTransposedAttributes& attr) {
int32_t padding_height = CalculateSamePadding<Axis::HEIGHT>(input, attr);
Expand Down Expand Up @@ -375,6 +382,18 @@ BHWC CalculateOutputShape(const BHWC& input,
input.c);
}

BHWDC CalculateOutputShape(const BHWDC& input,
const MaxUnpooling3DAttributes& attr) {
return BHWDC(input.b,
input.h * attr.strides.h - attr.padding.prepended.h -
attr.padding.appended.h,
input.w * attr.strides.w - attr.padding.prepended.w -
attr.padding.appended.w,
input.d * attr.strides.d - attr.padding.prepended.d -
attr.padding.appended.d,
input.c);
}

BHWC CalculateOutputShape(const BHWC& input, const Pooling2DAttributes& attr) {
return BHWC(input.b, CalculateOutput<Axis::HEIGHT>(input, attr),
CalculateOutput<Axis::WIDTH>(input, attr), input.c);
Expand Down Expand Up @@ -527,6 +546,11 @@ Padding2D CalculateSamePadding(const BHWC& input,
return MakeSamePadding(input, attr);
}

Padding3D CalculateSamePadding(const BHWDC& input,
const MaxUnpooling3DAttributes& attr) {
return MakeSamePadding(input, attr);
}

float CalculateResizeScale(int32_t input_size, int32_t output_size,
const Upsample2DAttributes& attr) {
return attr.align_corners && input_size > 1 && output_size > 1
Expand Down
17 changes: 17 additions & 0 deletions tensorflow/lite/delegates/gpu/common/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ struct MaxUnpooling2DAttributes {
Padding2D padding;
};

struct MaxUnpooling3DAttributes {
// Strides for every axis.
HWD strides = HWD(0, 0, 0);
HWD kernel = HWD(0, 0, 0);
Padding3D padding;
};

struct ConcatAttributes {
// Defines axis by which to concat on.
Axis axis = Axis::UNKNOWN;
Expand All @@ -169,6 +176,11 @@ struct ConcatAttributes {
BHWC CalculateOutputShape(const BHWC& input,
const MaxUnpooling2DAttributes& attr);

// @return shape of a tensor after MaxUnpooling3D operation is applied to
// the given input.
BHWDC CalculateOutputShape(const BHWDC& input,
const MaxUnpooling3DAttributes& attr);

// @return shape of a tensor after Pooling2D operation is applied to the given
// input.
BHWC CalculateOutputShape(const BHWC& input, const Pooling2DAttributes& attr);
Expand Down Expand Up @@ -197,6 +209,11 @@ Padding3D CalculateSamePadding(const BHWDC& input,
Padding2D CalculateSamePadding(const BHWC& input,
const MaxUnpooling2DAttributes& attr);

// @return padding for max unpooling operation to make sure output keep the same
// shape as the given input.
Padding3D CalculateSamePadding(const BHWDC& input,
const MaxUnpooling3DAttributes& attr);

struct Convolution2DAttributes {
HW strides = HW(1, 1); // Along each axis.
HW dilations = HW(1, 1); // Along each axis.
Expand Down

0 comments on commit f947e4d

Please sign in to comment.