[Dy2St] transforms.Resize Support static mode #49008
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
New features
PR changes
OPs
Describe
vision.transform变换类API新增支持静态图的样板间PR,供 #48612 参考。
支持静态图分支,实现API行为动静统一主要包括如下三个核心步骤:
step 1:tensor 判断逻辑升级
在 Resize API 中使用了
_is_tensor_image
函数。在静态图下,需要此函数支持 Variable 类型判断,同样返回 True 即可:step 2:升级functional_tensor.py的核心接口
Resize 与Tensor相关的变换逻辑是在functional_tensor.py 中实现的,需要兼容适配下静态图逻辑。静态图下是通过append_op添加算子实现组网的,此部分逻辑大多数已经封装在了框架公用API中,只需要微调适配下即可。
step 3:添加相应单测,确保静态图执行结果与动态图一致
可以统一添加到 test_transforms_static.py 文件里,统一继承TestTransformUnitTestBase基类即可。
对于新增单测,仅需要设置api信息即可,如有新需求,可扩展TestTransformUnitTestBase基类接口:
其他说明
1. 注意 API 入口逻辑分流
其他vision.transform 的API入口逻辑可能相对复杂,可以考虑在入口函数进行分流,如:
2. 注意静态图下动态shape的适配或报错