Skip To Main Content
Support Knowledge Base

Encountered Accuracy Issue While Inferencing XFeat* Model with OpenVINO™ 2024.6

Content Type: Troubleshooting   |   Article ID: 000102315   |   Last Reviewed: 02/18/2026

Description

  • Converted custom XFeat ONNX model to OpenVINO™ Intermediate Representation (IR)
  • Accuracy loss while running XFeat IR model with OpenVINO™ 2024.6

Resolution

XFeat.NMS function in XFeat model has a for loop that depends on the input data, and it cannot be captured correctly during export to ONNX format.

  1. Upgrade OpenVINO™ version to 2025.3 and above
  2. Rewrite XFeat.NMS function to avoid using the for loop for dynamic data:
    model.forward = model.detectAndCompute
       
        def NMS_no_loop(x, threshold=0.05, kernel_size=5):
            B, _, H, W = x.shape
            pad = kernel_size // 2
       
            local_max = torch.nn.functional.max_pool2d(x, kernel_size=kernel_size, stride=1, padding=pad)   
            pos = (x == local_max) & (x > threshold)   
            pos_indices = pos.nonzero(as_tuple=False)   
            batch_indices = pos_indices[:, 0]
            spatial_positions = pos_indices[:, 2:].flip(-1)   
            unique_batches, counts = torch.unique(batch_indices, return_counts=True)
            pad_val = counts.max().item()   
            pos_tensor = torch.zeros((B, pad_val, 2), dtype=torch.long, device=x.device)
       
            for b in unique_batches:
                batch_mask = batch_indices == b
                pos_tensor[b, :batch_mask.sum(), :] = spatial_positions[batch_mask]
       
            return pos_tensor
       
        model.NMS = NMS_no_loop
     
        ovm = ov.convert_model(model, example_input=(torch.randn(1,3,800,800),), verbose=True)
    

Related Products

This article applies to 1 products.