From 0b9f1f4bc5be08a181a3e2b34e0ef24111b89a25 Mon Sep 17 00:00:00 2001 From: igkonov Date: Thu, 21 Nov 2024 17:03:49 +0300 Subject: [PATCH 01/13] init --- src/model_converters/x2paddle/README.md | 58 +++++++++++++ src/model_converters/x2paddle/converter.py | 87 ++++++++++++++++++++ src/model_converters/x2paddle/paddle2onnx.py | 63 ++++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 src/model_converters/x2paddle/README.md create mode 100644 src/model_converters/x2paddle/converter.py create mode 100644 src/model_converters/x2paddle/paddle2onnx.py diff --git a/src/model_converters/x2paddle/README.md b/src/model_converters/x2paddle/README.md new file mode 100644 index 000000000..c2a50d0d3 --- /dev/null +++ b/src/model_converters/x2paddle/README.md @@ -0,0 +1,58 @@ +# Conversion to PaddlePaddle + +PaddlePaddle converter supports conversion to Paddle format from Pytorch and ONNX formats. + +## PaddlePaddle converter usage + +Usage of the script: + +```sh +python converter.py -m -f -p -d +``` + +This will convert model from `` to Paddle format. + +### Paddle converter parameters + +- `--model_path` Path to an .onnx or .pth file with the original model. +- `--framework` is a source framework for convertion to PaddlePaddle format. +- `--pytorch_module_name` Module name for PyTorch model (necessary if source framework is Pytorch). +- `--save_dir` Directory for converted model to be saved to. + +### Examples of usage + +```sh +python converter.py -m .\public\googlenet-v3-pytorch\inception_v3_google-1a9a5a14.pth -f pytorch -p InceptionV3 -d pd +``` + +```sh +python converter.py -m .\public\ctdet_coco_dlav0_512\ctdet_coco_dlav0_512.onnx -f onnx -d pd +``` + +# Conversion from PaddlePaddle + +paddle2onnx converter supports conversion to ONNX format from Paddle format. + +## PaddlePaddle converter usage + +Usage of the script: + +```sh +python paddle2onnx.py -d .\pd_pth\inference_model -f model.pdmodel -p model.pdiparams -m inference.onnx -o 11 +``` + +This will convert model from Paddle to ONNX format. + +### Converter parameters + +- `--model_dir` Path to the directory with the original model. +- `--model_filename` Name of the model file name. +- `--params_filename` Name of the parameters file name. +- `--model_path` Path to the resulting .onnx file. +- `--opset_version` Desired opset version of the resulting ONNX model. + +### Examples of usage + +```sh +python paddle2onnx.py -d .\pd_pth\inference_model -f model.pdmodel -p model.pdiparams -m inference.onnx -o 11 +``` diff --git a/src/model_converters/x2paddle/converter.py b/src/model_converters/x2paddle/converter.py new file mode 100644 index 000000000..c07693dc4 --- /dev/null +++ b/src/model_converters/x2paddle/converter.py @@ -0,0 +1,87 @@ +import torch +import numpy as np +from torchvision.models import * +from x2paddle.convert import pytorch2paddle +import argparse +import logging as log +import sys +from pathlib import Path +import os + +sys.path.append(str(Path(__file__).parent.parent.parent.parent)) + + +def cli_argument_parser(): + parser = argparse.ArgumentParser() + + parser.add_argument('-m', '--model_path', + help='Path to an .onnx or .pth file.', + required=True, + type=str, + dest='model_path') + parser.add_argument('-f', '--framework', + help='Original model framework (ONNX or Pytorch)', + required=True, + type=str, + choices=['onnx', 'pytorch'], + dest='framework') + parser.add_argument('-p', '--pytorch_module_name', + help='Module name for PyTorch model.', + required=False, + type=str, + choices=['AlexNet', 'VGG', 'ResNet', 'SqueezeNet', 'DenseNet', 'InceptionV3', 'GoogLeNet', + 'ShuffleNetV2', 'MobileNetV2', 'MobileNetV3', 'MNASNet'], + dest='module_name') + parser.add_argument('-d', '--save_dir', + help='Directory for converted model to be saved to.', + required=True, + type=str, + dest='save_dir') + args = parser.parse_args() + + return args + +def convert_pytorch_to_paddle(model_path: str, module_name, save_dir: str): + + modules = {'AlexNet': AlexNet, + 'VGG': VGG, + 'ResNet': ResNet, + 'SqueezeNet': SqueezeNet, + 'DenseNet': DenseNet, + 'InceptionV3': Inception3, + 'GoogLeNet': GoogLeNet, + 'ShuffleNetV2': ShuffleNetV2, + 'MobileNetV2': MobileNetV2, + 'MobileNetV3': MobileNetV3, + 'MNASNet': MNASNet} + + torch_module = modules[module_name]() + torch_module.load_state_dict(torch.load(model_path)) + torch_module.eval() + + input_data = np.random.rand(1, 3, 224, 224).astype("float32") + pytorch2paddle(torch_module, + save_dir=save_dir, + jit_type="trace", + input_examples=[torch.tensor(input_data)]) + +def convert_onnx_to_paddle(model_path: str, save_dir: str): + print(f'x2paddle --framework=onnx --model={model_path} --save_dir={save_dir}') + os.system(f'x2paddle --framework=onnx --model={model_path} --save_dir={save_dir}') + + +def main(): + log.basicConfig(format='[ %(levelname)s ] %(message)s', + level=log.INFO, stream=sys.stdout) + args = cli_argument_parser() + if args.framework == 'pytorch' and not args.module_name: + raise ValueError('Module name for pytorch is not specified') + elif args.framework == 'pytorch' and args.module_name: + convert_pytorch_to_paddle(model_path=args.model_path, + module_name=args.module_name, save_dir=args.save_dir) + elif args.framework == 'onnx': + convert_onnx_to_paddle(model_path=args.model_path, save_dir=args.save_dir) + + +if __name__ == '__main__': + main() diff --git a/src/model_converters/x2paddle/paddle2onnx.py b/src/model_converters/x2paddle/paddle2onnx.py new file mode 100644 index 000000000..ceed1139d --- /dev/null +++ b/src/model_converters/x2paddle/paddle2onnx.py @@ -0,0 +1,63 @@ +import argparse +import logging as log +import sys +from pathlib import Path +import os + +sys.path.append(str(Path(__file__).parent.parent.parent.parent)) + + +def cli_argument_parser(): + parser = argparse.ArgumentParser() + + parser.add_argument('-d', '--model_dir', + help='Directory to save model in.', + required=True, + type=str, + dest='model_dir') + parser.add_argument('-f', '--model_filename', + help='Name of the model file name.', + required=True, + type=str, + dest='model_filename') + parser.add_argument('-p', '--params_filename', + help='Name of the parameters file name.', + required=True, + type=str, + dest='params_filename') + parser.add_argument('-m', '--model_path', + help='Path to an .onnx file.', + required=True, + type=str, + dest='model_path') + parser.add_argument('-o', '--opset_version', + help='', + required=True, + type=str, + dest='opset_version') + args = parser.parse_args() + + return args + + +def convert_paddle_to_onnx(model_dir: str, model_filename: str, params_filename: str, + model_path: str, opset_version: str): + os.system(f'paddle2onnx --model_dir {model_dir} \ + --model_filename {model_filename} \ + --params_filename {params_filename} \ + --save_file {model_path} \ + --opset_version {opset_version} \ + --enable_onnx_checker True') + + +def main(): + log.basicConfig(format='[ %(levelname)s ] %(message)s', + level=log.INFO, stream=sys.stdout) + args = cli_argument_parser() + convert_paddle_to_onnx(model_dir=args.model_dir, model_filename=args.model_filename, + params_filename=args.params_filename, model_path=args.model_path, + opset_version=args.opset_version) + + +if __name__ == '__main__': + main() From 33770be483f9e7fdf74945ab013a4ee234f9bbbc Mon Sep 17 00:00:00 2001 From: igkonov Date: Thu, 28 Nov 2024 14:54:58 +0300 Subject: [PATCH 02/13] style fix --- src/model_converters/x2paddle/converter.py | 9 ++++++--- src/model_converters/x2paddle/paddle2onnx.py | 11 +++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/model_converters/x2paddle/converter.py b/src/model_converters/x2paddle/converter.py index c07693dc4..41e52e7a9 100644 --- a/src/model_converters/x2paddle/converter.py +++ b/src/model_converters/x2paddle/converter.py @@ -1,6 +1,7 @@ import torch import numpy as np -from torchvision.models import * +from torchvision.models import (AlexNet, VGG, ResNet, SqueezeNet, DenseNet, + Inception3, GoogLeNet, ShuffleNetV2, MobileNetV2, MobileNetV3, MNASNet) from x2paddle.convert import pytorch2paddle import argparse import logging as log @@ -41,6 +42,7 @@ def cli_argument_parser(): return args + def convert_pytorch_to_paddle(model_path: str, module_name, save_dir: str): modules = {'AlexNet': AlexNet, @@ -59,12 +61,13 @@ def convert_pytorch_to_paddle(model_path: str, module_name, save_dir: str): torch_module.load_state_dict(torch.load(model_path)) torch_module.eval() - input_data = np.random.rand(1, 3, 224, 224).astype("float32") + input_data = np.random.rand(1, 3, 224, 224).astype('float32') pytorch2paddle(torch_module, save_dir=save_dir, - jit_type="trace", + jit_type='trace', input_examples=[torch.tensor(input_data)]) + def convert_onnx_to_paddle(model_path: str, save_dir: str): print(f'x2paddle --framework=onnx --model={model_path} --save_dir={save_dir}') os.system(f'x2paddle --framework=onnx --model={model_path} --save_dir={save_dir}') diff --git a/src/model_converters/x2paddle/paddle2onnx.py b/src/model_converters/x2paddle/paddle2onnx.py index ceed1139d..8fe39237c 100644 --- a/src/model_converters/x2paddle/paddle2onnx.py +++ b/src/model_converters/x2paddle/paddle2onnx.py @@ -42,12 +42,11 @@ def cli_argument_parser(): def convert_paddle_to_onnx(model_dir: str, model_filename: str, params_filename: str, model_path: str, opset_version: str): - os.system(f'paddle2onnx --model_dir {model_dir} \ - --model_filename {model_filename} \ - --params_filename {params_filename} \ - --save_file {model_path} \ - --opset_version {opset_version} \ - --enable_onnx_checker True') + os.system(f'''paddle2onnx --model_dir {model_dir} --model_filename {model_filename} + --params_filename {params_filename} + --save_file {model_path} + --opset_version {opset_version} + --enable_onnx_checker True''') def main(): From cd95f2aa1bbdb188b225f7795308c055b9d1be3d Mon Sep 17 00:00:00 2001 From: igkonov Date: Thu, 28 Nov 2024 14:58:41 +0300 Subject: [PATCH 03/13] style fix 2 --- src/model_converters/x2paddle/paddle2onnx.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/model_converters/x2paddle/paddle2onnx.py b/src/model_converters/x2paddle/paddle2onnx.py index 8fe39237c..043ff421c 100644 --- a/src/model_converters/x2paddle/paddle2onnx.py +++ b/src/model_converters/x2paddle/paddle2onnx.py @@ -42,11 +42,11 @@ def cli_argument_parser(): def convert_paddle_to_onnx(model_dir: str, model_filename: str, params_filename: str, model_path: str, opset_version: str): - os.system(f'''paddle2onnx --model_dir {model_dir} --model_filename {model_filename} - --params_filename {params_filename} - --save_file {model_path} - --opset_version {opset_version} - --enable_onnx_checker True''') + os.system(f"""paddle2onnx --model_dir {model_dir} --model_filename {model_filename} + --params_filename {params_filename} + --save_file {model_path} + --opset_version {opset_version} + --enable_onnx_checker True""") def main(): From 13c9a95957092c49e24d86435c1d220d517c294f Mon Sep 17 00:00:00 2001 From: igkonov Date: Thu, 28 Nov 2024 15:20:59 +0300 Subject: [PATCH 04/13] required tools + style fix 3 --- .../{x2paddle => paddle_covnerter}/README.md | 20 +++++++++---------- .../converter.py | 0 .../paddle2onnx.py | 2 +- .../paddle_covnerter/requirements.txt | 2 ++ 4 files changed, 13 insertions(+), 11 deletions(-) rename src/model_converters/{x2paddle => paddle_covnerter}/README.md (62%) rename src/model_converters/{x2paddle => paddle_covnerter}/converter.py (100%) rename src/model_converters/{x2paddle => paddle_covnerter}/paddle2onnx.py (98%) create mode 100644 src/model_converters/paddle_covnerter/requirements.txt diff --git a/src/model_converters/x2paddle/README.md b/src/model_converters/paddle_covnerter/README.md similarity index 62% rename from src/model_converters/x2paddle/README.md rename to src/model_converters/paddle_covnerter/README.md index c2a50d0d3..f528ff1aa 100644 --- a/src/model_converters/x2paddle/README.md +++ b/src/model_converters/paddle_covnerter/README.md @@ -7,17 +7,17 @@ PaddlePaddle converter supports conversion to Paddle format from Pytorch and ONN Usage of the script: ```sh -python converter.py -m -f -p -d +python converter.py -m -f -p -d ``` This will convert model from `` to Paddle format. ### Paddle converter parameters -- `--model_path` Path to an .onnx or .pth file with the original model. +- `--model_path` is a path to an .onnx or .pth file with the original model. - `--framework` is a source framework for convertion to PaddlePaddle format. -- `--pytorch_module_name` Module name for PyTorch model (necessary if source framework is Pytorch). -- `--save_dir` Directory for converted model to be saved to. +- `--pytorch_module_name` is a module name for PyTorch model (necessary if source framework is Pytorch). +- `--save_dir` is a directory for converted model to be saved to. ### Examples of usage @@ -41,15 +41,15 @@ Usage of the script: python paddle2onnx.py -d .\pd_pth\inference_model -f model.pdmodel -p model.pdiparams -m inference.onnx -o 11 ``` -This will convert model from Paddle to ONNX format. +This script will convert model from Paddle to ONNX format. ### Converter parameters -- `--model_dir` Path to the directory with the original model. -- `--model_filename` Name of the model file name. -- `--params_filename` Name of the parameters file name. -- `--model_path` Path to the resulting .onnx file. -- `--opset_version` Desired opset version of the resulting ONNX model. +- `--model_dir` is a path to the directory with the original model. +- `--model_filename` is a name of the model file name. +- `--params_filename` is a name of the parameters file name. +- `--model_path` is a path to the resulting .onnx file. +- `--opset_version` is a desired opset version of the resulting ONNX model. ### Examples of usage diff --git a/src/model_converters/x2paddle/converter.py b/src/model_converters/paddle_covnerter/converter.py similarity index 100% rename from src/model_converters/x2paddle/converter.py rename to src/model_converters/paddle_covnerter/converter.py diff --git a/src/model_converters/x2paddle/paddle2onnx.py b/src/model_converters/paddle_covnerter/paddle2onnx.py similarity index 98% rename from src/model_converters/x2paddle/paddle2onnx.py rename to src/model_converters/paddle_covnerter/paddle2onnx.py index 043ff421c..b47bd5d1c 100644 --- a/src/model_converters/x2paddle/paddle2onnx.py +++ b/src/model_converters/paddle_covnerter/paddle2onnx.py @@ -42,7 +42,7 @@ def cli_argument_parser(): def convert_paddle_to_onnx(model_dir: str, model_filename: str, params_filename: str, model_path: str, opset_version: str): - os.system(f"""paddle2onnx --model_dir {model_dir} --model_filename {model_filename} + os.system(f"""paddle2onnx --model_dir {model_dir} --model_filename {model_filename} --params_filename {params_filename} --save_file {model_path} --opset_version {opset_version} diff --git a/src/model_converters/paddle_covnerter/requirements.txt b/src/model_converters/paddle_covnerter/requirements.txt new file mode 100644 index 000000000..46f68f468 --- /dev/null +++ b/src/model_converters/paddle_covnerter/requirements.txt @@ -0,0 +1,2 @@ +x2paddle +paddle2onnx From 36b1d332bbfe3612d342f6a14ec8e24b13cf9f63 Mon Sep 17 00:00:00 2001 From: igkonov Date: Thu, 5 Dec 2024 16:13:16 +0300 Subject: [PATCH 05/13] refactor --- src/csv2html/README.md | 2 +- src/csv2xlsx/README.md | 2 +- .../paddle_covnerter/README.md | 10 +++--- .../{converter.py => srcf2paddle.py} | 36 +++++++++---------- 4 files changed, 23 insertions(+), 27 deletions(-) rename src/model_converters/paddle_covnerter/{converter.py => srcf2paddle.py} (77%) diff --git a/src/csv2html/README.md b/src/csv2html/README.md index 99d1dc2c6..fb31d38c0 100644 --- a/src/csv2html/README.md +++ b/src/csv2html/README.md @@ -3,7 +3,7 @@ Общий вид командной строки: ```bash -python3 converter.py -t -r -k +python3 srcf2paddle.py -t -r -k ``` Аргументы командной строки: diff --git a/src/csv2xlsx/README.md b/src/csv2xlsx/README.md index bea7ea8dc..c55698089 100644 --- a/src/csv2xlsx/README.md +++ b/src/csv2xlsx/README.md @@ -3,7 +3,7 @@ Общий вид командной строки: ```bash -python3 converter.py -t -r -k +python3 srcf2paddle.py -t -r -k ``` Аргументы командной строки: diff --git a/src/model_converters/paddle_covnerter/README.md b/src/model_converters/paddle_covnerter/README.md index f528ff1aa..c4e323bc0 100644 --- a/src/model_converters/paddle_covnerter/README.md +++ b/src/model_converters/paddle_covnerter/README.md @@ -1,13 +1,13 @@ # Conversion to PaddlePaddle -PaddlePaddle converter supports conversion to Paddle format from Pytorch and ONNX formats. +PaddlePaddle converter supports conversion to Paddle format from PyTorch and ONNX formats. ## PaddlePaddle converter usage Usage of the script: ```sh -python converter.py -m -f -p -d +python srcf2paddle.py -m -f -p -d ``` This will convert model from `` to Paddle format. @@ -16,17 +16,17 @@ This will convert model from `` to Paddle format. - `--model_path` is a path to an .onnx or .pth file with the original model. - `--framework` is a source framework for convertion to PaddlePaddle format. -- `--pytorch_module_name` is a module name for PyTorch model (necessary if source framework is Pytorch). +- `--pytorch_module_name` is a module name for PyTorch model (necessary if source framework is PyTorch). - `--save_dir` is a directory for converted model to be saved to. ### Examples of usage ```sh -python converter.py -m .\public\googlenet-v3-pytorch\inception_v3_google-1a9a5a14.pth -f pytorch -p InceptionV3 -d pd +python srcf2paddle.py -m .\public\googlenet-v3-pytorch\inception_v3_google-1a9a5a14.pth -f pytorch -p InceptionV3 -d pd ``` ```sh -python converter.py -m .\public\ctdet_coco_dlav0_512\ctdet_coco_dlav0_512.onnx -f onnx -d pd +python srcf2paddle.py -m .\public\ctdet_coco_dlav0_512\ctdet_coco_dlav0_512.onnx -f onnx -d pd ``` # Conversion from PaddlePaddle diff --git a/src/model_converters/paddle_covnerter/converter.py b/src/model_converters/paddle_covnerter/srcf2paddle.py similarity index 77% rename from src/model_converters/paddle_covnerter/converter.py rename to src/model_converters/paddle_covnerter/srcf2paddle.py index 41e52e7a9..1b3fb44d2 100644 --- a/src/model_converters/paddle_covnerter/converter.py +++ b/src/model_converters/paddle_covnerter/srcf2paddle.py @@ -1,7 +1,6 @@ import torch import numpy as np -from torchvision.models import (AlexNet, VGG, ResNet, SqueezeNet, DenseNet, - Inception3, GoogLeNet, ShuffleNetV2, MobileNetV2, MobileNetV3, MNASNet) +import torchvision.models as models from x2paddle.convert import pytorch2paddle import argparse import logging as log @@ -12,6 +11,15 @@ sys.path.append(str(Path(__file__).parent.parent.parent.parent)) +def get_model_by_name(model_name): + try: + model_constructor = getattr(models, model_name) + model = model_constructor() + return model + except AttributeError: + raise ValueError(f'Model {model_name} is not found in torchvision.models') + + def cli_argument_parser(): parser = argparse.ArgumentParser() @@ -21,7 +29,7 @@ def cli_argument_parser(): type=str, dest='model_path') parser.add_argument('-f', '--framework', - help='Original model framework (ONNX or Pytorch)', + help='Original model framework (ONNX or PyTorch)', required=True, type=str, choices=['onnx', 'pytorch'], @@ -31,7 +39,7 @@ def cli_argument_parser(): required=False, type=str, choices=['AlexNet', 'VGG', 'ResNet', 'SqueezeNet', 'DenseNet', 'InceptionV3', 'GoogLeNet', - 'ShuffleNetV2', 'MobileNetV2', 'MobileNetV3', 'MNASNet'], + 'ShuffleNetV2', 'MobileNetV2', 'MobileNetV3', 'MNASNet', 'EfficientNet'], dest='module_name') parser.add_argument('-d', '--save_dir', help='Directory for converted model to be saved to.', @@ -45,24 +53,12 @@ def cli_argument_parser(): def convert_pytorch_to_paddle(model_path: str, module_name, save_dir: str): - modules = {'AlexNet': AlexNet, - 'VGG': VGG, - 'ResNet': ResNet, - 'SqueezeNet': SqueezeNet, - 'DenseNet': DenseNet, - 'InceptionV3': Inception3, - 'GoogLeNet': GoogLeNet, - 'ShuffleNetV2': ShuffleNetV2, - 'MobileNetV2': MobileNetV2, - 'MobileNetV3': MobileNetV3, - 'MNASNet': MNASNet} - - torch_module = modules[module_name]() - torch_module.load_state_dict(torch.load(model_path)) - torch_module.eval() + model = get_model_by_name(module_name) + model.load_state_dict(torch.load(model_path)) + model.eval() input_data = np.random.rand(1, 3, 224, 224).astype('float32') - pytorch2paddle(torch_module, + pytorch2paddle(model, save_dir=save_dir, jit_type='trace', input_examples=[torch.tensor(input_data)]) From 49d269a343b6e8188c4575ffd0a6376ddf30e772 Mon Sep 17 00:00:00 2001 From: Valentina Date: Mon, 9 Dec 2024 12:04:23 +0300 Subject: [PATCH 06/13] Update README.md --- src/csv2html/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/csv2html/README.md b/src/csv2html/README.md index fb31d38c0..a28c100c4 100644 --- a/src/csv2html/README.md +++ b/src/csv2html/README.md @@ -3,7 +3,7 @@ Общий вид командной строки: ```bash -python3 srcf2paddle.py -t -r -k +python3 converter.py -t -r -k ``` Аргументы командной строки: @@ -19,4 +19,4 @@ python3 srcf2paddle.py -t -r -k 1. Если агрументы не переданы или переданы некорректно, скрипт завершит свою работу. 1. Таблица формируется с разделителем вида ";", так как столбец - "Infrastucture" содержит данные о вычислительном узле, разделенные запятой. \ No newline at end of file + "Infrastucture" содержит данные о вычислительном узле, разделенные запятой. From 9cc12abd83381943345f60734b813f3048522c6c Mon Sep 17 00:00:00 2001 From: Valentina Date: Mon, 9 Dec 2024 12:04:53 +0300 Subject: [PATCH 07/13] Update README.md --- src/csv2xlsx/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/csv2xlsx/README.md b/src/csv2xlsx/README.md index c55698089..16f43289b 100644 --- a/src/csv2xlsx/README.md +++ b/src/csv2xlsx/README.md @@ -3,7 +3,7 @@ Общий вид командной строки: ```bash -python3 srcf2paddle.py -t -r -k +python3 converter.py -t -r -k ``` Аргументы командной строки: @@ -23,4 +23,4 @@ python3 srcf2paddle.py -t -r -k 1. Если агрументы не переданы или переданы некорректно, скрипт завершит свою работу. 1. csv-таблица формируется с разделителем вида ";", так как столбец - "Infrastucture" содержит данные о вычислительном узле, разделенные запятой. \ No newline at end of file + "Infrastucture" содержит данные о вычислительном узле, разделенные запятой. From 7de463f04abb372d5a416a923fa72463ba0e195d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=83=D1=81=D1=82=D0=B8=D0=BA=D0=BE=D0=B2=D0=B0=20?= =?UTF-8?q?=D0=92=D0=B0=D0=BB=D0=B5=D0=BD=D1=82=D0=B8=D0=BD=D0=B0=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B5=D0=B2=D0=BD=D0=B0?= Date: Mon, 9 Dec 2024 12:09:52 +0300 Subject: [PATCH 08/13] Rename dir --- .../{paddle_covnerter => paddle_converter}/README.md | 0 .../{paddle_covnerter => paddle_converter}/paddle2onnx.py | 0 .../{paddle_covnerter => paddle_converter}/requirements.txt | 0 .../{paddle_covnerter => paddle_converter}/srcf2paddle.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/model_converters/{paddle_covnerter => paddle_converter}/README.md (100%) rename src/model_converters/{paddle_covnerter => paddle_converter}/paddle2onnx.py (100%) rename src/model_converters/{paddle_covnerter => paddle_converter}/requirements.txt (100%) rename src/model_converters/{paddle_covnerter => paddle_converter}/srcf2paddle.py (100%) diff --git a/src/model_converters/paddle_covnerter/README.md b/src/model_converters/paddle_converter/README.md similarity index 100% rename from src/model_converters/paddle_covnerter/README.md rename to src/model_converters/paddle_converter/README.md diff --git a/src/model_converters/paddle_covnerter/paddle2onnx.py b/src/model_converters/paddle_converter/paddle2onnx.py similarity index 100% rename from src/model_converters/paddle_covnerter/paddle2onnx.py rename to src/model_converters/paddle_converter/paddle2onnx.py diff --git a/src/model_converters/paddle_covnerter/requirements.txt b/src/model_converters/paddle_converter/requirements.txt similarity index 100% rename from src/model_converters/paddle_covnerter/requirements.txt rename to src/model_converters/paddle_converter/requirements.txt diff --git a/src/model_converters/paddle_covnerter/srcf2paddle.py b/src/model_converters/paddle_converter/srcf2paddle.py similarity index 100% rename from src/model_converters/paddle_covnerter/srcf2paddle.py rename to src/model_converters/paddle_converter/srcf2paddle.py From 1da33b0e0b174567b5bea2d937149cbfdbb070fe Mon Sep 17 00:00:00 2001 From: valentina-kustikova Date: Mon, 9 Dec 2024 12:21:00 +0300 Subject: [PATCH 09/13] Fix readme --- .../paddle_converter/README.md | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/model_converters/paddle_converter/README.md b/src/model_converters/paddle_converter/README.md index c4e323bc0..4abf2fdb1 100644 --- a/src/model_converters/paddle_converter/README.md +++ b/src/model_converters/paddle_converter/README.md @@ -1,58 +1,62 @@ -# Conversion to PaddlePaddle +# Conversion to the PaddlePaddle format -PaddlePaddle converter supports conversion to Paddle format from PyTorch and ONNX formats. +PaddlePaddle converter supports conversion to the PaddlePaddle format +from PyTorch and ONNX formats. ## PaddlePaddle converter usage Usage of the script: -```sh -python srcf2paddle.py -m -f -p -d +```bash +python srcf2paddle.py -m -f \ + -p -d ``` -This will convert model from `` to Paddle format. - ### Paddle converter parameters -- `--model_path` is a path to an .onnx or .pth file with the original model. -- `--framework` is a source framework for convertion to PaddlePaddle format. -- `--pytorch_module_name` is a module name for PyTorch model (necessary if source framework is PyTorch). -- `--save_dir` is a directory for converted model to be saved to. +- `-m / --model_path` is a path to an .onnx or .pth file with the original model. +- `-f / --framework` is a source framework for convertion to the PaddlePaddle format. +- `-p / --pytorch_module_name` is a module name for the PyTorch model (it is required + if source framework is PyTorch). +- `-d / --save_dir` is a directory for converted model to be saved to. ### Examples of usage -```sh -python srcf2paddle.py -m .\public\googlenet-v3-pytorch\inception_v3_google-1a9a5a14.pth -f pytorch -p InceptionV3 -d pd +```bash +python srcf2paddle.py -m .\public\googlenet-v3-pytorch\inception_v3_google-1a9a5a14.pth \ + -f pytorch -p InceptionV3 -d pd ``` -```sh -python srcf2paddle.py -m .\public\ctdet_coco_dlav0_512\ctdet_coco_dlav0_512.onnx -f onnx -d pd +```bash +python srcf2paddle.py -m .\public\ctdet_coco_dlav0_512\ctdet_coco_dlav0_512.onnx \ + -f onnx -d pd ``` -# Conversion from PaddlePaddle +# Conversion from the PaddlePaddle to the ONNX format -paddle2onnx converter supports conversion to ONNX format from Paddle format. +paddle2onnx converter supports conversion to the ONNX format from the PaddlePaddle +format. ## PaddlePaddle converter usage Usage of the script: -```sh -python paddle2onnx.py -d .\pd_pth\inference_model -f model.pdmodel -p model.pdiparams -m inference.onnx -o 11 +```bash +python paddle2onnx.py -d .\pd_pth\inference_model -f model.pdmodel \ + -p model.pdiparams -m inference.onnx -o 11 ``` -This script will convert model from Paddle to ONNX format. - ### Converter parameters -- `--model_dir` is a path to the directory with the original model. -- `--model_filename` is a name of the model file name. -- `--params_filename` is a name of the parameters file name. -- `--model_path` is a path to the resulting .onnx file. -- `--opset_version` is a desired opset version of the resulting ONNX model. +- `-d / --model_dir` is a path to the directory with the original model. +- `-f / --model_filename` is a model file name. +- `-p / --params_filename` is a parameters file name. +- `-m / --model_path` is a path to the resulting .onnx file. +- `-o / --opset_version` is a desired opset version of the ONNX model. ### Examples of usage -```sh -python paddle2onnx.py -d .\pd_pth\inference_model -f model.pdmodel -p model.pdiparams -m inference.onnx -o 11 +```bash +python paddle2onnx.py -d .\pd_pth\inference_model -f model.pdmodel \ + -p model.pdiparams -m inference.onnx -o 11 ``` From b76f80c063e52b4d64f380f2292a04ad8a92c62e Mon Sep 17 00:00:00 2001 From: Valentina Date: Tue, 10 Dec 2024 18:11:42 +0300 Subject: [PATCH 10/13] Fix line len --- src/model_converters/paddle_converter/srcf2paddle.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/model_converters/paddle_converter/srcf2paddle.py b/src/model_converters/paddle_converter/srcf2paddle.py index 1b3fb44d2..4280e48da 100644 --- a/src/model_converters/paddle_converter/srcf2paddle.py +++ b/src/model_converters/paddle_converter/srcf2paddle.py @@ -38,8 +38,9 @@ def cli_argument_parser(): help='Module name for PyTorch model.', required=False, type=str, - choices=['AlexNet', 'VGG', 'ResNet', 'SqueezeNet', 'DenseNet', 'InceptionV3', 'GoogLeNet', - 'ShuffleNetV2', 'MobileNetV2', 'MobileNetV3', 'MNASNet', 'EfficientNet'], + choices=['AlexNet', 'VGG', 'ResNet', 'SqueezeNet', 'DenseNet', + 'InceptionV3', 'GoogLeNet', 'ShuffleNetV2', 'MobileNetV2', + 'MobileNetV3', 'MNASNet', 'EfficientNet'], dest='module_name') parser.add_argument('-d', '--save_dir', help='Directory for converted model to be saved to.', From 7a4b88a622e2fd79fd1ff7cd53ee004d4890841b Mon Sep 17 00:00:00 2001 From: Valentina Date: Tue, 10 Dec 2024 18:24:01 +0300 Subject: [PATCH 11/13] Try to fix tests --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 0c15f1647..6f6263c6f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ PyYAML paramiko; sys_platform != 'win32' wmi; sys_platform == 'win32' opencv-python +PyQt5-sip PyQt5 pandas xlsxwriter From bfa7839729087085ccbbac41548054f702e502fc Mon Sep 17 00:00:00 2001 From: Valentina Date: Tue, 10 Dec 2024 18:27:11 +0300 Subject: [PATCH 12/13] Try to fix tests --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6f6263c6f..cc6b232d0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ PyYAML paramiko; sys_platform != 'win32' wmi; sys_platform == 'win32' opencv-python -PyQt5-sip +PyQt5-sip==12.15.0 PyQt5 pandas xlsxwriter From 34494c632cb133f236d0294326c2a2e6cdf9820e Mon Sep 17 00:00:00 2001 From: Valentina Date: Tue, 10 Dec 2024 18:28:52 +0300 Subject: [PATCH 13/13] Try to fix tests --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index cc6b232d0..36c6d0c79 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ PyYAML paramiko; sys_platform != 'win32' wmi; sys_platform == 'win32' opencv-python -PyQt5-sip==12.15.0 +PyQt5-sip==12.12.2 PyQt5 pandas xlsxwriter