与其它框架 API 进行对比#
警告
MegEngine 的 API 设计遵循 MEP 3 – Tensor API 设计规范 , 向《数组 API 标准》靠齐。
在同其它框架进行对比时,同样的命名不意味着用法也完全一致;
如果有新的 API 支持需求,可在 GitHub 创建相应的 Issue 或 Pull Request.
备注
你可以利用浏览器的查找功能在当前页面查询对应的 API.
当前页面并非自动生成,如发现有缺失/过时内容,欢迎编辑当前页面。
参见
当前页面更多用于检索,具有其它框架使用经验的用户还可以参考 用户迁移指南 。
数据结构#
NumPy |
Pytorch |
MegEngine |
Comment |
---|---|---|---|
全局tensor操作#
创建功能#
NumPy |
Pytorch |
MegEngine |
Comment |
---|---|---|---|
操作功能#
NumPy |
Pytorch |
MegEngine |
Comment |
---|---|---|---|
Arithmetic operations#
NumPy |
Pytorch |
MegEngine |
Comment |
---|---|---|---|
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Trigonometric functions#
NumPy |
Pytorch |
MegEngine |
Comment |
---|---|---|---|
Hyperbolic functions#
NumPy |
Pytorch |
MegEngine |
Comment |
---|---|---|---|
Bit operations#
NumPy |
Pytorch |
MegEngine |
Comment |
---|---|---|---|
Not Found |
|
||
Not Found |
|
Logic functions#
NumPy |
Pytorch |
MegEngine |
Comment |
---|---|---|---|
Not Found |
|
||
Not Found |
|
||
Not Found |
|
||
Not Found |
|
||
统计函数#
NumPy |
Pytorch |
MegEngine |
Comment |
---|---|---|---|
线性代数函数#
NumPy |
Pytorch |
MegEngine |
Comment |
---|---|---|---|
Indexing Functions#
NumPy |
Pytorch |
MegEngine |
Comment |
---|---|---|---|
取决于传参情况 |
Searching Functions#
NumPy |
Pytorch |
MegEngine |
Comment |
---|---|---|---|
Sorting Functions#
NumPy |
Pytorch |
MegEngine |
Comment |
---|---|---|---|
NN Funtional Operations#
卷积运算#
Pytorch |
MegEngine |
Comment |
---|---|---|
local_conv2d |
||
deformable_conv2d |
||
池化函数#
Pytorch |
MegEngine |
Comment |
---|---|---|
非线性激活函数#
Pytorch |
MegEngine |
Comment |
---|---|---|
标准化函数#
Pytorch |
MegEngine |
Comment |
---|---|---|
See |
||
See |
||
See |
||
线性函数#
Pytorch |
MegEngine |
Comment |
---|---|---|
Dropout 函数#
Pytorch |
MegEngine |
Comment |
---|---|---|
Sparse 函数#
Pytorch |
MegEngine |
Comment |
---|---|---|
度量函数#
Pytorch |
MegEngine |
Comment |
---|---|---|
损失函数#
Pytorch |
MegEngine |
Comment |
---|---|---|
NN Module#
Pytorch |
MegEngine |
Comment |
---|---|---|
容器#
Pytorch |
MegEngine |
Comment |
---|---|---|
MegEngine 原生支持 |
||
MegEngine 原生支持 |
||
MegEngine 原生支持 |
||
MegEngine 原生支持 |
Initialization#
Pytorch |
MegEngine |
Comment |
---|---|---|
_calculate_fan_in_and_fan_out |
||
_calculate_correct_fan |
||
卷积层#
Pytorch |
MegEngine |
Comment |
---|---|---|
LocalConv2d |
||
DeformableConv2d |
||
池化层#
Pytorch |
MegEngine |
Comment |
---|---|---|
Padding Layers#
Pytorch |
MegEngine |
Comment |
---|---|---|
mode = REFLECT |
||
mode = REFLECT |
||
mode = REFLECT |
||
mode = EDGE |
||
mode = EDGE |
||
mode = EDGE |
||
mode = CONSTANT |
||
mode = CONSTANT |
||
mode = CONSTANT |
||
mode = CONSTANT |
非线性激活层#
Pytorch |
MegEngine |
Comment |
---|---|---|
归一化层#
Pytorch |
MegEngine |
Comment |
---|---|---|
Recurrent Layers#
Pytorch |
MegEngine |
Comment |
---|---|---|
|
||
Transformer Layers#
Pytorch |
MegEngine |
Comment |
---|---|---|
线性变化层#
Pytorch |
MegEngine |
Comment |
---|---|---|
Droupout 层#
Pytorch |
MegEngine |
Comment |
---|---|---|
Sparse 层#
Pytorch |
MegEngine |
Comment |
---|---|---|
Distance Functions#
Pytorch |
MegEngine |
Comment |
---|---|---|
Loss Functions#
参见
请参考 loss function 的 functional 实现。
Pytorch |
MegEngine |
Comment |
---|---|---|
Vision functions#
Pytorch |
MegEngine |
Comment |
---|---|---|
|
||
|
||
|
OpenCV Python Package#
Pytorch |
MegEngine |
Comment |
---|---|---|
cvtColor |
||
resize |
||
remap |
||
warpAffine |
||
warpPerspective |
NVIDIA#
Pytorch |
MegEngine |
Comment |
---|---|---|
correlation |
||
nvof |
未实施#
备注
一些 API 在 MegEngine 中可能还没有实现,但所有的 API 并不是一开始就被设计出来的。 我们可以像搭积木一样,利用已经存在的基础 API 来组合出 MegEngine 中尚未提供的接口。
比如 “如何实现 roll
” 这个问题,可以使用 split
和 concat
拼接出来:
import megengine.functional as F
def roll(x, shifts, axis):
shp = x.shape
dim = len(shp)
if isinstance(shifts, int):
assert isinstance(axis, int)
shifts = [shifts]
axis = [axis]
assert len(shifts) == len(axis)
y = x
for i in range(len(shifts)):
axis_ = axis[i]
shift_ = shifts[i]
axis_t_ = axis_ + dim if axis_ < 0 else axis_
assert (
dim > axis_t_ >= 0
), "axis out of range (expected to be in range of [{}, {}], but got {})".format(
-dim, dim - 1, axis_
)
if shift_ == 0:
continue
size = shp[axis_t_]
if shift_ > 0:
a, b = F.split(y, [size - shift_,], axis=axis_t_)
else:
a, b = F.split(y, [-shift_,], axis=axis_t_)
y = F.concat((b, a), axis=axis_t_)
return y
除此之外,你可以尝试在 GitHub Issues 或论坛中针对 API 问题发起求助。
我们也欢迎你将自己实现的 API 以 Pull Request 的形式提交到 MegEngine 代码库中来~
备注
对于缺失的 Loss Funtions 算子,大都可自行设计实现。