Skip To Main Content
Support Knowledge Base

Unable to Obtain Expected Results from the Converted Intermediate Representation (IR) Model

Content Type: Troubleshooting   |   Article ID: 000099197   |   Last Reviewed: 07/09/2024

Description

  • Converted PyTorch models directly via Model Conversion API.
    ov_model = convert_detectron2_model(model, image)
  • Obtained undesired results from the converted Intermediate Representation (IR) files.

Resolution

Apply preprocessing steps based on model-specific transformations defined in the model config.

import detectron2.data.transforms as T
from detectron2.data import detection_utils

image_file = "example_image.jpg"

def get_sample_inputs(image_path, cfg):


# get a sample data
original_image = detection_utils.read_image(image_path, format=cfg.INPUT.FORMAT)
# Do same preprocessing as DefaultPredictor
aug = T.ResizeShortestEdge([cfg.INPUT.MIN_SIZE_TEST, cfg.INPUT.MIN_SIZE_TEST], cfg.INPUT.MAX_SIZE_TEST)
height, width = original_image.shape[:2]
image = aug.get_transform(original_image).apply_image(original_image)
image = torch.as_tensor(image.astype("float32").transpose(2, 0, 1))

inputs = {"image": image, "height": height, "width": width}

# Sample ready
sample_inputs = [inputs]
return sample_inputs

sample_input = get_sample_inputs(image_file, cfg)
ov_model = convert_detectron2_model(model, sample_input)

Related Products

This article applies to 1 products.