autodl-projects/tests/test_tas.py

25 lines
845 B
Python
Raw Normal View History

2021-05-19 10:10:42 +02:00
##################################################
# Copyright (c) Xuanyi Dong [GitHub D-X-Y], 2019 #
##################################################
import torch
import torch.nn as nn
2021-05-19 10:38:21 +02:00
import unittest
2021-05-19 10:10:42 +02:00
from xautodl.models.shape_searchs.SoftSelect import ChannelWiseInter
class TestTASFunc(unittest.TestCase):
"""Test the TAS function."""
def test_channel_interplation(self):
tensors = torch.rand((16, 128, 7, 7))
for oc in range(200, 210):
out_v1 = ChannelWiseInter(tensors, oc, "v1")
out_v2 = ChannelWiseInter(tensors, oc, "v2")
assert (out_v1 == out_v2).any().item() == 1
for oc in range(48, 160):
out_v1 = ChannelWiseInter(tensors, oc, "v1")
out_v2 = ChannelWiseInter(tensors, oc, "v2")
assert (out_v1 == out_v2).any().item() == 1