ขั้นตอนในการใช้ขั้นตอนการประมวลผลล่วงหน้าตามการเปลี่ยนแปลงเฉพาะโมเดลที่กําหนดไว้ในการกําหนดค่าโมเดล
- โมเดล PyTorch ที่แปลงโดยตรงผ่าน Model Conversion API
ov_model = convert_detectron2_model(model, image) - ได้รับผลลัพธ์ที่ไม่ต้องการจากไฟล์ Intermediate Representation (IR) ที่แปลงแล้ว
ใช้ขั้นตอนการประมวลผลล่วงหน้าตามการเปลี่ยนแปลงเฉพาะแบบจําลองที่กําหนดไว้ในการกําหนดค่าโมเดล
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)