ncnn icon indicating copy to clipboard operation
ncnn copied to clipboard

pnnx 转换 ECA-attention 结果不对

Open gs-ren opened this issue 2 years ago • 0 comments

error log | 日志或报错信息 | ログ

context | 编译/运行环境 | バックグラウンド

pnnx version:pnnx-20220720-windows ncnn version:pyhton 版本,pip 安装的,1.0.20220729

how to reproduce | 复现步骤 | 再現方法

1.模型取自 https://github.com/BangguWu/ECANet/blob/master/models/eca_mobilenetv2.py

import torch
from torch import nn
from torch.nn.parameter import Parameter

class eca_layer(nn.Module):
    """Constructs a ECA module.
    Args:
        channel: Number of channels of the input feature map
        k_size: Adaptive selection of kernel size
    """
    def __init__(self, channel, k_size=3):
        super(eca_layer, self).__init__()
        self.avg_pool = nn.AdaptiveAvgPool2d(1)
        self.conv = nn.Conv1d(1, 1, kernel_size=k_size, padding=(k_size - 1) // 2, bias=False) 
        self.sigmoid = nn.Sigmoid()

    def forward(self, x):
        # feature descriptor on the global spatial information
        y = self.avg_pool(x)

        # Two different branches of ECA module
        y = self.conv(y.squeeze(-1).transpose(-1, -2)).transpose(-1, -2).unsqueeze(-1)

        # Multi-scale information fusion
        y = self.sigmoid(y)

        return x * y.expand_as(x)
  1. 转出来的模型结果为常数,修复 layer Tensor.expand_as not exists or registered 问题后还是会出错

more | 其他 | その他

gs-ren avatar Aug 12 '22 09:08 gs-ren