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

Openvino Chinese Path and Interface Support #24520

Open
1 task done
laogonggong847 opened this issue May 15, 2024 · 11 comments
Open
1 task done

Openvino Chinese Path and Interface Support #24520

laogonggong847 opened this issue May 15, 2024 · 11 comments
Assignees
Labels
enhancement New feature or request feature New feature request

Comments

@laogonggong847
Copy link

laogonggong847 commented May 15, 2024

Request Description

Thanks for the great convenience and progress brought by openvino, in the future I hope openvino can solve two new problems:

1: Using openvino in python doesn't seem to solve the problem of paths containing Chinese characters. In fact I have solved the problem of including Chinese paths in C++ with openvino. But when using openvino in python, I haven't come up with a good way to solve the Chinese characters caused.

import openvino as ov

if __name__ == "__main__":

    # onnx_path = r"H:\Path\my.onnx"     #  can
    onnx_path = r"H:\路径\my.onnx"        #  Error

    ov_model = ov.convert_model(onnx_path)

2: On another note, it seems to me that the current openvino interface for reading models is still not very flexible. Taking onnx as an example, I can read onnx model into memory and then pass the value from memory directly to "Ort::Session" for initialization. But when I look at the interface, it seems that openvino doesn't support me to pass both "xml" and "bin", which are processed and stored in memory, to the "ov::Core". " for initialization. Opening up or overloading similar interfaces would broaden the scenarios for using openvino.

Thank you very much for the great contribution made by openvino, for problem 1 do not know in addition to recompile whether there is a better way to solve the Chinese path error, very much look forward to your guidance, thank you very much!

Feature Use Case

No response

Issue submission checklist

  • The feature request or improvement must be related to OpenVINO

CVS-141444

@laogonggong847 laogonggong847 added enhancement New feature or request feature New feature request labels May 15, 2024
@ilya-lavrenov
Copy link
Contributor

ilya-lavrenov commented May 15, 2024

doesn't support me to pass both "xml" and "bin", which are processed and stored in memory, to the "ov::Core". " for initialization

/**
* @brief Reads models from IR / ONNX / PDPD / TF / TFLite formats.
* @param model String with a model in IR / ONNX / PDPD / TF / TFLite format.
* @param weights Shared pointer to a constant tensor with weights.
* Reading ONNX / PDPD / TF / TFLite models does not support loading weights from the @p weights tensors.
* @note Created model object shares the weights with the @p weights object.
* Thus, do not create @p weights on temporary data that can be freed later, since the model
* constant data will point to an invalid memory.
* @return A model.
*/
std::shared_ptr<ov::Model> read_model(const std::string& model, const Tensor& weights) const;

or directly to compile model w/o reading it first

/**
* @brief Reads a model and creates a compiled model from the IR/ONNX/PDPD memory.
* @param model String with a model in IR/ONNX/PDPD format.
* @param weights Shared pointer to a constant tensor with weights.
* Reading ONNX/PDPD models does not support loading weights from the @p weights tensors.
* @param device_name Name of a device to load a model to.
* @tparam Properties Should be a pack of `std::pair<std::string, ov::Any>` types.
* @note Created model object shares the weights with the @p weights object.
* Thus, do not create @p weights on temporary data that can be freed later, since the model
* constant data will point to an invalid memory.
* @return A compiled model.
*/
template <typename... Properties>
util::EnableIfAllStringAny<CompiledModel, Properties...> compile_model(const std::string& model,
const ov::Tensor& weights,
const std::string& device_name,
Properties&&... properties) {
return compile_model(model, weights, device_name, AnyMap{std::forward<Properties>(properties)...});
}

@andrei-kochin
Copy link
Contributor

@laogonggong847 Thank you for reaching the OpenVINO!

do you see the error like this?
[ ERROR ] Cannot recognize input model.

@laogonggong847
Copy link
Author

Hello @ilya-lavrenov
Thank you for your very professional and quick reply!
I apologize for not being clear on question 2.

Yes, about the interface you're talking about, I've noticed that before.

(std::shared_ptr<ov::Model> read_model(const std::string& model, const Tensor& weights) const;)

Passing ov::Model to ov::CompiledModel is undoubtedly fine, but for ov::Model I'm still passing in this path
Imagine an application scenario where I process "xml" and "bin" and some other information into a file in a new format. When I process this new file, I need to parse out the xml and bin, then localize and save them, and finally pass in at least the path to the "xml". But is it possible to provide an interface that allows me to initialize "ov::Core" by passing in the parsing result directly, instead of using the result that I save locally after parsing?
Thank you very much for your answer.

Thank you very much for your answers and I look forward to speaking with you further!

@laogonggong847
Copy link
Author

@laogonggong847 Thank you for reaching the OpenVINO!

do you see the error like this? [ ERROR ] Cannot recognize input model.

Hello @andrei-kochin
Thanks for your reply and many thanks for your great contribution to the openvino community!
Yes, that's my error message.
f55cbee920c379e29721e322969338d4
It seems that you have found this problem, please ask if there is a corresponding solution, looking forward to your reply, thank you very much!

@riverlijunjie
Copy link
Contributor

std::shared_ptrov::Model read_model(const std::string& model, const Tensor& weights) const;

This API uses xml content and bin data as its input arguments, it should can meet your requirement - parse out the xml and bin from the new format file and pass to ov::Model directly? Or correct me if I misunderstood your requirement.

@laogonggong847
Copy link
Author

std::shared_ptrov::Model read_model(const std::string& model, const Tensor& weights) const;

This API uses xml content and bin data as its input arguments, it should can meet your requirement - parse out the xml and bin from the new format file and pass to ov::Model directly? Or correct me if I misunderstood your requirement.

Thank you very much for your professional and patient reply, if this "const std::string& model" contains Chinese characters, what should be done? The main thing is that when I include Chinese paths in python, I get the error I mentioned before.
Thank you very much for your professional advice.

@riverlijunjie
Copy link
Contributor

std::shared_ptrov::Model read_model(const std::string& model, const Tensor& weights) const;

This API uses xml content and bin data as its input arguments, it should can meet your requirement - parse out the xml and bin from the new format file and pass to ov::Model directly? Or correct me if I misunderstood your requirement.

Thank you very much for your professional and patient reply, if this "const std::string& model" contains Chinese characters, what should be done? The main thing is that when I include Chinese paths in python, I get the error I mentioned before. Thank you very much for your professional advice.

Here const std::string& model is not a file path, but the actual xml content buffer.

@riverlijunjie
Copy link
Contributor

1: Using openvino in python doesn't seem to solve the problem of paths containing Chinese characters. In fact I have solved the problem of including Chinese paths in C++ with openvino. But when using openvino in python, I haven't come up with a good way to solve the Chinese characters caused.

Is it reproduced in Linux also?

@laogonggong847
Copy link
Author

1: Using openvino in python doesn't seem to solve the problem of paths containing Chinese characters. In fact I have solved the problem of including Chinese paths in C++ with openvino. But when using openvino in python, I haven't come up with a good way to solve the Chinese characters caused.

Is it reproduced in Linux also?

In fact I am having this problem when using python for model conversion in windows, because the saved path contains Chinese. But I haven't tested it in linux, so I can't be sure if the problem exists in linux as well!

Thank you for your reply, looking forward to your help, thank you very much!

import openvino as ov

if __name__ == "__main__":

    # onnx_path = r"H:\Path\my.onnx"     #  can
    onnx_path = r"H:\路径\my.onnx"        #  Error

    ov_model = ov.convert_model(onnx_path)

f55cbee920c379e29721e322969338d4

@andrei-kochin
Copy link
Contributor

andrei-kochin commented May 16, 2024

@riverlijunjie
No, issue is not visible on Linux

Please ignore the unrelated error as I had only faulty model for testing

>>> from openvino import convert_model
>>> convert_model("/home/andrei/привет/RandomUniformLike.onnx")
openvino._pyopenvino.GeneralFailure: Check 'false' failed at src/frontends/onnx/frontend/src/frontend.cpp:144:
FrontEnd API failed with GeneralFailure:
Errors during ONNX translation:
[ONNX Frontend] Conversion failed for RandomUniformLike-18
While validating ONNX node '<Node(RandomUniformLike): y>': Check 'validate::out_et(out_et) && (out_et == min_et)' failed at src/core/src/op/random_uniform.cpp:48:
While validating node 'opset8::RandomUniform RandomUniform_5 (opset3::ShapeOf ShapeOf_2[0]:i64[1], opset1::Constant Constant_4[0]:f32[], opset1::Constant Constant_3[0]:f32[]) -> (dynamic[...])' with friendly_name 'RandomUniform_5':
'min_val' and 'max_val' should have the same type as 'out_type' attribute.

ref: CVS-141444

@sammysun0711
Copy link
Collaborator

sammysun0711 commented May 17, 2024

@laogonggong847, it seems path with Chinese character encoding in python on windows failed to decode in UTF-8 Unicode: https://ofstack.com/python/20064/python-solves-the-problem-of-chinese-character-encoding:-unicode-decode-error.html

You may try out following quick workaround:

import openvino as ov
if __name__ == "__main__":
    # onnx_path = u"H:\Path\my.onnx".encode('utf-8')     #  can
    onnx_path = u"H:\路径\my.onnx".encode('utf-8')        #  can
    ov_model = ov.convert_model(onnx_path)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature New feature request
Projects
None yet
Development

No branches or pull requests

6 participants