26 #ifndef MSHADOW_EXTENSION_SPATIAL_UNPOOL_H_ 27 #define MSHADOW_EXTENSION_SPATIAL_UNPOOL_H_ 29 #include "../extension.h" 39 template<
typename Reducer,
typename SrcExp,
typename DType,
int srcdim>
41 public MakeTensorExp<UnPoolingExp<Reducer, SrcExp, DType, srcdim>,
42 SrcExp, srcdim, DType> {
63 const SrcExp &data_pooled,
64 const SrcExp &grad_pooled,
66 : data_src_(data_src), data_pooled_(data_pooled),
67 grad_pooled_(grad_pooled),
68 ksize_y_(ksize_y), ksize_x_(ksize_x),
69 kstride_y_(kstride_y), kstride_x_(kstride_x) {
72 CHECK_EQ(pshape, ShapeCheckSrcDimSrcExp::Check(data_pooled))
73 <<
"UnPoolingExp: pooled shape mismatch";
75 for (
int k = 0; k < srcdim - 2; ++k) {
76 CHECK_EQ(pshape[k], sshape[k]) <<
"UnPoolingExp: pool and src shape mismatch";
78 pshape_x_ = pshape[srcdim - 1];
79 pshape_y_ = pshape[srcdim - 2];
99 template<
typename Reducer,
typename SrcExp,
typename DType,
int etype>
106 (data_src.
self(), data_pooled.
self(), grad_pooled.
self(),
107 ksize_y, ksize_x, kstride_y, kstride_x);
112 template<
typename Reducer,
typename SrcExp,
typename DType,
int srcdim>
124 const index_t y = i % sshape_y_;
125 const index_t c = i / sshape_y_;
134 DType val =
static_cast<DType
>(0);
135 for (
index_t py = py_min; py < py_max; ++py) {
136 for (
index_t px = px_min; px < px_max; ++px) {
137 val += Reducer::PartialGrad(vsrc,
154 #endif // MSHADOW_EXTENSION_SPATIAL_UNPOOL_H_ const SrcExp & grad_pooled_
gradient data of pooled part, to be propgate down
Definition: spatial_unpool.h:48
Definition: expr_engine-inl.h:59
index_t kstride_x_
kernel stride in x directory
Definition: spatial_unpool.h:60
Definition: optional.h:241
index_t ksize_x_
kernel size in width
Definition: spatial_unpool.h:56
index_t pshape_x_
shape of pooled expression
Definition: spatial_unpool.h:52
const SrcExp & data_pooled_
result of pooled data, corresponds to result of pooling
Definition: spatial_unpool.h:46
unpooling expr reverse operation of pooling, used to pass gradient back
Definition: spatial_unpool.h:40
static Shape< dim > Check(const E &t)
const SrcExp & data_src_
source input, corresponds to src in pooling
Definition: spatial_unpool.h:44
#define MSHADOW_XINLINE
Definition: base.h:223
int32_t index_t
type that will be used for index
Definition: base.h:336
Plan(const UnPoolingExp< Reducer, SrcExp, DType, srcdim > &e)
Definition: spatial_unpool.h:115
runtime shape checking template get the shape of an expression, report error if shape mismatch ...
Definition: expr_engine-inl.h:365
index_t pshape_y_
shape of pooled expression
Definition: spatial_unpool.h:50
UnPoolingExp(const SrcExp &data_src, const SrcExp &data_pooled, const SrcExp &grad_pooled, index_t ksize_y, index_t ksize_x, index_t kstride_y, index_t kstride_x)
constructor
Definition: spatial_unpool.h:62
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:80
const SubType & self(void) const
Definition: expression.h:83
Plan< BinaryMapExp< OP, TA, TB, DType, etype >, DType > MakePlan(const BinaryMapExp< OP, TA, TB, DType, etype > &e)
Definition: expr_engine-inl.h:240
a general class that allows extension that makes tensors of some shape
Definition: expr_engine-inl.h:44
index_t ksize_y_
kernel size in height
Definition: spatial_unpool.h:54
overloaded + operator between half_t and bf16_t
Definition: base.h:327
MSHADOW_XINLINE DType Eval(index_t i, index_t j) const
Definition: spatial_unpool.h:121
Shape< dim > shape_
the shape of this expression
Definition: expr_engine-inl.h:48
UnPoolingExp< Reducer, SrcExp, DType, ExpInfo< SrcExp >::kDim > unpool(const Exp< SrcExp, DType, etype > &data_src, const Exp< SrcExp, DType, etype > &data_pooled, const Exp< SrcExp, DType, etype > &grad_pooled, index_t ksize_y, index_t ksize_x, index_t kstride_y, index_t kstride_x)
unpooling gradient for 4D, backprop gradient value back, revserse operation of pooling, same as unpooling, but allows unequal size of kernel
Definition: spatial_unpool.h:101
index_t kstride_y_
kernel stride in y directory
Definition: spatial_unpool.h:58