void Net::InitWeights(const mxArray *mx_weights_in, mxArray *&mx_weights) { size_t num_weights = NumWeights(); bool isgen = false; if (mx_weights_in != NULL) { // training mexAssert(num_weights == mexGetNumel(mx_weights_in), "In InitWeights the vector of weights has the wrong length!"); mx_weights = mexDuplicateArray(mx_weights_in); } else { // genweights mx_weights = mexNewMatrix(1, num_weights); isgen = true; } weights_.Init(mexGetPointer(mx_weights), num_weights); size_t offset = 0; for (size_t i = 0; i < layers_.size(); ++i) { layers_[i]->InitWeights(weights_, offset, isgen); } }
void Net::GetWeights(mxArray *&mx_weights) const { size_t num_weights = NumWeights(); mx_weights = mexNewMatrix(num_weights, 1); Mat weights_cpu; weights_cpu.attach(mexGetPointer(mx_weights), num_weights, 1); Mat weights_mat(num_weights, 1); #if COMP_REGIME != 2 // CPU weights_mat.attach(weights_cpu); #endif size_t offset = 0; for (size_t i = 0; i < layers_.size(); ++i) { layers_[i]->GetWeights(weights_mat, offset); } #if COMP_REGIME == 2 // GPU DeviceToHost(weights_mat, weights_cpu); #endif }