MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / setTensorScalesFromCalibration

Function setTensorScalesFromCalibration

samples/common/sampleEngines.cpp:194–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192}
193
194void setTensorScalesFromCalibration(nvinfer1::INetworkDefinition& network, std::vector<IOFormat> const& inputFormats,
195 std::vector<IOFormat> const& outputFormats, std::string const& calibrationFile)
196{
197 auto const tensorScales = readScalesFromCalibrationCache(calibrationFile);
198 bool const broadcastInputFormats = broadcastIOFormats(inputFormats, network.getNbInputs());
199 for (int32_t i = 0, n = network.getNbInputs(); i < n; ++i)
200 {
201 int32_t formatIdx = broadcastInputFormats ? 0 : i;
202 if (!inputFormats.empty() && inputFormats[formatIdx].first == DataType::kINT8)
203 {
204 auto* input = network.getInput(i);
205 auto const calibScale = tensorScales.at(input->getName());
206 input->setDynamicRange(-127 * calibScale, 127 * calibScale);
207 }
208 }
209 bool const broadcastOutputFormats = broadcastIOFormats(outputFormats, network.getNbInputs());
210 for (int32_t i = 0, n = network.getNbOutputs(); i < n; ++i)
211 {
212 int32_t formatIdx = broadcastOutputFormats ? 0 : i;
213 if (!outputFormats.empty() && outputFormats[formatIdx].first == DataType::kINT8)
214 {
215 auto* output = network.getOutput(i);
216 auto const calibScale = tensorScales.at(output->getName());
217 output->setDynamicRange(-127 * calibScale, 127 * calibScale);
218 }
219 }
220}
221
222//!
223//! \brief Generate a network definition for a given model

Callers 1

setupNetworkAndConfigFunction · 0.85

Calls 9

broadcastIOFormatsFunction · 0.85
getNbInputsMethod · 0.45
emptyMethod · 0.45
getInputMethod · 0.45
getNameMethod · 0.45
setDynamicRangeMethod · 0.45
getNbOutputsMethod · 0.45
getOutputMethod · 0.45

Tested by

no test coverage detected