IInt8LegacyCalibrator¶
- class tensorrt.IInt8LegacyCalibrator(self: tensorrt.tensorrt.IInt8LegacyCalibrator)¶
[已弃用] 在 TensorRT 10.1 中已弃用。已被显式量化取代。
扩展了
IInt8Calibrator
类。 此校准器需要用户参数化,如果其他校准器产生不良结果,则作为后备选项提供。要实现自定义校准器,请确保在
__init__()
中显式实例化基类class MyCalibrator(trt.IInt8LegacyCalibrator): def __init__(self): trt.IInt8LegacyCalibrator.__init__(self)
- 变量:
quantile –
float
分位数(介于 0 和 1 之间),当使用分位数方法时,将用于选择区域最大值。 有关如何使用分位数的更多详细信息,请参阅用户指南。regression_cutoff –
float
最大值的百分比(介于 0 和 1 之间),用于在使用回归确定区域最大值时定义回归截止值。 有关如何使用回归截止值的更多详细信息,请参阅用户指南
- get_algorithm(self: tensorrt.tensorrt.IInt8LegacyCalibrator) tensorrt.tensorrt.CalibrationAlgoType ¶
表示这是旧版校准器。
- 返回值:
CalibrationAlgoType.LEGACY_CALIBRATION
- get_batch(self: tensorrt.tensorrt.IInt8LegacyCalibrator, names: List[str]) List[int] ¶
获取用于校准的输入批次。 输入的批次大小必须与
get_batch_size()
返回的批次大小匹配。可能的实现可能如下所示
def get_batch(names): try: # Assume self.batches is a generator that provides batch data. data = next(self.batches) # Assume that self.device_input is a device buffer allocated by the constructor. cuda.memcpy_htod(self.device_input, data) return [int(self.device_input)] except StopIteration: # When we're out of batches, we return either [] or None. # This signals to TensorRT that there is no calibration data remaining. return None
- 参数:
names – 绑定数组中每个对象的网络输入的名称。
- 返回值:
一个
list
设备内存指针列表,设置为包含每个网络输入数据的内存,如果不再有用于校准的批次,则为空list
。 您可以使用 pycuda 分配这些设备缓冲区,例如,然后将其强制转换为int
以检索指针。
- get_batch_size(self: tensorrt.tensorrt.IInt8Calibrator) int ¶
获取用于校准批次的批次大小。
- 返回值:
批次大小。
- read_calibration_cache(self: tensorrt.tensorrt.IInt8LegacyCalibrator) buffer ¶
加载校准缓存。
校准可能很耗时,因此生成一次校准数据,然后在后续网络构建中使用它可能很有用。 缓存包括用于生成它的回归截止值和分位数,如果这些值与当前校准器的设置不匹配,则不会使用该缓存。 但是,如果网络的结构发生变化或输入数据集发生变化,也应重新校准网络,应用程序有责任确保这一点。
读取缓存就像在 Python 中读取任何其他文件一样。 例如,一种可能的实现是
def read_calibration_cache(self): # If there is a cache, use it instead of calibrating again. Otherwise, implicitly return None. if os.path.exists(self.cache_file): with open(self.cache_file, "rb") as f: return f.read()
- 返回值:
缓存对象;如果没有数据,则为 None。
- write_calibration_cache(self: tensorrt.tensorrt.IInt8LegacyCalibrator, cache: buffer) None ¶
保存校准缓存。
写入缓存就像在 Python 中写入任何其他缓冲区一样。 例如,一种可能的实现是
def write_calibration_cache(self, cache): with open(self.cache_file, "wb") as f: f.write(cache)
- 参数:
cache – 要写入的校准缓存。