模块：import torch
import torch.nn as nn

# Channel Attention
class ChannelAttention(nn.Module):
    def __init__(self, in_planes, ratio=16):
        super(ChannelAttention, self).__init__()
        # 使用 max 确保至少为 1
        reduced_planes = max(1, in_planes // ratio)
        self.max_pool = nn.AdaptiveMaxPool2d(1)
        self.fc1 = nn.Conv2d(in_planes, reduced_planes, 1, bias=False)
        self.relu1 = nn.ReLU()
        self.fc2 = nn.Conv2d(reduced_planes, in_planes, 1, bias=False)
        self.sigmoid = nn.Sigmoid()

    def forward(self, x):
        max_out = self.fc2(self.relu1(self.fc1(self.max_pool(x))))
        return self.sigmoid(max_out)

# Spatial Attention
class SpatialAttention(nn.Module):
    def __init__(self, kernel_size=7):
        super(SpatialAttention, self).__init__()

        assert kernel_size in (3, 7), 'kernel size must be 3 or 7'
        padding = 3 if kernel_size == 7 else 1

        self.conv1 = nn.Conv2d(1, 1, kernel_size, padding=padding, bias=False)
        self.sigmoid = nn.Sigmoid()

    def forward(self, x):
        max_out, _ = torch.max(x, dim=1, keepdim=True)
        x = max_out
        x = self.conv1(x)
        return self.sigmoid(x)
    
### 应用两次 通道注意力

class HinResBlock(nn.Module):
    def __init__(self, in_size, out_size, relu_slope=0.2, use_HIN=True):
        super(HinResBlock, self).__init__()

        self.identity = nn.Conv2d(in_size, out_size, 1, 1, 0)
        self.conv_1x1 = nn.Conv2d(in_size, out_size, kernel_size=1, padding=0, bias=True)
        self.conv_3x3 = nn.Conv2d(in_size, out_size, kernel_size=3, padding=1, bias=True)
        self.conv_5x5 = nn.Conv2d(in_size, out_size, kernel_size=5, padding=2, bias=True)
        self.relu = nn.LeakyReLU(relu_slope, inplace=False)
        self.conv_2 = nn.Conv2d(out_size * 3, out_size, kernel_size=3, padding=1, bias=True)
        self.norm = nn.InstanceNorm2d(2, affine=True)

        # FEAM modules
        self.atten_channel_initial = ChannelAttention(out_size * 3)
        self.atten_spatial = SpatialAttention()

    def forward(self, x):
        scale_1 = self.conv_1x1(x)
        scale_2 = self.conv_3x3(x)
        scale_3 = self.conv_5x5(x)
        
        scale_1 = scale_1 * self.atten_spatial(scale_1) + scale_1
        scale_2 = scale_2 * self.atten_spatial(scale_2) + scale_2
        scale_3 = scale_3 * self.atten_spatial(scale_3) + scale_3
        
        resi = torch.cat([scale_1, scale_2, scale_3], dim=1)
        
        resi = resi * self.atten_channel_initial(resi) + resi
        resi = self.relu(resi)
        resi = self.relu(self.conv_2(resi))
        
        out_1, out_2 = torch.chunk(resi, 2, dim=1)

        resi = torch.cat([self.norm(out_1), out_2], dim=1)
        output = x + resi
        return output


，被调用：self.num_classes = num_classes
        self.d_model = self.num_features = self.embed_dim = embed_dim  # num_features for consistency with other models
        base_filter=32
        self.hin_block = nn.Sequential(
            nn.Conv2d(channels, base_filter, kernel_size=3, stride=1, padding=1),
            HinResBlock(base_filter, base_filter),  # 第一个 HinResBlock
            HinResBlock(base_filter, base_filter),  # 第二个 HinResBlock
            HinResBlock(base_filter, base_filter),  # 第三个 HinResBlock
            nn.Conv2d(base_filter, channels, kernel_size=1)  # 将通道数从32转换为3
        )                 def forward_features(self, z, x, inference_params=None, if_random_cls_token_position=False, if_random_token_rank=False):
        x = self.hin_block(x)
        z = self.hin_block(z)，报错：Traceback for the error!
Traceback (most recent call last):
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/train/trainers/base_trainer.py", line 85, in train
    self.train_epoch()
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/train/trainers/ltr_trainer.py", line 133, in train_epoch
    self.cycle_dataset(loader)
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/train/trainers/ltr_trainer.py", line 86, in cycle_dataset
    loss, stats = self.actor(data)
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/train/actors/mamba_fetrack.py", line 31, in __call__
    out_dict = self.forward_pass(data)
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/train/actors/mamba_fetrack.py", line 74, in forward_pass
    out_dict = self.net(template=template_list,
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/parallel/distributed.py", line 1519, in forward
    else self._run_ddp_forward(*inputs, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/parallel/distributed.py", line 1355, in _run_ddp_forward
    return self.module(*inputs, **kwargs)  # type: ignore[index]
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/models/mamba_fetrack/mamba_fetrack.py", line 51, in forward
    rgb_feature = self.backbone.forward_features( z=template, x=search,
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/models/mamba_fetrack/models_mamba.py", line 412, in forward_features
    x = self.hin_block(x)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/container.py", line 215, in forward
    input = module(input)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/models/mamba_fetrack/HinBlock.py", line 72, in forward
    resi = torch.cat([self.norm(out_1), out_2], dim=1)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/instancenorm.py", line 76, in forward
    raise ValueError(
ValueError: expected input's size at dim=1 to match num_features (2), but got: 16.

Restarting training from last epoch ...
Finished training!
Training crashed at epoch 1
Traceback for the error!
Traceback (most recent call last):
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/train/trainers/base_trainer.py", line 85, in train
    self.train_epoch()
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/train/trainers/ltr_trainer.py", line 133, in train_epoch
    self.cycle_dataset(loader)
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/train/trainers/ltr_trainer.py", line 86, in cycle_dataset
    loss, stats = self.actor(data)
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/train/actors/mamba_fetrack.py", line 31, in __call__
    out_dict = self.forward_pass(data)
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/train/actors/mamba_fetrack.py", line 74, in forward_pass
    out_dict = self.net(template=template_list,
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/parallel/distributed.py", line 1519, in forward
    else self._run_ddp_forward(*inputs, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/parallel/distributed.py", line 1355, in _run_ddp_forward
    return self.module(*inputs, **kwargs)  # type: ignore[index]
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/models/mamba_fetrack/mamba_fetrack.py", line 51, in forward
    rgb_feature = self.backbone.forward_features( z=template, x=search,
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/models/mamba_fetrack/models_mamba.py", line 412, in forward_features
    x = self.hin_block(x)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/container.py", line 215, in forward
    input = module(input)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "/data2/local_userdata/heyuting/Mamba/MyFETrack/lib/train/../../lib/models/mamba_fetrack/HinBlock.py", line 72, in forward
    resi = torch.cat([self.norm(out_1), out_2], dim=1)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/heyuting/anaconda3/envs/mamba/lib/python3.10/site-packages/torch/nn/modules/instancenorm.py", line 76, in forward
    raise ValueError(
ValueError: expected input's size at dim=1 to match num_features (2), but got: 16.

Restarting training from last epoch ...
Finished training!