Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PyOV] Add torchvision to OpenVINO preprocessing converter #17934

Merged
merged 146 commits into from
Aug 2, 2023

Conversation

p-wysocki
Copy link
Contributor

@p-wysocki p-wysocki commented Jun 7, 2023

Details:

  • Tools for converting a torchvision.transforms object into OpenVINO preprocessing

  • Based on @AlexKoff88's POC

  • List of supported torchvision transforms:

    • Compose
    • ToTensor
    • ConvertImageDtype
    • Normalize
    • Resize
    • CenterCrop
    • Pad
    • Grayscale
  • Bindings for PILLOW interpolation modes

  • Example use case:

preprocess_pipeline = torchvision.transforms.Compose(
    [
        torchvision.transforms.Resize(256, interpolation=transforms.InterpolationMode.NEAREST),
        torchvision.transforms.CenterCrop((216, 218)),
        torchvision.transforms.Pad((2, 3, 4, 5), fill=3),
        torchvision.transforms.ToTensor(),
        torchvision.transforms.ConvertImageDtype(torch.float32),
        torchvision.transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
    ]
)

torch_model = SimpleConvnet(input_channels=3)

torch.onnx.export(torch_model, torch.randn(1, 3, 224, 224), "test_convnet.onnx", verbose=False, input_names=["input"], output_names=["output"])
core = Core()
ov_model = core.read_model(model="test_convnet.onnx")

test_input = np.random.randint(255, size=(260, 260, 3), dtype=np.uint16)
ov_model = PreprocessConverter.from_torchvision(
    model=ov_model, transform=preprocess_pipeline, input_example=Image.fromarray(test_input.astype("uint8"), "RGB")
)
ov_model = core.compile_model(ov_model, "CPU")
ov_input = np.expand_dims(test_input, axis=0)
output = ov_model.output(0)
ov_result = ov_model(ov_input)[output]

Tickets:

  • 111306, 90100

TODO

@p-wysocki p-wysocki requested review from a team as code owners June 7, 2023 13:36
@github-actions github-actions bot added category: dependency_changes Pull requests that update a dependency file category: Python API OpenVINO Python bindings labels Jun 7, 2023

from openvino.preprocess.torchvision_to_ov import PreprocessConverter


Copy link
Member

@rkazants rkazants Jun 7, 2023

Choose a reason for hiding this comment

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

Also, I think it makes sense to add it into PyTorch layer tests scope

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests do not match the definition of layer tests. If there's a better place we can put preprocessing tests I'll move them somewhere else, but I don't think they belong to openvino/tests/layer_tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem we have here is that different categories of tests (read as "folder with python code") require the same frameworks.
And it results to the fact we have requirements files, where we have a lot of frameworks like ONNX and PT. We already have a ticket (and PR) to move ONNX tests from python folder to folder closer to ONNX FE. Similar with PR tests - what are we testing here? Python API ? or integration with PT? I suppose the later one, so here I aligned with @rkazants that such tests are closer to PT tests, which allows to group tests by frameworks:

  • (No frameworks) - OpenVINO Python API, which does not require heavy dependencies
  • (PT) - PT Layer tests, PT decoder, preprocessing tests
  • (ONNX) - ONNX tests
  • ...

Alternatively, we need to create tox.ini files where developers can test only Python API or only PT preprocessing or only interaction of ONNX and OpenVINO. Currently, we have a mix of everything in one place - OpenVINO Python API, ONNX tests and newly introduced PT preprocessing, also we have different decoders in openvino.frontends package. And it's hard to test everything together.

@ilya-lavrenov ilya-lavrenov requested a review from AlexKoff88 July 24, 2023 12:57
Copy link

@jiwaszki jiwaszki left a comment

Choose a reason for hiding this comment

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

One remark.

.ci/openvino-onnx/Dockerfile Show resolved Hide resolved
@ilya-lavrenov ilya-lavrenov merged commit 62fa09a into openvinotoolkit:master Aug 2, 2023
@p-wysocki p-wysocki deleted the torchvision branch August 2, 2023 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: build OpenVINO cmake script / infra category: CI OpenVINO public CI category: dependency_changes Pull requests that update a dependency file category: Python API OpenVINO Python bindings Feature Freeze Label to highlight PR for Feature Freeze no_stale Do not mark as stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants