Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
f5f9249a
MegEngine
项目概览
MegEngine 天元
/
MegEngine
大约 1 年 前同步成功
通知
399
Star
4705
Fork
582
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
f5f9249a
编写于
2月 28, 2022
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs(compose): update compose API docstring and example
GitOrigin-RevId: fd52df2c48d50749714ea909f0b53440c7965fca
上级
7d3a6db0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
58 addition
and
26 deletion
+58
-26
imperative/python/megengine/data/transform/vision/transform.py
...ative/python/megengine/data/transform/vision/transform.py
+58
-26
未找到文件。
imperative/python/megengine/data/transform/vision/transform.py
浏览文件 @
f5f9249a
...
...
@@ -8,7 +8,7 @@
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import
collections.abc
import
math
from
typing
import
Sequence
,
Tuple
from
typing
import
List
,
Sequence
,
Tuple
import
cv2
import
numpy
as
np
...
...
@@ -52,7 +52,7 @@ class VisionTransform(Transform):
order is used to specify the order of structures. For example, if your input
is (image, boxes) type, then the ``order`` should be ("image", "boxes").
Current available strings and data type are describe below:
* "image": input image, with shape of `(H, W, C)`.
* "coords": coordinates, with shape of `(N, 2)`.
* "boxes": bounding boxes, with shape of `(N, 4)`, "xyxy" format,
...
...
@@ -69,7 +69,7 @@ class VisionTransform(Transform):
means category of the input image and "boxes_category" means categories of
bounding boxes.
* "info": information for images such as image shapes and image path.
You can also customize your data types only if you implement the corresponding
_apply_*() methods, otherwise ``NotImplementedError`` will be raised.
"""
...
...
@@ -183,35 +183,67 @@ class ToMode(VisionTransform):
class
Compose
(
VisionTransform
):
r
"""Composes several transfo
rm
s together.
r
"""Composes several transfo
mation
s together.
Args:
transforms: list of :class:`VisionTransform` to compose.
batch_compose: whether use shuffle_indices for batch data or not.
If True, use original input sequence.
Otherwise, the shuffle_indices will be used for transforms.
batch_compose: whether keep the same transform order in batch data when shuffle.
shuffle_indices: indices used for random shuffle, start at 1.
For example, if shuffle_indices is [(1, 3), (2, 4)], then the 1st and 3rd transform
will be random shuffled, the 2nd and 4th transform will also be shuffled.
order: the same with :class:`VisionTransform`
.. seealso:: Refer to :mod:`~.data.transform` module for vision transform APIs.
Examples:
.. testcode::
from megengine.data.transform import RandomHorizontalFlip, RandomVerticalFlip, CenterCrop, ToMode, Compose
transform_func = Compose([
RandomHorizontalFlip(),
RandomVerticalFlip(),
CenterCrop(100),
ToMode("CHW"),
],
shuffle_indices=[(1, 2, 3)]
)
>>> import megengine.data.transform as T
>>> T.Compose([ # doctest: +SKIP
... T.RandomHorizontalFlip(), # 1st
... T.RandomVerticalFlip(), # 2nd
... T.CenterCrop(100), # 3rd
... T.ToMode("CHW"), # 4th
... ],
... shuffle_indices=[(1, 2, 3)]
... )
In this case, ``shuffle_indices`` is given so each input data will be transformed
out of order:
.. math::
\begin{array}{cc}
[{\color{red}1 \quad 2 \quad 3} \quad 4] & [{\color{red}1 \quad 3 \quad 2} \quad 4] \\
[{\color{red}2 \quad 1 \quad 3} \quad 4] & [{\color{red}2 \quad 3 \quad 1} \quad 4] \\
[{\color{red}3 \quad 1 \quad 2} \quad 4] & [{\color{red}3 \quad 2 \quad 1} \quad 4]
\end{array}
In another case, if ``[(1, 3), (2, 4)]`` is given, then the 1st and 3rd transfomation
will be random shuffled, the 2nd and 4th transfomation will also be shuffled:
.. math::
\begin{array}{cc}
[{\color{red}1} \quad {\color{blue}2} \quad {\color{red}3} \quad {\color{blue}4}] &
[{\color{red}1} \quad {\color{blue}4} \quad {\color{red}3} \quad {\color{blue}2}] \\
[{\color{red}3} \quad {\color{blue}2} \quad {\color{red}1} \quad {\color{blue}4}] &
[{\color{red}3} \quad {\color{blue}4} \quad {\color{red}1} \quad {\color{blue}2}]
\end{array}
Different colors represent different groups that need to be internally shuffled.
.. warning::
Different samples within each batch will also use random transfomation orders,
unless ``batch_compose`` is set to ``True``.
"""
def
__init__
(
self
,
transforms
=
[],
batch_compose
=
False
,
shuffle_indices
=
None
,
*
,
order
=
None
self
,
transforms
:
List
[
VisionTransform
]
=
[],
batch_compose
:
bool
=
False
,
shuffle_indices
:
List
[
Tuple
]
=
None
,
*
,
order
=
None
):
super
().
__init__
(
order
)
self
.
transforms
=
transforms
...
...
@@ -354,7 +386,7 @@ class Resize(VisionTransform):
Args:
output_size: target size of image, with (height, width) shape.
interpolation: interpolation method. All methods are listed below:
* cv2.INTER_NEAREST – a nearest-neighbor interpolation.
* cv2.INTER_LINEAR – a bilinear interpolation (used by default).
* cv2.INTER_AREA – resampling using pixel area relation.
...
...
@@ -1012,9 +1044,9 @@ class ColorJitter(VisionTransform):
class
Lighting
(
VisionTransform
):
r
"""Apply AlexNet-Style "lighting" augmentation to input data.
Input images are assumed to have 'RGB' channel order.
The degree of color jittering is randomly sampled via a normal distribution,
with standard deviation given by the scale parameter.
"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录