我一直在寻找一种方法来使用 OpenVINO 框架上的 C++ API 为网络的每一层获取权重/参数和偏差的张量。我在文档中找不到任何内容,也找不到示例中的任何示例。我怎样才能提取这些张量?
谢谢,塞萨尔。
编辑:分别获取权重和偏差的代码:
for (auto&& layer : this->pImplementation->network) {
weightsbuf << "Layer name: " << layer->name << std::endl;
weightsbuf << "Parameters:" << std::endl;
for (auto&& param : layer->params) {
weightsbuf << '\t' << param.first << ": " << param.second << std::endl;
}
std::vector<int> kernelvect;
auto kernelsize = layer->params.at("kernel");
std::stringstream ss(kernelsize);
// split by comma kernel size
for (int i; ss >> i;) {
kernelvect.push_back(i);
if (ss.peek() == ',')
ss.ignore();
}
int noutputs = std::stoi(layer->params.at("output"));
int nweights = kernelvect[0] * kernelvect[1] * noutputs;
int nbias = noutputs;
for (auto&& blob : layer->blobs) {
weightsbuf << '\t' << blob.first << ": ";
for (size_t w = 0; w < nweights; ++w) {
weightsbuf << blob.second->buffer().as<float*>()[w] << " ";
}
weightsbuf << std::endl;
weightsbuf << '\t' << "biases:";
for (size_t b = 0; b < nbias; ++b) {
weightsbuf << blob.second->buffer().as<float*>()[nweights + b] << " ";
}
}
weightsbuf << std::endl;
}