文档反馈

问题文档片段

问题文档片段包含公式时,显示为空格。

提交类型
issue

有点复杂...

找人问问吧。

PR

小问题,全程线上修改...

一键搞定!

请选择提交类型

问题类型
规范和低错类

- 规范和低错类:

- 错别字或拼写错误,标点符号使用错误、公式错误或显示异常。

- 链接错误、空单元格、格式错误。

- 英文中包含中文字符。

- 界面和描述不一致,但不影响操作。

- 表述不通顺,但不影响理解。

- 版本号不匹配:如软件包名称、界面版本号。

易用性

- 易用性:

- 关键步骤错误或缺失,无法指导用户完成任务。

- 缺少主要功能描述、关键词解释、必要前提条件、注意事项等。

- 描述内容存在歧义指代不明、上下文矛盾。

- 逻辑不清晰,该分类、分项、分步骤的没有给出。

正确性

- 正确性:

- 技术原理、功能、支持平台、参数类型、异常报错等描述和软件实现不一致。

- 原理图、架构图等存在错误。

- 命令、命令参数等错误。

- 代码片段错误。

- 命令无法完成对应功能。

- 界面错误,无法指导操作。

- 代码样例运行报错、运行结果不符。

风险提示

- 风险提示:

- 对重要数据或系统存在风险的操作,缺少安全提示。

内容合规

- 内容合规:

- 违反法律法规,涉及政治、领土主权等敏感词。

- 内容侵权。

请选择问题类型

问题描述

点击输入详细问题描述,以帮助我们快速定位问题。

比较与torchvision.ops.deform_conv2d的差异

查看源文件

torchvision.ops.deform_conv2d

class torchvision.ops.deform_conv2d(
    input,
    offset,
    weight,
    bias=None,
    stride=(1, 1),
    padding=(0, 0),
    dilations=(1, 1),
    mask=None
)

更多内容详见torchvision.ops.deform_conv2d.

mindspore.ops.deformable_conv2d

class mindspore.ops.deformable_conv2d(
    x,
    weight,
    offsets,
    kernel_size,
    strides,
    padding,
    bias=None,
    dilations=(1, 1, 1, 1),
    groups=1,
    deformable_groups=1,
    modulated=True
)

更多内容详见mindspore.ops.deformable_conv2d.

差异对比

PyTorch: 参数offsets是一个四维Tensor,存储x和y坐标的偏移。数据格式为“NCHW”,shape为(batch,deformablegroups×H×W×2,Hout ,Wout ),注意其中C维度的存储顺序为(deformablegroups,H,W,(offsety,offsetx))。参数mask是一个四维Tensor,存储可变形卷积的输入掩码mask。数据格式为“NCHW”,shape为(batch,deformablegroups×H×W×1,Hout ,Wout ),注意其中C维度的存储顺序为(deformablegroups,Hf,Wf,mask)

MindSpore: 一个四维Tensor,存储x和y坐标的偏移,以及可变形卷积的输入掩码mask。数据格式为“NCHW”,shape为(batch,3×deformablegroups×H×W,Hout ,Wout ),注意其中C维度的存储顺序为((offsetx,offsety,mask),deformablegroups,Hf,Wf)

分类

子类

PyTorch

MindSpore

差异

参数

参数1

input

x

功能一致,参数名不同

参数2

offset

offsets

MindSpore的offsets参数包含PyTorch的offset和mask两个参数

参数3

weight

weight

-

参数4

-

kernel_size

Pytorch无此参数

参数5

mask

-

MindSpore无此参数

参数6

bias

bias

-

参数7

stride

strides

功能一致,参数名不同

参数8

padding

padding

-

参数9

dilations

dilations

-

参数10

-

groups

Pytorch无此参数

参数11

-

deformable_groups

Pytorch无此参数

参数12

-

modulated

Pytorch无此参数

代码示例

# PyTorch
import torch
from torch import tensor
import numpy as np
from torchvision.ops import deform_conv2d
np.random.seed(1)
kh, kw = 1, 1
batch = 1
deformable_groups = 1
stride_h, stride_w = 1, 1
dilation_h, dilation_w = 1, 1
pad_h, pad_w = 0, 0
x_h, x_w = 1, 2
out_h = (x_h + 2 * pad_h - dilation_h * (kh - 1) - 1) // stride_h + 1
out_w = (x_w + 2 * pad_w - dilation_w * (kw - 1) - 1) // stride_w + 1

x = np.random.randn(batch, 64, x_h, x_w).astype(np.float32)
weight = np.random.randn(batch, 64, kh, kw).astype(np.float32)
offsets_x = np.random.randn(batch, 1, deformable_groups, kh, kw, out_h, out_w).astype(np.float32)
offsets_y = np.random.randn(batch, 1, deformable_groups, kh, kw, out_h, out_w).astype(np.float32)
mask = np.random.randn(batch, 1, deformable_groups, kh, kw, out_h, out_w).astype(np.float32)

offsets = np.concatenate((offsets_y, offsets_x), axis=1)
offsets = offsets.transpose(0, 2, 3, 4, 1, 5, 6)
offsets = offsets.reshape((batch, 2 * deformable_groups * kh * kw, out_h, out_w))
mask = mask.transpose(0, 2, 3, 4, 1, 5, 6)
mask = mask.reshape((batch, 1 * deformable_groups * kh * kw, out_h, out_w))
x = torch.from_numpy(x.copy().astype(np.float32))
weight = torch.from_numpy(weight.copy().astype(np.float32))
offsets = torch.from_numpy(offsets.copy().astype(np.float32))
mask = torch.from_numpy(mask.copy().astype(np.float32))
output = deform_conv2d(x, offsets, weight, stride=(stride_h, stride_w), padding=(pad_h, pad_w), dilation=(dilation_h, dilation_w), mask=mask)
print(output)
# tensor([[[[-0.0022,  0.0000]]]])

# MindSpore
import mindspore
from mindspore import Tensor
import mindspore.nn as nn
import numpy as np
from mindspore.ops import deformable_conv2d
import mindspore.ops as ops
np.random.seed(1)
kh, kw = 1, 1
batch = 1
deformable_groups = 1
stride_h, stride_w = 1, 1
dilation_h, dilation_w = 1, 1
pad_h, pad_w = 0, 0
x_h, x_w = 1, 2
out_h = (x_h + 2 * pad_h - dilation_h * (kh - 1) - 1) // stride_h + 1
out_w = (x_w + 2 * pad_w - dilation_w * (kw - 1) - 1) // stride_w + 1

x = np.random.randn(batch, 64, x_h, x_w).astype(np.float32)
weight = np.random.randn(batch, 64, kh, kw).astype(np.float32)
offsets_x = np.random.randn(batch, 1, deformable_groups, kh, kw, out_h, out_w).astype(np.float32)
offsets_y = np.random.randn(batch, 1, deformable_groups, kh, kw, out_h, out_w).astype(np.float32)
mask = np.random.randn(batch, 1, deformable_groups, kh, kw, out_h, out_w).astype(np.float32)

offsets = np.concatenate((offsets_x, offsets_y, mask), axis=1)
offsets = offsets.reshape((batch, 3 * deformable_groups * kh * kw, out_h, out_w))

x = Tensor(x)
weight = Tensor(weight)
offsets = Tensor(offsets)
output = ops.deformable_conv2d(x, weight, offsets, (kh, kw), (1, 1, stride_h, stride_w,), (pad_h, pad_h, pad_w, pad_w), dilations=(1, 1, dilation_h, dilation_w))
print(output)
# [[[[-0.00220442  0.        ]]]]