MCPcopy Create free account
hub / github.com/alibaba/MNN / dumpTensorScales

Method dumpTensorScales

tools/quantization/calibration.cpp:1474–1572  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1472}
1473
1474void Calibration::dumpTensorScales(const std::string& modelFile) {
1475 rapidjson::StringBuffer sb;
1476 rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb);
1477
1478 writer.StartArray();
1479
1480 for (auto iter = _originalModel->oplists.begin(); iter != _originalModel->oplists.end(); iter++) {
1481 auto op = iter->get();
1482 const auto opType = op->type;
1483 const auto name = op->name;
1484
1485 if (opType == MNN::OpType_Raster) {
1486 continue;
1487 }
1488
1489 writer.StartObject();
1490
1491 writer.Key("name");
1492 writer.String(rapidjson::StringRef(name.c_str(), name.size()));
1493
1494 auto& inputIndexes = op->inputIndexes;
1495 const int inputSize = static_cast<int32_t>(inputIndexes.size());
1496
1497 if (inputSize > 0) {
1498 writer.Key("inputs");
1499 writer.StartArray();
1500 for (int i = 0; i < inputSize; ++i) {
1501 const auto curInputIndex = inputIndexes[i];
1502
1503 auto weakPtr = _tensorMap[curInputIndex].first.lock();
1504 if (weakPtr == nullptr) {
1505 continue;
1506 }
1507 auto inputOpScale = _scales[weakPtr];
1508
1509 writer.StartObject();
1510 writer.Key("tensorIndex");
1511 writer.Int(curInputIndex);
1512
1513 writer.Key("scales");
1514 writer.StartArray();
1515 writer.Double(inputOpScale.first);
1516 writer.EndArray();
1517
1518 writer.Key("zeropoint");
1519 writer.StartArray();
1520 writer.Double(inputOpScale.second);
1521 writer.EndArray();
1522
1523 writer.EndObject();
1524 }
1525 writer.EndArray();
1526 }
1527
1528 auto& outputIndexes = op->outputIndexes;
1529 const int outputSize = static_cast<int32_t>(outputIndexes.size());
1530
1531 if (outputSize > 0) {

Callers 1

quant_mainFunction · 0.80

Calls 15

StringRefClass · 0.50
StartArrayMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getMethod · 0.45
StartObjectMethod · 0.45
KeyMethod · 0.45
StringMethod · 0.45
c_strMethod · 0.45
sizeMethod · 0.45
lockMethod · 0.45
IntMethod · 0.45

Tested by

no test coverage detected