Skip to content

feat: add model reshape support to high-level API#182

Merged
rahulchaphalkar merged 2 commits intointel:mainfrom
khengari77:feat/model-reshape
Jan 8, 2026
Merged

feat: add model reshape support to high-level API#182
rahulchaphalkar merged 2 commits intointel:mainfrom
khengari77:feat/model-reshape

Conversation

@khengari77
Copy link
Contributor

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

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

@rahulchaphalkar rahulchaphalkar self-requested a review January 5, 2026 21:43
@rahulchaphalkar
Copy link
Contributor

Thanks for the PR and a review! I will take a look at this soon, took a while to see this as I'm just returning from a year end break.

Copy link
Contributor

@rahulchaphalkar rahulchaphalkar left a comment

Choose a reason for hiding this comment

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

Looks good, a minor change requested and seems good to go after that. Thanks.

@rahulchaphalkar
Copy link
Contributor

Can you rebase main, I have updated the workflow file to fix the failure, it should pass now.
#183

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 <khengari77@gmail.com>
Signed-off-by: khengari77 <khengari77@gmail.com>
Copy link
Contributor

@rahulchaphalkar rahulchaphalkar left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the contribution

@rahulchaphalkar rahulchaphalkar merged commit 3ee9732 into intel:main Jan 8, 2026
14 checks passed
@khengari77 khengari77 deleted the feat/model-reshape branch January 8, 2026 20:41
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

4 participants