Schritte zum Anwenden von Vorverarbeitungsschritten basierend auf modellspezifischen Transformationen, die in der Modellkonfiguration definiert sind.
- Konvertierte PyTorch-Modelle direkt über die Model Conversion API.
ov_model = convert_detectron2_model(model, image) - Unerwünschte Ergebnisse aus den konvertierten IR-Dateien (Intermediate Representation) erhalten.
Wenden Sie Vorverarbeitungsschritte auf der Grundlage modellspezifischer Transformationen an, die in der Modellkonfiguration definiert sind.
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)