From 30e35c988bfd59da53168bd8fdb3eac3a48269cc Mon Sep 17 00:00:00 2001 From: SunAhong1993 <48579383+SunAhong1993@users.noreply.github.com> Date: Tue, 18 May 2021 16:13:41 +0800 Subject: [PATCH] fix the bug and fix the doc (#582) * fix the code * fix the visit_tuple * Update stargan.md * Update ultra_light_fast_generic_face_detector.md * fix the docs --- docs/inference_model_convertor/FAQ.md | 2 +- docs/introduction/x2paddle_model_zoo.md | 10 +++++----- docs/pytorch_project_convertor/API_docs/README.md | 2 +- docs/pytorch_project_convertor/add_api.md | 2 +- docs/pytorch_project_convertor/demo/stargan.md | 4 ++-- .../demo/ultra_light_fast_generic_face_detector.md | 5 +++-- .../op_mapper/dygraph/caffe2paddle/caffe_op_mapper.py | 4 ++-- .../op_mapper/static/caffe2paddle/caffe_op_mapper.py | 4 ++-- x2paddle/project_convertor/pytorch/ast_update.py | 5 +++-- x2paddle/project_convertor/pytorch/mapper.py | 2 +- 10 files changed, 21 insertions(+), 19 deletions(-) diff --git a/docs/inference_model_convertor/FAQ.md b/docs/inference_model_convertor/FAQ.md index 293229d..23a5feb 100644 --- a/docs/inference_model_convertor/FAQ.md +++ b/docs/inference_model_convertor/FAQ.md @@ -34,4 +34,4 @@ out =main(ipt) > 若运行代码无误,则说明代码中有op不支持动转静,我们将会再未来支持;若报错,则说明pytorch2paddle转换出错,请提issue,我们将及时回复。 **Q5. 目前支持了哪些op的转换呢?** -A: 可详见[X2Paddle支持的op列表](./docs/inference_model_convertor/op_list.md)。 +A: 可详见[X2Paddle支持的op列表](op_list.md)。 diff --git a/docs/introduction/x2paddle_model_zoo.md b/docs/introduction/x2paddle_model_zoo.md index 7c45808..e2ca747 100644 --- a/docs/introduction/x2paddle_model_zoo.md +++ b/docs/introduction/x2paddle_model_zoo.md @@ -16,7 +16,7 @@ | VGG16 | [code](https://github.com/tensorflow/models/tree/master/research/slim/nets) | | ResNet_V1_101 | [code](https://github.com/tensorflow/models/tree/master/research/slim/nets) | | ResNet_V2_101 | [code](https://github.com/tensorflow/models/tree/master/research/slim/nets) | -| UNet | [code1](https://github.com/jakeret/tf_unet )/[code2](https://github.com/lyatdawn/Unet-Tensorflow) | +| UNet | [code1](https://github.com/jakeret/tf_unet)/[code2](https://github.com/lyatdawn/Unet-Tensorflow) | | MTCNN | [code](https://github.com/AITTSMD/MTCNN-Tensorflow) | | YOLO-V3| [code](https://github.com/YunYang1994/tensorflow-yolov3) | | FALSR | [code](https://github.com/xiaomi-automl/FALSR) | @@ -49,7 +49,7 @@ ## ONNX预测模型 -**注:** 部分模型来源于PyTorch,PyTorch的转换可参考[pytorch_to_onnx.md](pytorch_to_onnx.md) +**注:** 部分模型来源于PyTorch,PyTorch的转换可参考[pytorch_to_onnx.md](../inference_model_convertor/pytorch2onnx.md) | 模型 | 来源 | operator version|备注| |-------|--------|---------|---------| @@ -82,7 +82,7 @@ | MNasNet | [code](https://github.com/pytorch/vision/blob/master/torchvision/models/mnasnet.py) |-| | MobileNetV2 | [code](https://github.com/pytorch/vision/blob/master/torchvision/models/mobilenet.py) |-| | ResNet18 | [code](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) |-| -| ShuffleNetV2 | [code](https://github.com/pytorch/vision/blob/master/torchvision/models/shufflenet.py) |-| +| ShuffleNetV2 | [code](https://github.com/pytorch/vision/blob/master/torchvision/models/shufflenetv2.py) |-| | SqueezeNet | [code](https://github.com/pytorch/vision/blob/master/torchvision/models/squeezenet.py) |-| | VGG16 | [code](https://github.com/pytorch/vision/blob/master/torchvision/models/vgg.py) |-| | InceptionV3 | [code](https://github.com/pytorch/vision/blob/master/torchvision/models/inception.py) |-| @@ -90,7 +90,7 @@ | FCN_ResNet50 | [code](https://github.com/pytorch/vision/blob/master/torchvision/models/segmentation/fcn.py) |-| | CamembertForQuestionAnswering | [code](https://huggingface.co/transformers/model_doc/camembert.html) |只支持trace模式| | DPRContextEncoder | [code](https://huggingface.co/transformers/model_doc/dpr.html) |只支持trace模式| -| ElectraModel | [code](https://huggingface.co/transformers/model_doc/electra.html ) |只支持trace模式| +| ElectraModel | [code](https://huggingface.co/transformers/model_doc/electra.html) |只支持trace模式| | FlaubertModel | [code](https://huggingface.co/transformers/model_doc/flaubert.html) |只支持trace模式| | Roberta| [code](https://huggingface.co/transformers/model_doc/roberta.html) |只支持trace模式| | XLMRobertaForTokenClassification|[code](https://huggingface.co/transformers/model_doc/xlmroberta.html) |只支持trace模式| @@ -98,7 +98,7 @@ | EasyOCR_recognizer|[code](https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/recognition.py) |-| | SwinTransformer|[code](https://github.com/microsoft/Swin-Transformer/) |-| | BASNet|[code](https://github.com/xuebinqin/BASNet) |-| -| DBFace |[code](https://github.com/dlunion/DBFacet) |-| +| DBFace |[code](https://github.com/dlunion/DBFace) |-| ## PyTorch训练项目 | 模型 | 转换前代码 | 转换后代码 | diff --git a/docs/pytorch_project_convertor/API_docs/README.md b/docs/pytorch_project_convertor/API_docs/README.md index 8cd1759..74e2936 100644 --- a/docs/pytorch_project_convertor/API_docs/README.md +++ b/docs/pytorch_project_convertor/API_docs/README.md @@ -3,7 +3,7 @@ | 类别 | 简介 | | ---------- | ------------------------- | | [基础操作类](./ops/README.md) | 主要为`torch.XX`类API | -| [组网类]((./nn/README.md)) | 主要为`torch.nn.XX`类下组网相关的API | +| [组网类](./nn/README.md) | 主要为`torch.nn.XX`类下组网相关的API | | [Loss类](./loss/README.md) |主要为`torch.nn.XX`类下loss相关的API | | [工具类](./utils/README.md) | 主要为`torch.nn.XX`类下分布式相关的API和`torch.utils.XX`类API| | [视觉类](./vision/README.md) | 主要为`torchvision.XX`类API | diff --git a/docs/pytorch_project_convertor/add_api.md b/docs/pytorch_project_convertor/add_api.md index 8e89b18..72f0636 100644 --- a/docs/pytorch_project_convertor/add_api.md +++ b/docs/pytorch_project_convertor/add_api.md @@ -116,7 +116,7 @@ NN_MAPPER = { 该情况需要完成以下几个步骤: -***步骤1*** 在[x2paddle/project_convertor/pytorch/mapper.py](.../../x2paddle/project_convertor/pytorch/mapper.py)中对应的MAPPER中添加PyTorch API的字符串以及Paddle API的字符串、映射处理类,具体实现如下: +***步骤1*** 在[x2paddle/project_convertor/pytorch/mapper.py](../../x2paddle/project_convertor/pytorch/mapper.py)中对应的MAPPER中添加PyTorch API的字符串以及Paddle API的字符串、映射处理类,具体实现如下: ```python # key为PyTorch API字符串; diff --git a/docs/pytorch_project_convertor/demo/stargan.md b/docs/pytorch_project_convertor/demo/stargan.md index 92d4151..17a1b00 100644 --- a/docs/pytorch_project_convertor/demo/stargan.md +++ b/docs/pytorch_project_convertor/demo/stargan.md @@ -3,9 +3,9 @@ ``` shell # 下载项目 git clone https://github.com/yunjey/stargan.git +cd stargan git checkout 30867d6f85a3bb99c38ae075de651004747c42d4 # 下载预训练模型 -cd stargan bash download.sh pretrained-celeba-128x128 # 下载数据集 bash download.sh celeba @@ -99,7 +99,7 @@ class Solver(object): ### 运行训练代码 ``` shell -cd paddle_project/stargan +cd paddle_project python main.py --mode train --dataset CelebA --image_size 128 --c_dim 5 --sample_dir stargan_celeba/samples --log_dir stargan_celeba/logs --model_save_dir stargan_celeba/models --result_dir stargan_celeba/results --selected_attrs Black_Hair Blond_Hair Brown_Hair Male Young --celeba_image_dir ./data/celeba/images --attr_path ./data/celeba/list_attr_celeba.txt ``` diff --git a/docs/pytorch_project_convertor/demo/ultra_light_fast_generic_face_detector.md b/docs/pytorch_project_convertor/demo/ultra_light_fast_generic_face_detector.md index dc5830e..f41001d 100644 --- a/docs/pytorch_project_convertor/demo/ultra_light_fast_generic_face_detector.md +++ b/docs/pytorch_project_convertor/demo/ultra_light_fast_generic_face_detector.md @@ -5,9 +5,10 @@ ``` shell # 下载项目 git clone https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB.git +cd Ultra-Light-Fast-Generic-Face-Detector-1MB git checkout 492a02471671b49c56be8d90cda54c94749d2980 ``` -2. 根据Generate VOC format training data set and training process的README.md所示下载数据集,并存放于Ultra-Light-Fast-Generic-Face-Detector-1MB/data/文件夹下。 +2. 根据[Generate VOC format training data set and training process的README.md](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB#generate-voc-format-training-data-set-and-training-process)所示下载数据集,并存放于Ultra-Light-Fast-Generic-Face-Detector-1MB/data/文件夹下。 ### 第一步:转换前代码预处理 1. 将代码中的[或操作符](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/blob/master/vision/utils/box_utils.py#L153)替换为如下代码: ``` python @@ -83,7 +84,7 @@ class VOCDataset(data.Dataset): ### 运行训练代码 ``` shell -cd paddle_project/Ultra-Light-Fast-Generic-Face-Detector-1MB +cd paddle_projec sh train-version-RFB.sh ``` ***转换后的代码可在[这里](https://github.com/SunAhong1993/Ultra-Light-Fast-Generic-Face-Detector-1MB/tree/paddle)进行查看。*** diff --git a/x2paddle/op_mapper/dygraph/caffe2paddle/caffe_op_mapper.py b/x2paddle/op_mapper/dygraph/caffe2paddle/caffe_op_mapper.py index dcecf0e..f75ac35 100644 --- a/x2paddle/op_mapper/dygraph/caffe2paddle/caffe_op_mapper.py +++ b/x2paddle/op_mapper/dygraph/caffe2paddle/caffe_op_mapper.py @@ -1188,8 +1188,8 @@ class CaffeOpMapper(OpMapper): "scale_factor": params.scale, "mode": "nearest"} self.paddle_graph.add_layer( - "paddle.nn.functioanl.interpolate", - inputs={"input": input.name}, + "paddle.nn.functional.interpolate", + inputs={"x": input.name}, outputs=[node.layer_name], **layer_attrs) diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py b/x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py index d76c977..c3917b3 100644 --- a/x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py +++ b/x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py @@ -1247,8 +1247,8 @@ class CaffeOpMapper(OpMapper): "scale_factor": params.scale, "mode": "nearest"} self.paddle_graph.add_layer( - "paddle.nn.functioanl.interpolate", - inputs={"input": input.name}, + "paddle.nn.functional.interpolate", + inputs={"x": input.name}, outputs=[node.layer_name], **layer_attrs) diff --git a/x2paddle/project_convertor/pytorch/ast_update.py b/x2paddle/project_convertor/pytorch/ast_update.py index bff9112..8d2caf0 100644 --- a/x2paddle/project_convertor/pytorch/ast_update.py +++ b/x2paddle/project_convertor/pytorch/ast_update.py @@ -431,8 +431,9 @@ class AstUpdater(ast.NodeVisitor): elts_nodes = getattr(node, "elts") elts = list() for elts_node in elts_nodes: - elts.append(self.visit(elts_node)) - elts = tuple(elts) + elt = self.visit(elts_node) + elts.append(elt if isinstance(elt, str) else str(elt)) + elts = "({})".format(", ".join(elts)) return elts def visit_Assign(self, node): diff --git a/x2paddle/project_convertor/pytorch/mapper.py b/x2paddle/project_convertor/pytorch/mapper.py index 81ceec3..c139a2e 100644 --- a/x2paddle/project_convertor/pytorch/mapper.py +++ b/x2paddle/project_convertor/pytorch/mapper.py @@ -275,7 +275,7 @@ API_MAPPER = { "torch.min": ["x2paddle.torch2paddle.min", None], "torch.argmax": ["paddle.argmax", OneMathMapper], "torch.argmin": ["paddle.argmin", OneMathMapper], - "torch.stack": ["paddle.stacks", StackMapper], + "torch.stack": ["paddle.stack", StackMapper], "torch.log": ["paddle.log", OneMathMapper], "torch.randperm": ["paddle.randperm", RandpermMapper], "torch.rand": ["x2paddle.torch2paddle.rand", None], -- GitLab