26 #ifndef MXNET_CPP_INITIALIZER_H_ 27 #define MXNET_CPP_INITIALIZER_H_ 40 const std::string& check_str) {
41 return (name.size() >= check_str.size() &&
42 name.substr(0, check_str.size()) == check_str);
45 const std::string& check_str) {
46 return (name.size() >= check_str.size() &&
47 name.substr(name.size() - check_str.size(), check_str.size()) ==
77 std::vector<float> weight(shape.Size(), 0);
79 float c = (2 * f - 1 - f % 2) / (2. * f);
80 for (
size_t i = 0; i < shape.Size(); ++i) {
82 int y = (i / shape[3]) % shape[2];
85 (*arr).SyncCopyFromCPU(weight);
122 : begin(begin), end(end) {}
133 : mu(mu), sigma(sigma) {}
163 : rand_type(rand_type), factor_type(factor_type), magnitude(magnitude) {}
167 float hw_scale = 1.0f;
168 if (shape.ndim() > 2) {
169 for (
size_t i = 2; i < shape.ndim(); ++i) {
170 hw_scale *= shape[i];
173 float fan_in = shape[1] * hw_scale, fan_out = shape[0] * hw_scale;
175 switch (factor_type) {
177 factor = (fan_in + fan_out) / 2.0;
185 float scale =
std::sqrt(magnitude / factor);
200 #endif // MXNET_CPP_INITIALIZER_H_ static bool StringStartWith(const std::string &name, const std::string &check_str)
Definition: initializer.h:39
static bool StringEndWith(const std::string &name, const std::string &check_str)
Definition: initializer.h:44
void operator()(const std::string &name, NDArray *arr) override
Definition: initializer.h:144
void operator()(const std::string &name, NDArray *arr) override
Definition: initializer.h:134
Definition: initializer.h:141
Definition: initializer.h:149
namespace of mxnet
Definition: base.h:126
dynamic shape class that can hold shape of arbirary dimension
Definition: shape.h:42
Definition: initializer.h:96
FactorType
Definition: initializer.h:155
Xavier(RandType rand_type=gaussian, FactorType factor_type=avg, float magnitude=3)
Definition: initializer.h:161
float value
Definition: initializer.h:104
Symbol sqrt(const std::string &symbol_name, Symbol data)
Definition: op.h:3007
virtual void InitOne(NDArray *arr)
Definition: initializer.h:88
virtual void InitGamma(NDArray *arr)
Definition: initializer.h:90
Definition: initializer.h:112
virtual void InitBias(NDArray *arr)
Definition: initializer.h:89
One()
Definition: initializer.h:114
virtual void InitZero(NDArray *arr)
Definition: initializer.h:87
NDArray interface.
Definition: ndarray.h:120
Definition: initializer.h:152
Definition: initializer.h:107
Definition: initializer.h:156
float sigma
Definition: initializer.h:138
virtual void InitBeta(NDArray *arr)
Definition: initializer.h:91
Definition: initializer.h:157
virtual void InitWeight(NDArray *arr)
Definition: initializer.h:92
Definition: initializer.h:130
RandType
Definition: initializer.h:151
Zero()
Definition: initializer.h:109
static void SampleUniform(mx_float begin, mx_float end, NDArray *out)
Sample uniform distribution for each elements of out.
Bilinear()
Definition: initializer.h:143
virtual void InitBilinear(NDArray *arr)
Definition: initializer.h:75
Symbol abs(const std::string &symbol_name, Symbol data)
Definition: op.h:2801
Normal(float mu, float sigma)
Definition: initializer.h:132
Symbol ceil(const std::string &symbol_name, Symbol data)
Definition: op.h:2891
Constant(float value)
Definition: initializer.h:98
virtual void InitDefault(NDArray *arr)
Definition: initializer.h:93
float magnitude
Definition: initializer.h:160
std::vector< mx_uint > GetShape() const
virtual void operator()(const std::string &name, NDArray *arr)
Definition: initializer.h:50
static void SampleGaussian(mx_float mu, mx_float sigma, NDArray *out)
Sample gaussian distribution for each elements of out.
void operator()(const std::string &name, NDArray *arr) override
Definition: initializer.h:165
void operator()(const std::string &name, NDArray *arr) override
Definition: initializer.h:100
Definition: initializer.h:37