# -*- coding: utf-8 -*-

"""
@date: 2020/12/4 下午3:21
@file: test_mobilenetv2_inverted_residual.py
@author: zj
@description: 
"""

import torch

from zcls.model.backbones.mobilenet.mobilenetv2_inverted_residual import MobileNetV2InvertedResidual


def test_mobilenetv2_inverted_residual():
    # 不进行下采样、不进行膨胀
    data = torch.randn(1, 32, 112, 112)
    inplanes = 32
    planes = 16
    stride = 1
    model = MobileNetV2InvertedResidual(inplanes,
                                        planes,
                                        stride=stride,
                                        expansion_rate=1.0)
    print(model)

    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 16, 112, 112)

    # 进行下采样，进行膨胀
    data = torch.randn(1, 16, 112, 112)
    inplanes = 16
    planes = 24
    stride = 2
    model = MobileNetV2InvertedResidual(inplanes,
                                        planes,
                                        stride=stride,
                                        expansion_rate=6.0)
    print(model)

    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 24, 56, 56)

    # 不进行下采样、进行膨胀
    data = torch.randn(1, 24, 56, 56)
    inplanes = 24
    planes = 24
    stride = 1
    model = MobileNetV2InvertedResidual(inplanes,
                                        planes,
                                        stride=stride,
                                        expansion_rate=6.0)
    print(model)

    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 24, 56, 56)


if __name__ == '__main__':
    test_mobilenetv2_inverted_residual()

4dd49c0d161d6691342ef9ddf413d4b5e28d457d
<mask token>

<mask token>


def test_mobilenetv2_inverted_residual():
    data = torch.randn(1, 32, 112, 112)
    inplanes = 32
    planes = 16
    stride = 1
    model = MobileNetV2InvertedResidual(inplanes, planes, stride=stride,
        expansion_rate=1.0)
    print(model)
    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 16, 112, 112)
    data = torch.randn(1, 16, 112, 112)
    inplanes = 16
    planes = 24
    stride = 2
    model = MobileNetV2InvertedResidual(inplanes, planes, stride=stride,
        expansion_rate=6.0)
    print(model)
    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 24, 56, 56)
    data = torch.randn(1, 24, 56, 56)
    inplanes = 24
    planes = 24
    stride = 1
    model = MobileNetV2InvertedResidual(inplanes, planes, stride=stride,
        expansion_rate=6.0)
    print(model)
    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 24, 56, 56)


<mask token>

<mask token>


def test_mobilenetv2_inverted_residual():
    data = torch.randn(1, 32, 112, 112)
    inplanes = 32
    planes = 16
    stride = 1
    model = MobileNetV2InvertedResidual(inplanes, planes, stride=stride,
        expansion_rate=1.0)
    print(model)
    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 16, 112, 112)
    data = torch.randn(1, 16, 112, 112)
    inplanes = 16
    planes = 24
    stride = 2
    model = MobileNetV2InvertedResidual(inplanes, planes, stride=stride,
        expansion_rate=6.0)
    print(model)
    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 24, 56, 56)
    data = torch.randn(1, 24, 56, 56)
    inplanes = 24
    planes = 24
    stride = 1
    model = MobileNetV2InvertedResidual(inplanes, planes, stride=stride,
        expansion_rate=6.0)
    print(model)
    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 24, 56, 56)


if __name__ == '__main__':
    test_mobilenetv2_inverted_residual()

<mask token>
import torch
from zcls.model.backbones.mobilenet.mobilenetv2_inverted_residual import MobileNetV2InvertedResidual


def test_mobilenetv2_inverted_residual():
    data = torch.randn(1, 32, 112, 112)
    inplanes = 32
    planes = 16
    stride = 1
    model = MobileNetV2InvertedResidual(inplanes, planes, stride=stride,
        expansion_rate=1.0)
    print(model)
    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 16, 112, 112)
    data = torch.randn(1, 16, 112, 112)
    inplanes = 16
    planes = 24
    stride = 2
    model = MobileNetV2InvertedResidual(inplanes, planes, stride=stride,
        expansion_rate=6.0)
    print(model)
    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 24, 56, 56)
    data = torch.randn(1, 24, 56, 56)
    inplanes = 24
    planes = 24
    stride = 1
    model = MobileNetV2InvertedResidual(inplanes, planes, stride=stride,
        expansion_rate=6.0)
    print(model)
    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 24, 56, 56)


if __name__ == '__main__':
    test_mobilenetv2_inverted_residual()

# -*- coding: utf-8 -*-

"""
@date: 2020/12/4 下午3:21
@file: test_mobilenetv2_inverted_residual.py
@author: zj
@description: 
"""

import torch

from zcls.model.backbones.mobilenet.mobilenetv2_inverted_residual import MobileNetV2InvertedResidual


def test_mobilenetv2_inverted_residual():
    # 不进行下采样、不进行膨胀
    data = torch.randn(1, 32, 112, 112)
    inplanes = 32
    planes = 16
    stride = 1
    model = MobileNetV2InvertedResidual(inplanes,
                                        planes,
                                        stride=stride,
                                        expansion_rate=1.0)
    print(model)

    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 16, 112, 112)

    # 进行下采样，进行膨胀
    data = torch.randn(1, 16, 112, 112)
    inplanes = 16
    planes = 24
    stride = 2
    model = MobileNetV2InvertedResidual(inplanes,
                                        planes,
                                        stride=stride,
                                        expansion_rate=6.0)
    print(model)

    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 24, 56, 56)

    # 不进行下采样、进行膨胀
    data = torch.randn(1, 24, 56, 56)
    inplanes = 24
    planes = 24
    stride = 1
    model = MobileNetV2InvertedResidual(inplanes,
                                        planes,
                                        stride=stride,
                                        expansion_rate=6.0)
    print(model)

    outputs = model(data)
    print(outputs.shape)
    assert outputs.shape == (1, 24, 56, 56)


if __name__ == '__main__':
    test_mobilenetv2_inverted_residual()
