|
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # -------------------
- # @Version : 1.0
- # @Author : xingchaolong
- # @For :
- # -------------------
- from __future__ import absolute_import
- from __future__ import division
- from __future__ import print_function
-
- import numpy as np
- import mindspore as ms
-
- import torch
-
- from mindspore import nn
-
-
- def check_conv_1():
- data = np.random.rand(2, 3, 16, 16).astype(np.float32)
-
- m_t = ms.Tensor(data, dtype=ms.float32)
- t_t = torch.Tensor(data)
-
- m_conv = nn.Conv2d(3, 3, 3, 1, pad_mode="pad", padding=9, has_bias=False, dilation=3, group=3)
- t_conv = torch.nn.Conv2d(3, 3, 3, 1, 9, bias=False, dilation=3, groups=3)
-
- m_out = m_conv(m_t)
- print(m_out.shape, flush=True)
-
- t_out = t_conv(t_t)
- print(t_out.shape, flush=True)
-
- # print("====== m_out ======\n{}".format(m_out), flush=True)
- # print("====== t_out ======\n{}".format(t_out), flush=True)
-
-
- def check_conv_2():
- data = np.random.rand(2, 3, 4, 4).astype(np.float32)
-
- m_t = ms.Tensor(data, dtype=ms.float32)
- t_t = torch.Tensor(data)
-
- m_conv = nn.Conv2d(3, 3, 3, 1, pad_mode="pad", padding=2, has_bias=True)
- t_conv = torch.nn.Conv2d(3, 3, 3, 1, 2, bias=True)
-
- m_out = m_conv(m_t)
- print(m_out.shape, flush=True)
-
- t_out = t_conv(t_t)
- print(t_out.shape, flush=True)
-
-
- if __name__ == "__main__":
- check_conv_1()
|