ncnn
ncnn copied to clipboard
pnnx 转换 ECA-attention 结果不对
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)
- 转出来的模型结果为常数,修复 layer Tensor.expand_as not exists or registered 问题后还是会出错