Go to the documentation of this file.
25 #ifndef MSHADOW_EXTENSION_CHANNEL_POOL_H_
26 #define MSHADOW_EXTENSION_CHANNEL_POOL_H_
28 #include "../extension.h"
39 template<
typename Reducer,
typename SrcExp,
typename DType,
int srcdim>
41 public MakeTensorExp<ChannelPoolingExp<Reducer, SrcExp, DType, srcdim>,
42 SrcExp, srcdim, DType> {
56 this->src_channel_ = this->
shape_[srcdim - 3];
58 <<
"chpool: local size must be smaller than nchannels";
59 this->
shape_[srcdim - 3] = (this->src_channel_ - nsize +
pad * 2 + 1) / stride;
73 template<
typename Reducer,
typename SrcExp,
typename DType,
int etype>
74 inline ChannelPoolingExp<Reducer, SrcExp, DType, ExpInfo<SrcExp>::kDim>
77 ::Error_Expression_Does_Not_Meet_Dimension_Req();
78 CHECK_EQ(nsize % 2, 1U) <<
"chpool: if no pad is specified, local size must be odd";
83 template<
typename Reducer,
typename SrcExp,
typename DType,
int etype>
84 inline ChannelPoolingExp<Reducer, SrcExp, DType, ExpInfo<SrcExp>::kDim>
87 ::Error_Expression_Does_Not_Meet_Dimension_Req();
95 template<
typename Reducer,
typename SrcExp,
typename DType,
int srcdim>
99 : src_(
MakePlan(e.src_)), channel_(e.shape_[srcdim - 3]),
100 height_(e.shape_[srcdim - 2]), width_(e.shape_[srcdim - 1]),
101 hnsize_(e.nsize_), stride_(e.stride_), pad_(e.pad_),
102 src_channel_(e.src_channel_) {}
107 const index_t c = i % channel_;
108 const index_t n = i / channel_;
110 const index_t cstart = c * stride_ < pad_ ? 0 : c * stride_ - pad_;
111 const index_t cend = min(c * stride_ - pad_ + hnsize_, channel_);
112 DType res; Reducer::SetInitValue(res);
113 for (
index_t cc = cstart; cc < cend; ++cc) {
114 Reducer::Reduce(res, src_.Eval((n * src_channel_ + cc) * height_ + y, x));
121 const index_t channel_, height_, width_, hnsize_, stride_, pad_, src_channel_;
125 #endif // MSHADOW_EXTENSION_CHANNEL_POOL_H_
index_t nsize_
neighbor size
Definition: channel_pool.h:46
index_t src_channel_
Definition: channel_pool.h:51
const SubType & self(void) const
Definition: expression.h:82
index_t stride_
stride of pooling
Definition: channel_pool.h:48
used to help static type check
Definition: expr_engine-inl.h:330
MSHADOW_XINLINE DType Eval(index_t i, index_t j) const
Definition: channel_pool.h:103
const SrcExp & src_
source operand
Definition: channel_pool.h:44
#define MSHADOW_XINLINE
Definition: base.h:228
static Shape< dim > Check(const E &t)
index_t pad_
pad of pooling of each side
Definition: channel_pool.h:50
static type inference template, used to get the dimension of each expression, if ExpInfo<E>::kDim == ...
Definition: expr_engine-inl.h:262
Plan< BinaryMapExp< OP, TA, TB, DType, etype >, DType > MakePlan(const BinaryMapExp< OP, TA, TB, DType, etype > &e)
Definition: expr_engine-inl.h:239
Shape< dim > shape_
the shape of this expression
Definition: expr_engine-inl.h:47
ChannelPoolingExp(const SrcExp &src, index_t nsize, index_t stride, index_t pad)
constructor
Definition: channel_pool.h:53
int32_t index_t
type that will be used for index
Definition: base.h:328
Definition: expr_engine-inl.h:58
channel pooling expression, do reduction over (local nearby) channels, used to implement local respon...
Definition: channel_pool.h:40
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:79
PaddingExp< SrcExp, DType, ExpInfo< SrcExp >::kDim > pad(const Exp< SrcExp, DType, etype > &src, index_t pad)
padding expression, pad a image with zeros on boundaries, padding affects shape[0],...
Definition: pad.h:71
overloaded + operator between half_t and bf16_t
Definition: base.h:319
a general class that allows extension that makes tensors of some shape
Definition: expr_engine-inl.h:43
Definition: optional.h:251
ChannelPoolingExp< Reducer, SrcExp, DType, ExpInfo< SrcExp >::kDim > chpool(const Exp< SrcExp, DType, etype > &src, index_t nsize)
channel pooling, do reduction over (local nearby) channels, used to implement local response normaliz...
Definition: channel_pool.h:75
Plan(const ChannelPoolingExp< Reducer, SrcExp, DType, srcdim > &e)
Definition: channel_pool.h:98