This guide explains how to quantize AnomaVision PaDiM and PatchCore with Vitis AI 3.5, generate an INT8 XModel, validate it, and compile it for the AMD/Xilinx Kria KV260 DPU.
The workflow is intended for a Linux environment with the Vitis AI tools available.
The deployment flow is:
AnomaVision PyTorch model
↓
Vitis AI INT8 calibration
↓
INT8 XModel
↓
XModel validation
↓
vai_c_xir + KV260 arch.json
↓
KV260 DPU compiled model
Both PaDiM and PatchCore use the same basic workflow.
Run Docker with v to dataset and Anomavison
docker run --rm -it -v ~/Vitis-AI/AnomaVision:/workspace/AnomaVision -v /root/dataset:/workspace/dataset xilinx/vitis-ai-pytorch-cpu:latest bash
Activate the Vitis AI PyTorch environment:
conda activate vitis-ai-pytorch
Check that the compiler is available:
vai_c_xir -h
You should be able to run the command without a command not found error.
cd /workspace/AnomaVision
Check the repository:
ls
The KV260 quantization scripts are:
quantize_padim_kv260.py
quantize_patchcore_kv260.py
Use normal/good training images for INT8 calibration.
For the MVTec bottle example:
/workspace/dataset/bottle/train/good
Check the directory:
ls /workspace/dataset/bottle/train/good | head
The calibration set should contain representative normal images. It should normally come from the same type of data used to train the anomaly detector.
The example PaDiM model is:
distributions/padim/bottle/anomav_exp/model.pt
The output directory used below is:
compiled_padim_kv260
Run the calibration phase:
python quantize_padim_kv260.py \
--model distributions/padim/bottle/anomav_exp/model.pt \
--calibration-dir /workspace/dataset/bottle/train/good \
--output-dir compiled_padim_kv260 \
--quant_mode calib
The calibration phase collects activation statistics and prepares the quantization configuration.
Check the generated files:
find compiled_padim_kv260 -maxdepth 2 -type f
Run the script in test mode:
python quantize_padim_kv260.py \
--model distributions/padim/bottle/anomav_exp/model.pt \
--calibration-dir /workspace/dataset/bottle/train/good \
--output-dir compiled_padim_kv260 \
--quant_mode test
The important output is:
compiled_padim_kv260/PadimKV260_int.xmodel
Check that the XModel exists:
ls -lh compiled_padim_kv260/*.xmodel
You can also inspect it with XIR:
python -c "import xir; g=xir.Graph.deserialize('compiled_padim_kv260/PadimKV260_int.xmodel'); print('XModel OK:', g.get_name()); print('Ops:', len(g.get_ops()))"
If the graph loads successfully, the generated XModel is readable by XIR.
Use the KV260 DPU architecture file:
vai_c_xir \
-x compiled_padim_kv260/PadimKV260_int.xmodel \
-a /opt/vitis_ai/compiler/arch/DPUCZDX8G/KV260/arch.json \
-o compiled_padim_kv260/compiled \
-n PadimKV260
The compiled output is placed under:
compiled_padim_kv260/compiled
The example PatchCore model is:
distributions/patchcore/bottle/anomav_exp/model.pt
Calibration images are the same normal training images:
/workspace/dataset/bottle/train/good
python quantize_patchcore_kv260.py \
--model distributions/patchcore/bottle/anomav_exp/model.pt \
--calibration-dir /workspace/dataset/bottle/train/good \
--output-dir compiled_patchcore_kv260 \
--quant_mode calib
Check the output:
find compiled_patchcore_kv260 -maxdepth 2 -type f
Run test mode:
python quantize_patchcore_kv260.py \
--model distributions/patchcore/bottle/anomav_exp/model.pt \
--calibration-dir /workspace/dataset/bottle/train/good \
--output-dir compiled_patchcore_kv260 \
--quant_mode test
The important output is:
compiled_patchcore_kv260/PatchCoreKV260_int.xmodel
ls -lh compiled_patchcore_kv260/*.xmodel
Inspect it with XIR:
python -c "import xir; g=xir.Graph.deserialize('compiled_patchcore_kv260/PatchCoreKV260_int.xmodel'); print('XModel OK:', g.get_name()); print('Ops:', len(g.get_ops()))"
A successful graph load confirms that the XModel can be deserialized by XIR.
vai_c_xir \
-x compiled_patchcore_kv260/PatchCoreKV260_int.xmodel \
-a /opt/vitis_ai/compiler/arch/DPUCZDX8G/KV260/arch.json \
-o compiled_patchcore_kv260/compiled \
-n PatchCoreKV260
The compiled output is placed under:
compiled_patchcore_kv260/compiled
After completing both workflows, the directories should contain the generated INT8 XModels and compiler output.
compiled_padim_kv260/
├── PadimKV260_int.xmodel
└── compiled/
└── ...
compiled_patchcore_kv260/
├── PatchCoreKV260_int.xmodel
└── compiled/
└── ...
The exact files inside compiled/ can vary with the Vitis AI compiler output.
Use the two modes in this order:
calib → test → vai_c_xir
Do not skip calibration when generating a calibrated INT8 model.
Use representative normal/good images. Poor calibration data can reduce INT8 accuracy.
The compiler must use the architecture file for the target KV260 DPU:
/opt/vitis_ai/compiler/arch/DPUCZDX8G/KV260/arch.json
Do not use an architecture file for another DPU target.
The XModel workflow depends on Vitis AI tooling and is intended to run in the supported Linux/Vitis AI environment. Windows-only execution is not expected to provide the required Vitis AI compiler commands.
A successfully generated and compiled XModel does not by itself prove end-to-end KV260 application correctness. The final step is to deploy the compiled model on the KV260 and validate preprocessing, tensor layout, postprocessing, anomaly scores, and latency on the target hardware.
# Calibration
python quantize_padim_kv260.py \
--model distributions/padim/bottle/anomav_exp/model.pt \
--calibration-dir /workspace/dataset/bottle/train/good \
--output-dir compiled_padim_kv260 \
--quant_mode calib
# XModel generation
python quantize_padim_kv260.py \
--model distributions/padim/bottle/anomav_exp/model.pt \
--calibration-dir /workspace/dataset/bottle/train/good \
--output-dir compiled_padim_kv260 \
--quant_mode test
# KV260 compilation
vai_c_xir \
-x compiled_padim_kv260/PadimKV260_int.xmodel \
-a /opt/vitis_ai/compiler/arch/DPUCZDX8G/KV260/arch.json \
-o compiled_padim_kv260/compiled \
-n PadimKV260
# Calibration
python quantize_patchcore_kv260.py \
--model distributions/patchcore/bottle/anomav_exp/model.pt \
--calibration-dir /workspace/dataset/bottle/train/good \
--output-dir compiled_patchcore_kv260 \
--quant_mode calib
# XModel generation
python quantize_patchcore_kv260.py \
--model distributions/patchcore/bottle/anomav_exp/model.pt \
--calibration-dir /workspace/dataset/bottle/train/good \
--output-dir compiled_patchcore_kv260 \
--quant_mode test
# KV260 compilation
vai_c_xir \
-x compiled_patchcore_kv260/PatchCoreKV260_int.xmodel \
-a /opt/vitis_ai/compiler/arch/DPUCZDX8G/KV260/arch.json \
-o compiled_patchcore_kv260/compiled \
-n PatchCoreKV260
vai_c_xir: command not foundThe Vitis AI environment is probably not activated. Check:
conda activate vitis-ai-pytorch
vai_c_xir -h
arch.json not foundVerify the KV260 architecture path:
ls -lh /opt/vitis_ai/compiler/arch/DPUCZDX8G/KV260/arch.json
If the file is not present, use the architecture path provided by your Vitis AI installation, but make sure it corresponds to the KV260 DPU.
Check the script output and the contents of the selected output directory:
find compiled_padim_kv260 -maxdepth 2 -type f
or:
find compiled_patchcore_kv260 -maxdepth 2 -type f
Also confirm that the calibration phase completed successfully before running test mode.
Check that the XModel was generated by the Vitis AI tooling in the active environment and that xir is available:
python -c "import xir; print('XIR OK')"
Once vai_c_xir completes successfully, copy the compiled deployment artifacts to the KV260 application environment and run the corresponding AnomaVision inference pipeline.
For production deployment, validate the complete pipeline on the actual KV260 hardware rather than relying only on host-side XModel compilation.