-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathtest_pixel_shuffle.py
99 lines (76 loc) · 3.47 KB
/
test_pixel_shuffle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright (C) 2018-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import numpy as np
import pytest
from pytorch_layer_test_class import PytorchLayerTest
class TestPixelShuffle(PytorchLayerTest):
def _prepare_input(self):
return (np.random.randn(*self.shape).astype(np.float32),)
def create_model(self, upscale_factor):
import torch
import torch.nn.functional as F
class aten_pixel_shuffle(torch.nn.Module):
def __init__(self, upscale_factor):
super(aten_pixel_shuffle, self).__init__()
self.upscale_factor = upscale_factor
def forward(self, x):
return F.pixel_shuffle(x, self.upscale_factor)
return aten_pixel_shuffle(upscale_factor), None, "aten::pixel_shuffle"
@pytest.mark.parametrize(("upscale_factor,shape"), [(3, [1, 9, 4, 4]),
(2, [1, 2, 3, 8, 4, 4]),])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_pixel_shuffle(self, upscale_factor, shape, ie_device, precision, ir_version):
self.shape = shape
self._test(*self.create_model(upscale_factor),
ie_device, precision, ir_version)
class TestPixelUnshuffle(PytorchLayerTest):
def _prepare_input(self):
return (np.random.randn(*self.shape).astype(np.float32),)
def create_model(self, upscale_factor):
import torch
import torch.nn.functional as F
class aten_pixel_unshuffle(torch.nn.Module):
def __init__(self, upscale_factor):
super(aten_pixel_unshuffle, self).__init__()
self.upscale_factor = upscale_factor
def forward(self, x):
return F.pixel_unshuffle(x, self.upscale_factor)
return aten_pixel_unshuffle(upscale_factor), None, "aten::pixel_unshuffle"
@pytest.mark.parametrize(("upscale_factor,shape"), [(3, [1, 1, 12, 12]),
(2, [1, 2, 3, 2, 8, 8]),])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_pixel_unshuffle(self, upscale_factor, shape, ie_device, precision, ir_version):
self.shape = shape
self._test(*self.create_model(upscale_factor),
ie_device, precision, ir_version)
class TestChannelShuffle(PytorchLayerTest):
def _prepare_input(self):
return (np.random.randn(*self.shape).astype(np.float32),)
def create_model(self, groups):
import torch
import torch.nn.functional as F
class aten_channel_shuffle(torch.nn.Module):
def __init__(self, upscale_factor):
super(aten_channel_shuffle, self).__init__()
self.upscale_factor = upscale_factor
def forward(self, x):
return F.channel_shuffle(x, self.upscale_factor)
return aten_channel_shuffle(groups), None, "aten::channel_shuffle"
@pytest.mark.parametrize(("groups,shape"), [
(3, [1, 9, 4, 4]),
(2, [1, 8, 8, 4, 4]),
(4, [4, 4, 2]),
(5, [4, 10, 2, 10, 1, 1]),
(1, [2, 3, 4])
])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_channel_shuffle(self, groups, shape, ie_device, precision, ir_version):
self.shape = shape
self._test(*self.create_model(groups),
ie_device, precision, ir_version)