Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Convertion to ONNX format #438

blackHorz started this conversation in General
Discussion options

Hi,
I found the implementation very efficient and strainght forward. However I would like to know if you can provide me hint for doing inference with OPENCV.
So I can convert the model to ONNX, however how should I handle the preprocessing function?
Any small code will suffice.
Thanks

You must be logged in to vote

Replies: 1 comment

Comment options

You can embed preprocessing function into your model and then convert to ONNX

class InferenceModel(torch.nn.Module):
    def __init__(self, my_model, mean, std):
        super().__init__()
        self.my_model = my_model
        self.register_buffer("mean", mean)
        self.register_buffer("std", std)
    
    def forward(self, x):
        x = x - self.mean
        x = x / self.std
        x = self.my_model(x)
        return x
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.