A representative dataset supplies sample inputs for activation-range calibration during full-integer TFLite quantization. TFLite manages calibration internally; about 200 samples suffice for most vision models, with diminishing returns beyond that. Static calibration is unsuitable for models with high activation variance, such as transformers. section 6.3
Listing 6.5 Representative dataset generator for calibration
def make_representative_dataset(images, num_calibration=200):
def generator(): #A
indices = np.random.RandomState(42).choice(
len(images), size=min(num_calibration, len(images)),
replace=False
)
for i in indices:
yield [images[i:i+1].astype(np.float32)] #B
return generator #CSee a MobileNetV2 generator that selects up to 200 images without replacement and yields batch-one float32 inputs. section 6.3
