openvinotoolkit / openvino

OpenVINO™ is an open-source toolkit for optimizing and deploying AI inference
https://docs.openvino.ai
Apache License 2.0
7.01k stars 2.21k forks source link

Openvino Chinese Path and Interface Support #24520

Closed laogonggong847 closed 2 months ago

laogonggong847 commented 4 months ago

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

CVS-141444

ilya-lavrenov commented 4 months ago

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

https://github.com/openvinotoolkit/openvino/blob/6950460b3427210d6cce940f6a6fcc8732308253/src/inference/include/openvino/runtime/core.hpp#L101-L111

or directly to compile model w/o reading it first https://github.com/openvinotoolkit/openvino/blob/6950460b3427210d6cce940f6a6fcc8732308253/src/inference/include/openvino/runtime/core.hpp#L310-L328

andrei-kochin commented 4 months ago

@laogonggong847 Thank you for reaching the OpenVINO!

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

laogonggong847 commented 4 months ago

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 commented 4 months ago

@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 commented 4 months ago

std::shared_ptr 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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

@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 commented 4 months ago

@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)
laogonggong847 commented 4 months ago

@laogonggong847,看来 windows 上 python 中中文字符编码的路径无法以 UTF-8 Unicode 解码:https://ofstack.com/python/20064/python-solves-the-problem-of-chinese-character-encoding :-unicode-decode-error.html

您可以尝试以下快速解决方法:

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)

hello @sammysun0711 I am very sorry it took me so long to see this message you replied to. I just couldn't wait to test it. But I found that there are still problems, the specific error is as follows, I am windows, may I ask your test environment is Linux? If windows I want it to be able to recognize Chinese characters correctly then what changes should I make. I look forward to your reply, thank you very much!

3988008e3710b0fdc9af57534dfc22f6

peterchen-intel commented 4 months ago

https://github.com/openvinotoolkit/openvino/pull/24606 @laogonggong847 Can you please check if the issue is fixed?

sammysun0711 commented 4 months ago

I checked following code works on windows 11 system with OpenVINO 24.1 and https://github.com/openvinotoolkit/openvino/pull/24606

if __name__ == "__main__":
    print("OpenVINO version: ", ov.get_version())
    onnx_path = "C:\\路径\\my.onnx"
    print("onnx_path: ", onnx_path)
    ov_model = ov.convert_model(onnx_path)
    print("convert model passed!")

Beside, I change language settings on windows: Time & Language -> Language & region -> Administrative language settings -> Change system locale -> Choose Beta: Use Unicode UTF-8 for worldwide language support -> Reboot

windows_chage_locale
laogonggong847 commented 4 months ago

Hello @sammysun0711

Thank you very much for pointing out the specific steps to solve the problem in such a detailed manner, this method can indeed solve the error brought about by the inclusion of Chinese in the path. However, this method seems to be not flexible enough, so I tried not to change this configuration, and just add the following code in my code # -*- coding: UTF-8 -*- does not seem to work. Is there a better way to accomplish this without changing this configuration, because I am afraid that this change will have some unknown effects on my other projects.

laogonggong847 commented 4 months ago

24606 @laogonggong847 Can you please check if the issue is fixed?

hello @peterchen-intel : Thank you very much for your reply, actually when using openvino in C++, I have been able to use it properly by converting the characters of the Chinese path to wstring. However, on windows, when I use python to read and save the model with Chinese paths, I get a series of errors

andrei-kochin commented 3 months ago

@laogonggong847 issue is fixed in the #24801

Could you please check that it works fine with python scenario as well?

andrei-kochin commented 2 months ago

@laogonggong847 any updates for us here?