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

update 2.0 public api in vision #33308

Merged
merged 2 commits into from
Jun 11, 2021
Merged

update 2.0 public api in vision #33308

merged 2 commits into from
Jun 11, 2021

Conversation

zhiboniu
Copy link
Contributor

@zhiboniu zhiboniu commented Jun 2, 2021

PR types

Others

PR changes

APIs

Describe

update 2.0 public api in vision
cherry-pick to #33307

PR types

Others

PR changes

APIs

Describe

update 2.0 public api in vision

背景:
对于用户调用api的层级,由于之前没有明确的设计,api开放层级比较随意。影响用户使用中的逻辑和正规感受。
目的:
1)重新整理api开放层级,提升用户使用感受
2)API保留自有特色,同时更好地符合行业规范,降低用户学习成本
3)提高框架api逻辑性,便于后续维护和优化
主要实现方法:
1)__all__内容清晰化,内容逐个列出,一行一个。不再使用 all 的向上传递机制,仅在公开API层级添加 all,其余的 all 列表统一置空
2)不再使用 #DEFINE_ALIAS
3)导入内容清晰化,原则上不再使用 import *, 按需引入需要的API, 每行一个
4)原则上不再使用 from . import module, from .module import submodule时会引入module,避免重复引用
5)添加新的Public API时,需向上寻找到最近的节点添加 import 并加入 all 列表
6)Public API列表由多个公开API层级的 all 列表共同组成,文档抽取以此为准,这些指定层级是:
paddle,
paddle.amp,
paddle.nn,
paddle.nn.functional,
paddle.nn.initializer,
paddle.nn.utils,
paddle.static,
paddle.static.nn,
paddle.io,
paddle.jit,
paddle.metric,
paddle.distribution,
paddle.optimizer,
paddle.optimizer.lr,
paddle.regularizer,
paddle.text,
paddle.utils,
paddle.utils.download,
paddle.utils.profiler,
paddle.utils.cpp_extension,
paddle.sysconfig,
paddle.vision,
paddle.vision.datasets,
paddle.vision.models,
paddle.vision.transforms,
paddle.vision.ops,
paddle.distributed,
paddle.distributed.fleet,
paddle.distributed.fleet.utils,
paddle.distributed.parallel,
paddle.distributed.utils,
paddle.callbacks,
paddle.hub,
paddle.autograd,
paddle.incubate,
paddle.inference,
paddle.onnx,
paddle.Tensor

修改示例展示:
原来写法:
image
新的写法:
image

对开发者使用API的影响:
1)在指定层级推荐方式:(不受影响)
from paddle.nn import CTCLoss
from paddle.nn import Conv2D
2)非指定层级支持但不推荐:(不受影响)
from paddle.nn.layer.loss import CTCLoss
from paddle.nn.layer.conv import Conv2D
3)对于import *使用方式不推荐。(非公开层级受影响)
不再支持:(非公开层级)
from paddle.nn.layer import *
from paddle.nn.layer.conv import *
from paddle.nn.initializer.norm import *
from paddle.tensor.math import *
from paddle.optimizer.adam import *
可以支持:(公开层级)
from paddle import *
from paddle.nn import *
from paddle.utils import *
from paddle.optimizer import *

本pr涉及的改动:
本pr整理vision文件夹下相关api开放接口,对原有接口按使用习惯及示例在以下几个层级开放,删除底层py文件__all__接口:
paddle.vision,
paddle.vision.datasets,
paddle.vision.models,
paddle.vision.transforms,
paddle.vision.ops,

@paddle-bot-old
Copy link

paddle-bot-old bot commented Jun 2, 2021

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

+ datasets.__all__ \
+ image.__all__
__all__ = [ #noqa
'set_image_backend', 'get_image_backend', 'image_load'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

和其它一样分行写?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里相对还好只有3个,目前这样也还比较清楚。
我看看有没有其他修改一起顺便改了,如果没有其他要改的就下次再改也行吧

XiaoguangHu01
XiaoguangHu01 previously approved these changes Jun 4, 2021
Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

from .image import set_image_backend # noqa: F401
from .image import get_image_backend # noqa: F401
from .image import image_load # noqa: F401
from .models import LeNet # noqa: F401
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为啥单独一个LeNet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为很多地方调用了这个,放这里是为了避免出错

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个理由表述的并不充分呀。另外,注意到下面all里也没包含。

Copy link
Contributor Author

@zhiboniu zhiboniu Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/search?p=1&q=org%3APaddlePaddle+paddle.vision.LeNet&type=Code
可以参考这里的结果。其实理想情况是跟其他模型api一样在这里不保留比较好。
因为LeNet已经在推荐路径加入__all__了(跟其他模型hapi在一个路径下),所以这里的__all__不加入。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经把所有调用paddle.vision.LeNet修改为paddle.vision.models.LeNet,同时删除了这一行

LielinJiang
LielinJiang previously approved these changes Jun 4, 2021
from .image import set_image_backend # noqa: F401
from .image import get_image_backend # noqa: F401
from .image import image_load # noqa: F401
from .models import LeNet # noqa: F401
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个理由表述的并不充分呀。另外,注意到下面all里也没包含。

@zhiboniu zhiboniu dismissed stale reviews from LielinJiang and XiaoguangHu01 via b943fc1 June 8, 2021 09:07
XiaoguangHu01
XiaoguangHu01 previously approved these changes Jun 10, 2021
Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python/paddle/hapi/model.py:34:1: F811 redefinition of unused 'in_dygraph_mode' from line 33
python/paddle/hapi/model.py:34:1: F811 redefinition of unused 'Variable' from line 33
python/paddle/hapi/model.py:166:18: F821 undefined name 'unique_name'
python/paddle/hapi/model.py:169:9: F841 local variable 'endpoint_to_index_map' is assigned to but never used
python/paddle/hapi/model.py:1366:97: E502 the backslash is redundant between brackets
python/paddle/hapi/model.py:1504:66: E502 the backslash is redundant between brackets
python/paddle/hapi/model.py:2125:29: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
python/paddle/hapi/model.py:2126:35: E502 the backslash is redundant between brackets
python/paddle/vision/transforms/functional_cv2.py:54:8: E713 test for membership should be 'not in'
python/paddle/vision/transforms/functional_cv2.py:397:26: F523 '...'.format(...) has unused arguments at position(s): 0
python/paddle/vision/transforms/functional_pil.py:62:8: E713 test for membership should be 'not in'
python/paddle/vision/transforms/functional_pil.py:383:26: F523 '...'.format(...) has unused arguments at position(s): 0

Copy link
Collaborator

@raindrops2sea raindrops2sea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zhiboniu
Copy link
Contributor Author

python/paddle/hapi/model.py:34:1: F811 redefinition of unused 'in_dygraph_mode' from line 33
python/paddle/hapi/model.py:34:1: F811 redefinition of unused 'Variable' from line 33
python/paddle/hapi/model.py:166:18: F821 undefined name 'unique_name'
python/paddle/hapi/model.py:169:9: F841 local variable 'endpoint_to_index_map' is assigned to but never used
python/paddle/hapi/model.py:1366:97: E502 the backslash is redundant between brackets
python/paddle/hapi/model.py:1504:66: E502 the backslash is redundant between brackets
python/paddle/hapi/model.py:2125:29: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
python/paddle/hapi/model.py:2126:35: E502 the backslash is redundant between brackets
python/paddle/vision/transforms/functional_cv2.py:54:8: E713 test for membership should be 'not in'
python/paddle/vision/transforms/functional_cv2.py:397:26: F523 '...'.format(...) has unused arguments at position(s): 0
python/paddle/vision/transforms/functional_pil.py:62:8: E713 test for membership should be 'not in'
python/paddle/vision/transforms/functional_pil.py:383:26: F523 '...'.format(...) has unused arguments at position(s): 0

done

Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@XiaoguangHu01 XiaoguangHu01 merged commit 2de737e into PaddlePaddle:develop Jun 11, 2021
@zhiboniu zhiboniu deleted the develop_vision branch November 25, 2021 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants