Skip to content

Conversation

@khengari77
Copy link

Description

This PR implements high-level, safe Rust bindings for the OpenVINO model reshape functionality. Currently, the openvino crate lacks a way to reshape models after they are loaded, which is a prerequisite for use cases involving dynamic batching or variable image resolutions.

This contribution bridges the gap between the low-level openvino-sys FFI and the ergonomic openvino crate by adding five core reshape methods to the Model struct.

Related Issue

Closes #181

Changes

  • crates/openvino/src/model.rs:
    • Implemented reshape: Enables name-to-PartialShape mapping for multi-input models.
    • Implemented reshape_single_input: An ergonomic helper for the common single-input model use case.
    • Implemented reshape_input_by_name: Targets a specific input port by its name string.
    • Implemented reshape_by_port_indexes: Enables index-based reshaping.
    • Implemented reshape_by_ports: Enables Node/Port-based reshaping.
  • crates/openvino/src/partial_shape.rs:
    • Updated the visibility of c_struct to pub(crate). This allows the model module to pass the underlying ov_partial_shape_t to FFI calls while keeping it hidden from the end-user.
  • crates/openvino/src/node.rs:
    • Added a pub(crate) fn as_ptr() helper to expose the internal ov_output_const_port_t pointer required for ov_model_reshape_by_ports.
  • crates/openvino/tests/reshape.rs:
    • Added a new integration test suite using the alexnet fixture to verify that all five reshape variants correctly communicate with the OpenVINO C++ runtime and that model state updates correctly (including is_dynamic checks).

Testing and Compliance

  • All integration tests pass: cargo test -p openvino --test reshape
  • Code is formatted: cargo fmt --all

Implements five methods in the Model struct to enable model reshaping
after loading, which is required for dynamic batching and changing
input image resolutions.

Changes:
- Added Model::reshape, reshape_single_input, reshape_input_by_name,
  reshape_by_port_indexes, and reshape_by_ports.
- Updated PartialShape internals to pub(crate) to allow Model to
  access the underlying C struct for FFI calls.
- Added Node::as_ptr() helper to expose the internal port pointer.
- Added a new integration test suite (tests/reshape.rs) using the
  AlexNet fixture to verify the FFI bridge logic.

This bridges the gap between the low-level sys crate and the
ergonomic high-level API.

Signed-off-by: khengari77 <[email protected]>
Copy link

@AbdulmalikDS AbdulmalikDS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@alwalxed
Copy link

image Just merge it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Model Reshaping

3 participants