27 #ifndef MXNET_CPP_INITIALIZER_H_ 28 #define MXNET_CPP_INITIALIZER_H_ 41 const std::string& check_str) {
42 return (name.size() >= check_str.size() &&
43 name.substr(0, check_str.size()) == check_str);
46 const std::string& check_str) {
47 return (name.size() >= check_str.size() &&
48 name.substr(name.size() - check_str.size(), check_str.size()) ==
78 std::vector<float> weight(shape.Size(), 0);
80 float c = (2 * f - 1 - f % 2) / (2. * f);
81 for (
size_t i = 0; i < shape.Size(); ++i) {
83 int y = (i / shape[3]) % shape[2];
86 (*arr).SyncCopyFromCPU(weight);
123 : begin(begin), end(end) {}
134 : mu(mu), sigma(sigma) {}
164 : rand_type(rand_type), factor_type(factor_type), magnitude(magnitude) {}
168 float hw_scale = 1.0f;
169 if (shape.ndim() > 2) {
170 for (
size_t i = 2; i < shape.ndim(); ++i) {
171 hw_scale *= shape[i];
174 float fan_in = shape[1] * hw_scale, fan_out = shape[0] * hw_scale;
176 switch (factor_type) {
178 factor = (fan_in + fan_out) / 2.0;
186 float scale =
std::sqrt(magnitude / factor);
201 #endif // MXNET_CPP_INITIALIZER_H_ static bool StringStartWith(const std::string &name, const std::string &check_str)
Definition: initializer.h:40
static bool StringEndWith(const std::string &name, const std::string &check_str)
Definition: initializer.h:45
void operator()(const std::string &name, NDArray *arr) override
Definition: initializer.h:145
void operator()(const std::string &name, NDArray *arr) override
Definition: initializer.h:135
Definition: initializer.h:142
Definition: initializer.h:150
namespace of mxnet
Definition: base.h:127
dynamic shape class that can hold shape of arbirary dimension
Definition: shape.h:43
Definition: initializer.h:97
FactorType
Definition: initializer.h:156
Xavier(RandType rand_type=gaussian, FactorType factor_type=avg, float magnitude=3)
Definition: initializer.h:162
float value
Definition: initializer.h:105
Symbol sqrt(const std::string &symbol_name, Symbol data)
Definition: op.h:1680
virtual void InitOne(NDArray *arr)
Definition: initializer.h:89
virtual void InitGamma(NDArray *arr)
Definition: initializer.h:91
Definition: initializer.h:113
virtual void InitBias(NDArray *arr)
Definition: initializer.h:90
One()
Definition: initializer.h:115
virtual void InitZero(NDArray *arr)
Definition: initializer.h:88
NDArray interface.
Definition: ndarray.h:121
Definition: initializer.h:153
Definition: initializer.h:108
Definition: initializer.h:157
float sigma
Definition: initializer.h:139
virtual void InitBeta(NDArray *arr)
Definition: initializer.h:92
Definition: initializer.h:158
virtual void InitWeight(NDArray *arr)
Definition: initializer.h:93
Definition: initializer.h:131
RandType
Definition: initializer.h:152
Zero()
Definition: initializer.h:110
static void SampleUniform(mx_float begin, mx_float end, NDArray *out)
Sample uniform distribution for each elements of out.
Bilinear()
Definition: initializer.h:144
virtual void InitBilinear(NDArray *arr)
Definition: initializer.h:76
Symbol abs(const std::string &symbol_name, Symbol data)
Definition: op.h:1427
Normal(float mu, float sigma)
Definition: initializer.h:133
Symbol ceil(const std::string &symbol_name, Symbol data)
Definition: op.h:1537
Constant(float value)
Definition: initializer.h:99
virtual void InitDefault(NDArray *arr)
Definition: initializer.h:94
float magnitude
Definition: initializer.h:161
std::vector< mx_uint > GetShape() const
virtual void operator()(const std::string &name, NDArray *arr)
Definition: initializer.h:51
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:166
void operator()(const std::string &name, NDArray *arr) override
Definition: initializer.h:101
Definition: initializer.h:38