* @brief UpdatableParam that could be updated thorugh optimizer
*/
struct UpdatableParam {
- Tensor weight; /**< weight to be updated and used */
- Tensor grad; /**< gradient for the weight */
- std::string name; /**< name of the parameter */
+ Tensor weight; /**< weight to be updated and used */
+ Tensor grad; /**< gradient for the weight */
+ std::string name; /**< name of the parameter */
+ bool updatable = true; /**< if this param is updatable */
};
/**
beta.setZero();
setParamSize(4);
- paramsAt(0) = {std::move(mu), Tensor(), "BN:moving_average"};
- paramsAt(1) = {std::move(var), Tensor(), "BN:moving_variance"};
+ paramsAt(0) = {std::move(mu), Tensor(), "BN:moving_average", false};
+ paramsAt(1) = {std::move(var), Tensor(), "BN:moving_variance", false};
paramsAt(2) = {std::move(gamma), Tensor(gamma.getDim()), "BN:gamma"};
paramsAt(3) = {std::move(beta), Tensor(beta.getDim()), "BN:beta"};
.divide_i(cvar.multiply(batch))
.run();
- std::shared_ptr<UpdatableParam> grad_params(params, params.get() + 2);
-
- opt.apply_gradients(grad_params, param_size - 2, iteration);
+ opt.apply_gradients(params, param_size, iteration);
return MAKE_SHARED_TENSOR(std::move(dx));
}
this->opt.setType(opt.getType());
this->opt.setOptParam(opt.getOptParam());
- return this->opt.initialize(getParams(), param_size, true);
+ return this->opt.initialize(params, param_size, true);
}
int Layer::checkValidation() {
for (unsigned int i = 0; i < param_size; ++i) {
UpdatableParam ¶m = param_data[i];
+ if (!param.updatable)
+ continue;
+
Tensor &weight = param.weight;
Tensor &grad = param.grad;
Tensor w = Tensor(weight.getDim());
for (unsigned int i = 0; i < param_size; ++i) {
UpdatableParam ¶m = param_data[i];
+ if (!param.updatable)
+ continue;
+
Tensor &x = param.weight;
const Tensor &x_grad = param.grad;
switch (type) {