-
Notifications
You must be signed in to change notification settings - Fork 60
tools for model exporting and converting #639
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
Conversation
ca54557
to
1c82279
Compare
tools/data_for_export_convert.py
Outdated
"infer_shape_list": ["1,3,736,1280", "1,3,704,1211"], | ||
"var": "args0", | ||
}, | ||
# "dbnet_resnet50_ch_en": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处注释是存在bug不支持吗?是否需要加TODO信息说明一下缘由?
tools/data_for_export_convert.py
Outdated
"infer_shape_list": ["1,3,1152,2048", "1,3,1120,2080"], | ||
"var": "args0", | ||
}, | ||
# "dbnetpp_resnet50_ch_en": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处注释是存在bug不支持吗?是否需要加TODO信息说明一下缘由?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处由于缺少dbnetpp_resnet50_ch_en
和dbnet_resnet50_ch_en
的ckpt自动下载。疑似dbnet_resnet50
和dbnetpp_resnet50
错写为dbnet_resnet50_ch_en
和dbnetpp_resnet50_ch_en
的ckpt下载路径。请查看该PR中mindocr/models/det_dbnet.py
的修改。修改之后该注释取消。
tests/test_export_convert.py
Outdated
|
||
if __name__ == "__main__": | ||
# not support export on Ascend 310P | ||
# test_export_static_model(output_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处为何大部分都要注释掉:
- 如依赖硬件,可考虑用npu-smi info判断本地ascend设备型号后,执行对应用例;
- 或者用注释说明,用户应选用哪些用例。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
新建完文件夹了以后最好删掉,可以参照下面的代码写个装饰器:
def vfl_data_test(func): @wraps(func) def wrap_test(*args, **kwargs): try: stop_fl_process() clean_fl_temp_files() mkdir("temp") mkdir("temp/leader") mkdir("temp/follower") generate_random_data() func(*args, **kwargs) except Exception: logger.error("VFL data test catch exception") raise finally: logger.info("VFl data test begin to clear") stop_fl_process() clean_fl_temp_files() logger.info("VFl data test end clear") return wrap_test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不知道咋调github缩进,参照下面那个链接吧
https://gitee.com/mindspore/federated/blob/master/tests/ut/python/tests/common.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI的启停机制是怎么样的,代码涉及网络和多进程,最好加上超时报错和退出时清空进程
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI的启停机制是怎么样的,代码涉及网络和多进程,最好加上超时报错和退出时清空进程
CI中执行tests/ut
和tests/st
中的用例,并不会执行该文件
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
非CI可以不用加超时报错或者退出清空,忽略我上面的那些评论
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不涉及CI
tests/test_export_convert.py
Outdated
def test_convert_static_model_from_download_mindir(output_path): | ||
convert_tool = "converter_lite" | ||
benchmark_tool = "benchmark" | ||
save_path = f"{output_path}/convert_static_from_download" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
构造路径时,需要考虑OS差异,建议使用:
file_path = os.getcwd() + os.sep + file_name
file_path = os.path.join(os.getcwd(), file_name)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
tools/export_convert_tool.py
Outdated
|
||
|
||
if __name__ == "__main__": | ||
output_path = "./output" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否需要判断路径是否存在,然后尝试新建文件夹?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已更新为parser传入,并加入路径判断,与是否文件覆盖选项
tests/test_export_convert.py
Outdated
from tools.export_convert_tool import ExportDynamicModel # noqa | ||
from tools.export_convert_tool import ExportStaticModel # noqa | ||
|
||
output_path = "./output" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否需要判断路径是否存在,然后尝试新建文件夹?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已更新为parser传入,并加入路径判断,与是否文件覆盖选项
tests/test_export_convert.py
Outdated
|
||
if __name__ == "__main__": | ||
# not support export on Ascend 310P | ||
# test_export_static_model(output_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
新建完文件夹了以后最好删掉,可以参照下面的代码写个装饰器:
def vfl_data_test(func): @wraps(func) def wrap_test(*args, **kwargs): try: stop_fl_process() clean_fl_temp_files() mkdir("temp") mkdir("temp/leader") mkdir("temp/follower") generate_random_data() func(*args, **kwargs) except Exception: logger.error("VFL data test catch exception") raise finally: logger.info("VFl data test begin to clear") stop_fl_process() clean_fl_temp_files() logger.info("VFl data test end clear") return wrap_test
tests/test_export_convert.py
Outdated
|
||
if __name__ == "__main__": | ||
# not support export on Ascend 310P | ||
# test_export_static_model(output_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不知道咋调github缩进,参照下面那个链接吧
https://gitee.com/mindspore/federated/blob/master/tests/ut/python/tests/common.py
tests/test_export_convert.py
Outdated
|
||
if __name__ == "__main__": | ||
# not support export on Ascend 310P | ||
# test_export_static_model(output_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI的启停机制是怎么样的,代码涉及网络和多进程,最好加上超时报错和退出时清空进程
tools/export_convert_tool.py
Outdated
convert_tool = "converter_lite" # path to converter_lite | ||
benchmark_tool = "benchmark" # path to benchmark | ||
save_path = f"{output_path}/convert_static_from_exported" # path to save converted static model | ||
exported_path = "path/to/exported/path" # path to exported model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported_path是不是没用到
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已更新
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不涉及CI
tools/export_convert_tool.py
Outdated
convert_tool = "converter_lite" # path to converter_lite | ||
benchmark_tool = "benchmark" # path to benchmark | ||
save_path = f"{output_path}/convert_dynamic_from_exported" # path to save converted dynamic model | ||
exported_path = "path/to/exported/path" # path to exported model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported_path是不是没用到
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已更新
self.log_handle.write(f"Export Success: {exported_model_path}") | ||
return True | ||
else: | ||
print("\033[31mExport Failed \033[0m") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
日志中添加失败原因
|
||
subprocess.call(f"echo Export Command: {command}".split(), stdout=self.log_handle, stderr=self.log_handle) | ||
print(f"\033[34mExport Command\033[0m: {command}") | ||
subprocess.call(command.split(), stdout=self.log_handle, stderr=self.log_handle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这种方式启动好像是非阻塞的?最好加个锁,然后校验下导出文件
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
非CI可以不用加,忽略我上面的评论
tests/test_export_convert.py
Outdated
|
||
if __name__ == "__main__": | ||
# not support export on Ascend 310P | ||
# test_export_static_model(output_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
非CI可以不用加超时报错或者退出清空,忽略我上面的那些评论
|
||
subprocess.call(f"echo Export Command: {command}".split(), stdout=self.log_handle, stderr=self.log_handle) | ||
print(f"\033[34mExport Command\033[0m: {command}") | ||
subprocess.call(command.split(), stdout=self.log_handle, stderr=self.log_handle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
非CI可以不用加,忽略我上面的评论
633c97d
to
6e2f016
Compare
482ce08
to
20e09ad
Compare
9d0996e
to
770473d
Compare
Thank you for your contribution to the MindOCR repo.
Before submitting this PR, please make sure:
Motivation
提供原生模型转换工具,用户终于可以无痛转模型了。支持以下功能
export
,convert
,export+convert
使用例子:
指定模型,运行后输出操作指令与报告
例1:运行export,得到如下指令和报告
例2:运行convert,得到如下指令和报告
例3:运行export_convert,全量动态转换,得到如下指令和报告