【AI达人特训营】AdaptFormer:一种新型fine-tuning方法复现

AdaptFormer由港大等机构提出,旨在解决大型视觉模型微调的算力和存储负担问题。其让网络及权重在多下游任务中尽可能保持一致,仅训练少量参数。通过在Transformer的MHSA层并行添加可学习模块,在Cifar100预训练后迁移至Cifar10,冻结网络时参数量大幅减少,准确率却更高,展现出在迁移学习中的优越性。

☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜

【ai达人特训营】adaptformer:一种新型fine-tuning方法复现 - 创想鸟

AdaptFormer

论文地址:https://arxiv.org/abs/2205.13535

简介:

港大,腾讯AI实验室,港中文贡献的文章:AdaptFormer: Adapting Vision Transformers for Scalable Visual Recognition. 研究人员认为最新的transformer文章做的是same network with task-specific weight工作,用的是同样的网络,但是对每个下游任务都要fine-tune模型,这样的模型是不可拓展的,每搞一个数据集就要在上边fully finetune, 尤其是现在像ViT-G/14这样有18亿参数的大模型,训练时的算力和存储负担很重。所以他们要搞same network with almost same weights, 不仅网络要一样,应用到下游任务,权重也尽可能一样。只需要训练很少的参数,其他大部分参数是固定的,这些固定的参数就可以跨任务共享。

要做这件事需要构建一种高效的pileline去适配预训练模型到许多下游任务,他们的工作更像VPT (Visual Prompt Tuning),VPT在patch embedding那里增加可学习的参数同时冻结整个主干只finetuen embedding部分,但本项目所作的工作能够大大超越VPT,如下图所示:

【AI达人特训营】AdaptFormer:一种新型fine-tuning方法复现 - 创想鸟        

AdaptFormer方法在SSv2数据集上全面打败了VPT

本文的方法和VPT不同的地方在于,AdaptFormer是加到Transformer的MHSA(multi-head self-attention layer)上:

【AI达人特训营】AdaptFormer:一种新型fine-tuning方法复现 - 创想鸟        

下图为在各种数据集上本方法与VPT等方法的对比:

【AI达人特训营】AdaptFormer:一种新型fine-tuning方法复现 - 创想鸟        

最后文章希望可以激励更多研究者探索更加高效的fine-tuning方法到大型视觉模型上。

数据集介绍:Cifar100

链接:http://www.cs.toronto.edu/~kriz/cifar.html

【AI达人特训营】AdaptFormer:一种新型fine-tuning方法复现 - 创想鸟        

CIFAR100数据集有100个类。每个类有600张大小为32 × 32 32times 3232×32的彩色图像,其中500张作为训练集,100张作为测试集。

数据集介绍:Cifar10

链接:http://www.cs.toronto.edu/~kriz/cifar.html

【AI达人特训营】AdaptFormer:一种新型fine-tuning方法复现 - 创想鸟        

CIFAR-10是一个更接近普适物体的彩色图像数据集。CIFAR-10 是由Hinton 的学生Alex Krizhevsky 和Ilya Sutskever 整理的一个用于识别普适物体的小型数据集。一共包含10 个类别的RGB彩色图片:飞机(airplane)、汽车(automobile)、鸟类(bird)、猫(cat)、鹿(deer)、狗(dog)、蛙类(frog)、马(horse)、船(ship)和卡车(truck).

每个图片的尺寸为 32×3232×32,每个类别有6000个图像,数据集中一共有50000张训练图片和10000张测试图片。

代码复现

1.引入依赖包

In [ ]

from __future__ import divisionfrom __future__ import print_functionimport paddle.nn as nnfrom paddle.nn import functional as Ffrom paddle.utils.download import get_weights_path_from_urlimport pickleimport numpy as npfrom paddle import callbacksfrom paddle.vision.transforms import (    ToTensor, RandomHorizontalFlip, RandomResizedCrop, SaturationTransform, Compose,    HueTransform, BrightnessTransform, ContrastTransform, RandomCrop, Normalize, RandomRotation, Resize)from paddle.vision.datasets import Cifar10, Cifar100from paddle.io import DataLoaderfrom paddle.optimizer.lr import CosineAnnealingDecay, MultiStepDecay, LinearWarmupimport randomimport osimport numpy as npimport cv2from PIL import Imageimport matplotlib.pyplot as pltimport paddlefrom paddle.io import Datasetfrom paddle.nn import Conv2D, MaxPool2D, Linear, Dropout, BatchNorm, AdaptiveAvgPool2D, AvgPool2Dimport paddle.nn.functional as Fimport paddle.nn as nnIS_STOP_GRADIENT = False

   

2.图像分块嵌入

In [2]

# 图像分块、Embeddingclass PatchEmbed(nn.Layer):    def __init__(self, img_size=224, patch_size=16, in_chans=3, embed_dim=768):        super().__init__()        # 原始大小为int,转为tuple,即:img_size原始输入224,变换后为[224,224]        img_size = to_2tuple(img_size)        patch_size = to_2tuple(patch_size)        # 图像块的个数        num_patches = (img_size[1] // patch_size[1]) *             (img_size[0] // patch_size[0])        self.img_size = img_size        self.patch_size = patch_size        self.num_patches = num_patches        # kernel_size=块大小,即每个块输出一个值,类似每个块展平后使用相同的全连接层进行处理        # 输入维度为3,输出维度为块向量长度        # 与原文中:分块、展平、全连接降维保持一致        # 输出为[B, C, H, W]        self.proj = nn.Conv2D(            in_chans, embed_dim, kernel_size=patch_size, stride=patch_size)    def forward(self, x):        B, C, H, W = x.shape        assert H == self.img_size[0] and W == self.img_size[1],             "Input image size ({H}*{W}) doesn't match model ({self.img_size[0]}*{self.img_size[1]})."        # [B, C, H, W] -> [B, C, H*W] ->[B, H*W, C]        x = self.proj(x).flatten(2).transpose((0, 2, 1))        return x

   

3.Multi-head Attention

In [3]

class Attention(nn.Layer):    def __init__(self,                 dim,                 num_heads=8,                 qkv_bias=False,                 qk_scale=None,                 attn_drop=0.,                 proj_drop=0.):        super().__init__()        self.num_heads = num_heads        head_dim = dim // num_heads        self.scale = qk_scale or head_dim**-0.5        # 计算 q,k,v 的转移矩阵        self.qkv = nn.Linear(dim, dim * 3, bias_attr=qkv_bias)        self.attn_drop = nn.Dropout(attn_drop)        # 最终的线性层        self.proj = nn.Linear(dim, dim)        self.proj_drop = nn.Dropout(proj_drop)    def forward(self, x):        N, C = x.shape[1:]        # 线性变换        qkv = self.qkv(x).reshape((-1, N, 3, self.num_heads, C //                                   self.num_heads)).transpose((2, 0, 3, 1, 4))        # 分割 query key value        q, k, v = qkv[0], qkv[1], qkv[2]        # Scaled Dot-Product Attention        # Matmul + Scale        attn = (q.matmul(k.transpose((0, 1, 3, 2)))) * self.scale        # SoftMax        attn = nn.functional.softmax(attn, axis=-1)        attn = self.attn_drop(attn)        # Matmul        x = (attn.matmul(v)).transpose((0, 2, 1, 3)).reshape((-1, N, C))        # 线性变换        x = self.proj(x)        x = self.proj_drop(x)        return x

   

4.多层感知机

In [4]

class Mlp(nn.Layer):    def __init__(self,                 in_features,                 hidden_features=None,                 out_features=None,                 act_layer=nn.GELU,                 drop=0.):        super().__init__()        out_features = out_features or in_features        hidden_features = hidden_features or in_features        self.fc1 = nn.Linear(in_features, hidden_features)        self.act = act_layer()        self.fc2 = nn.Linear(hidden_features, out_features)        self.drop = nn.Dropout(drop)    def forward(self, x):        # 输入层:线性变换        x = self.fc1(x)        # 应用激活函数        x = self.act(x)        # Dropout        x = self.drop(x)        # 输出层:线性变换        x = self.fc2(x)        # Dropout        x = self.drop(x)        return x

   

5.基础模块

基于上面实现的 Attention、MLP 和下面的 DropPath 模块就可以组合出 Vision Transformer 模型的一个基础模块

In [5]

def drop_path(x, drop_prob=0., training=False):    if drop_prob == 0. or not training:        return x    keep_prob = paddle.to_tensor(1 - drop_prob)    shape = (paddle.shape(x)[0], ) + (1, ) * (x.ndim - 1)    random_tensor = keep_prob + paddle.rand(shape, dtype=x.dtype)    random_tensor = paddle.floor(random_tensor)    output = x.divide(keep_prob) * random_tensor    return outputclass DropPath(nn.Layer):    def __init__(self, drop_prob=None):        super(DropPath, self).__init__()        self.drop_prob = drop_prob    def forward(self, x):        return drop_path(x, self.drop_prob, self.training)

   

6.Block

AdaptFormer网络在Block中进行了更改,MLP层并行了Down Relu Up三层,并通过一个可学习的参数scale进行相加

Paddle中提供的stop_gradient函数有两个功能,对于输出的值,如:

x = self.norm(x)x.sotp_gradient = True

       

则在此层之前的所有参数均停止更新

Tweeze Tweeze

Tweeze.app是一个AI驱动的个性化新闻简报服务,定位为个人互联网AI阅读助手

Tweeze 76 查看详情 Tweeze

x = self.norm(x)self.norm.stop_gradient = True

       

则只停止这一层网络的参数更新

以上两种用法可以用以冻结网络
通过读取全局变量IS_STOP_GRADIENT决定是否冻结网络

关于此API的说明在官方文档中较少,后续可以进行补充

In [6]

class Block(nn.Layer):    def __init__(self,                 dim,                 num_heads,                 mlp_ratio=4.,                 qkv_bias=False,                 qk_scale=None,                 drop=0.,                 attn_drop=0.,                 drop_path=0.,                 act_layer=nn.GELU,                 norm_layer='nn.LayerNorm',                 epsilon=1e-5):        super().__init__()        self.norm1 = eval(norm_layer)(dim, epsilon=epsilon)        # Multi-head Self-attention        self.attn = Attention(            dim,            num_heads=num_heads,            qkv_bias=qkv_bias,            qk_scale=qk_scale,            attn_drop=attn_drop,            proj_drop=drop)        # DropPath        self.drop_path = DropPath(drop_path) if drop_path > 0. else Identity()        self.norm2 = eval(norm_layer)(dim, epsilon=epsilon)        mlp_hidden_dim = int(dim * mlp_ratio)        self.mlp = Mlp(in_features=dim,                       hidden_features=mlp_hidden_dim,                       act_layer=act_layer,                       drop=drop)        self.n_embd = 768        self.down_size = 64        self.down_proj = nn.Linear(self.n_embd, self.down_size)        self.non_linear_func = nn.ReLU()        self.up_proj = nn.Linear(self.down_size, self.n_embd)        self.scale = self.create_parameter(shape=(1, 1), default_initializer=nn.initializer.Constant(value=1.))    def forward(self, x):        # Multi-head Self-attention, Add, LayerNorm        ###        # 设置是否训练参数        ###        self.norm1.stop_gradient = IS_STOP_GRADIENT        self.attn.stop_gradient = IS_STOP_GRADIENT        x = x + self.drop_path(self.attn(self.norm1(x)))        # Feed Forward, Add, LayerNorm        residual = x        ###        # 设置是否训练norm层参数        ###        self.norm2.stop_gradient = IS_STOP_GRADIENT        x = self.norm2(x)        ###        # 设置是否训练MLP层参数        ###        self.mlp.stop_gradient = IS_STOP_GRADIENT                ###        # 以下几层为AdaptFormer改进的核心,迁移训练过程中参数不变        ###        down = self.down_proj(x)        down = self.non_linear_func(down)        down = nn.functional.dropout(down, p=0.1)        up = self.up_proj(down)        up = up * self.scale + self.mlp(x)        up = self.drop_path(up)        output = up + residual        return output

   

7.参数初始化配置、独立的不进行任何操作的网络层

In [7]

# 参数初始化配置trunc_normal_ = nn.initializer.TruncatedNormal(std=.02)zeros_ = nn.initializer.Constant(value=0.)ones_ = nn.initializer.Constant(value=1.)# 将输入 x 由 int 类型转为 tuple 类型def to_2tuple(x):    return tuple([x] * 2)# 定义一个什么操作都不进行的网络层class Identity(nn.Layer):    def __init__(self):        super(Identity, self).__init__()    def forward(self, input):        return input

   

8.完整代码

由于Cifar100数据集由32×3232×32的图像构成,图像大小偏小,故将ViT的patch_size 由16调整为3,能够提取图像更多的特征信息。
调整后模型在测试集上的准确率能够随epoch的增加迅速上升,并减少过拟合现象。

In [8]

class VisionTransformer(nn.Layer):    def __init__(self,                 img_size=32,                 patch_size=3,                 in_chans=3,                 class_dim=100,                 embed_dim=768,                 depth=12,                 num_heads=12,                 mlp_ratio=4,                 qkv_bias=False,                 qk_scale=None,                 drop_rate=0.,                 attn_drop_rate=0.,                 drop_path_rate=0.,                 norm_layer='nn.LayerNorm',                 epsilon=1e-5,                 **args):        super().__init__()        self.class_dim = class_dim        self.num_features = self.embed_dim = embed_dim        # 图片分块和降维,块大小为patch_size,最终块向量维度为768        self.patch_embed = PatchEmbed(            img_size=img_size,            patch_size=patch_size,            in_chans=in_chans,            embed_dim=embed_dim)        # 分块数量        num_patches = self.patch_embed.num_patches        # 可学习的位置编码        self.pos_embed = self.create_parameter(            shape=(1, num_patches + 1, embed_dim), default_initializer=zeros_)        self.add_parameter("pos_embed", self.pos_embed)        # 人为追加class token,并使用该向量进行分类预测        self.cls_token = self.create_parameter(            shape=(1, 1, embed_dim), default_initializer=zeros_)        self.add_parameter("cls_token", self.cls_token)        self.pos_drop = nn.Dropout(p=drop_rate)        dpr = np.linspace(0, drop_path_rate, depth)        # transformer        self.blocks = nn.LayerList([            Block(                dim=embed_dim,                num_heads=num_heads,                mlp_ratio=mlp_ratio,                qkv_bias=qkv_bias,                qk_scale=qk_scale,                drop=drop_rate,                attn_drop=attn_drop_rate,                drop_path=dpr[i],                norm_layer=norm_layer,                epsilon=epsilon) for i in range(depth)        ])        self.norm = eval(norm_layer)(embed_dim, epsilon=epsilon)        # Classifier head        self.head = nn.Linear(embed_dim,                              class_dim) if class_dim > 0 else Identity()        trunc_normal_(self.pos_embed)        trunc_normal_(self.cls_token)        self.apply(self._init_weights)    # 参数初始化    def _init_weights(self, m):        if isinstance(m, nn.Linear):            trunc_normal_(m.weight)            if isinstance(m, nn.Linear) and m.bias is not None:                zeros_(m.bias)        elif isinstance(m, nn.LayerNorm):            zeros_(m.bias)            ones_(m.weight)    # 获取图像特征    def forward_features(self, x):        B = paddle.shape(x)[0]        # 将图片分块,并调整每个块向量的维度        x = self.patch_embed(x)        # 将class token与前面的分块进行拼接        cls_tokens = self.cls_token.expand((B, -1, -1))        x = paddle.concat((cls_tokens, x), axis=1)        # 将编码向量中加入位置编码        x = x + self.pos_embed        x = self.pos_drop(x)        ###        # 设置是否冻结网络        ###        x.stop_gradient = IS_STOP_GRADIENT                # 堆叠 transformer 结构        for blk in self.blocks:            x = blk(x)        # LayerNorm        x = self.norm(x)        # 提取分类 tokens 的输出        return x[:, 0]    def forward(self, x):        # 获取图像特征        x = self.forward_features(x)        # 图像分类        x = self.head(x)        return x

   In [11]

# 测试vit = VisionTransformer()paddle.summary(vit, (1, 3, 32, 32))

       

--------------------------------------------------------------------------- Layer (type)       Input Shape          Output Shape         Param #    ===========================================================================   Conv2D-2       [[1, 3, 32, 32]]     [1, 768, 10, 10]       21,504      PatchEmbed-2     [[1, 3, 32, 32]]      [1, 100, 768]            0         Dropout-38      [[1, 101, 768]]       [1, 101, 768]            0        LayerNorm-26     [[1, 101, 768]]       [1, 101, 768]          1,536        Linear-74      [[1, 101, 768]]       [1, 101, 2304]       1,769,472     Dropout-39    [[1, 12, 101, 101]]   [1, 12, 101, 101]          0          Linear-75      [[1, 101, 768]]       [1, 101, 768]         590,592      Dropout-40      [[1, 101, 768]]       [1, 101, 768]            0        Attention-13     [[1, 101, 768]]       [1, 101, 768]            0         Identity-13     [[1, 101, 768]]       [1, 101, 768]            0        LayerNorm-27     [[1, 101, 768]]       [1, 101, 768]          1,536        Linear-78      [[1, 101, 768]]        [1, 101, 64]         49,216         ReLU-13        [[1, 101, 64]]        [1, 101, 64]            0          Linear-79       [[1, 101, 64]]       [1, 101, 768]         49,920        Linear-76      [[1, 101, 768]]       [1, 101, 3072]       2,362,368       GELU-13       [[1, 101, 3072]]      [1, 101, 3072]           0         Dropout-41      [[1, 101, 768]]       [1, 101, 768]            0          Linear-77      [[1, 101, 3072]]      [1, 101, 768]        2,360,064       Mlp-13        [[1, 101, 768]]       [1, 101, 768]            0          Block-13       [[1, 101, 768]]       [1, 101, 768]            1        LayerNorm-28     [[1, 101, 768]]       [1, 101, 768]          1,536        Linear-80      [[1, 101, 768]]       [1, 101, 2304]       1,769,472     Dropout-42    [[1, 12, 101, 101]]   [1, 12, 101, 101]          0          Linear-81      [[1, 101, 768]]       [1, 101, 768]         590,592      Dropout-43      [[1, 101, 768]]       [1, 101, 768]            0        Attention-14     [[1, 101, 768]]       [1, 101, 768]            0         Identity-14     [[1, 101, 768]]       [1, 101, 768]            0        LayerNorm-29     [[1, 101, 768]]       [1, 101, 768]          1,536        Linear-84      [[1, 101, 768]]        [1, 101, 64]         49,216         ReLU-14        [[1, 101, 64]]        [1, 101, 64]            0          Linear-85       [[1, 101, 64]]       [1, 101, 768]         49,920        Linear-82      [[1, 101, 768]]       [1, 101, 3072]       2,362,368       GELU-14       [[1, 101, 3072]]      [1, 101, 3072]           0         Dropout-44      [[1, 101, 768]]       [1, 101, 768]            0          Linear-83      [[1, 101, 3072]]      [1, 101, 768]        2,360,064       Mlp-14        [[1, 101, 768]]       [1, 101, 768]            0          Block-14       [[1, 101, 768]]       [1, 101, 768]            1        LayerNorm-30     [[1, 101, 768]]       [1, 101, 768]          1,536        Linear-86      [[1, 101, 768]]       [1, 101, 2304]       1,769,472     Dropout-45    [[1, 12, 101, 101]]   [1, 12, 101, 101]          0          Linear-87      [[1, 101, 768]]       [1, 101, 768]         590,592      Dropout-46      [[1, 101, 768]]       [1, 101, 768]            0        Attention-15     [[1, 101, 768]]       [1, 101, 768]            0         Identity-15     [[1, 101, 768]]       [1, 101, 768]            0        LayerNorm-31     [[1, 101, 768]]       [1, 101, 768]          1,536        Linear-90      [[1, 101, 768]]        [1, 101, 64]         49,216         ReLU-15        [[1, 101, 64]]        [1, 101, 64]            0          Linear-91       [[1, 101, 64]]       [1, 101, 768]         49,920        Linear-88      [[1, 101, 768]]       [1, 101, 3072]       2,362,368       GELU-15       [[1, 101, 3072]]      [1, 101, 3072]           0         Dropout-47      [[1, 101, 768]]       [1, 101, 768]            0          Linear-89      [[1, 101, 3072]]      [1, 101, 768]        2,360,064       Mlp-15        [[1, 101, 768]]       [1, 101, 768]            0          Block-15       [[1, 101, 768]]       [1, 101, 768]            1        LayerNorm-32     [[1, 101, 768]]       [1, 101, 768]          1,536        Linear-92      [[1, 101, 768]]       [1, 101, 2304]       1,769,472     Dropout-48    [[1, 12, 101, 101]]   [1, 12, 101, 101]          0          Linear-93      [[1, 101, 768]]       [1, 101, 768]         590,592      Dropout-49      [[1, 101, 768]]       [1, 101, 768]            0        Attention-16     [[1, 101, 768]]       [1, 101, 768]            0         Identity-16     [[1, 101, 768]]       [1, 101, 768]            0        LayerNorm-33     [[1, 101, 768]]       [1, 101, 768]          1,536        Linear-96      [[1, 101, 768]]        [1, 101, 64]         49,216         ReLU-16        [[1, 101, 64]]        [1, 101, 64]            0          Linear-97       [[1, 101, 64]]       [1, 101, 768]         49,920        Linear-94      [[1, 101, 768]]       [1, 101, 3072]       2,362,368       GELU-16       [[1, 101, 3072]]      [1, 101, 3072]           0         Dropout-50      [[1, 101, 768]]       [1, 101, 768]            0          Linear-95      [[1, 101, 3072]]      [1, 101, 768]        2,360,064       Mlp-16        [[1, 101, 768]]       [1, 101, 768]            0          Block-16       [[1, 101, 768]]       [1, 101, 768]            1        LayerNorm-34     [[1, 101, 768]]       [1, 101, 768]          1,536        Linear-98      [[1, 101, 768]]       [1, 101, 2304]       1,769,472     Dropout-51    [[1, 12, 101, 101]]   [1, 12, 101, 101]          0          Linear-99      [[1, 101, 768]]       [1, 101, 768]         590,592      Dropout-52      [[1, 101, 768]]       [1, 101, 768]            0        Attention-17     [[1, 101, 768]]       [1, 101, 768]            0         Identity-17     [[1, 101, 768]]       [1, 101, 768]            0        LayerNorm-35     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-102      [[1, 101, 768]]        [1, 101, 64]         49,216         ReLU-17        [[1, 101, 64]]        [1, 101, 64]            0         Linear-103       [[1, 101, 64]]       [1, 101, 768]         49,920       Linear-100      [[1, 101, 768]]       [1, 101, 3072]       2,362,368       GELU-17       [[1, 101, 3072]]      [1, 101, 3072]           0         Dropout-53      [[1, 101, 768]]       [1, 101, 768]            0         Linear-101      [[1, 101, 3072]]      [1, 101, 768]        2,360,064       Mlp-17        [[1, 101, 768]]       [1, 101, 768]            0          Block-17       [[1, 101, 768]]       [1, 101, 768]            1        LayerNorm-36     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-104      [[1, 101, 768]]       [1, 101, 2304]       1,769,472     Dropout-54    [[1, 12, 101, 101]]   [1, 12, 101, 101]          0         Linear-105      [[1, 101, 768]]       [1, 101, 768]         590,592      Dropout-55      [[1, 101, 768]]       [1, 101, 768]            0        Attention-18     [[1, 101, 768]]       [1, 101, 768]            0         Identity-18     [[1, 101, 768]]       [1, 101, 768]            0        LayerNorm-37     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-108      [[1, 101, 768]]        [1, 101, 64]         49,216         ReLU-18        [[1, 101, 64]]        [1, 101, 64]            0         Linear-109       [[1, 101, 64]]       [1, 101, 768]         49,920       Linear-106      [[1, 101, 768]]       [1, 101, 3072]       2,362,368       GELU-18       [[1, 101, 3072]]      [1, 101, 3072]           0         Dropout-56      [[1, 101, 768]]       [1, 101, 768]            0         Linear-107      [[1, 101, 3072]]      [1, 101, 768]        2,360,064       Mlp-18        [[1, 101, 768]]       [1, 101, 768]            0          Block-18       [[1, 101, 768]]       [1, 101, 768]            1        LayerNorm-38     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-110      [[1, 101, 768]]       [1, 101, 2304]       1,769,472     Dropout-57    [[1, 12, 101, 101]]   [1, 12, 101, 101]          0         Linear-111      [[1, 101, 768]]       [1, 101, 768]         590,592      Dropout-58      [[1, 101, 768]]       [1, 101, 768]            0        Attention-19     [[1, 101, 768]]       [1, 101, 768]            0         Identity-19     [[1, 101, 768]]       [1, 101, 768]            0        LayerNorm-39     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-114      [[1, 101, 768]]        [1, 101, 64]         49,216         ReLU-19        [[1, 101, 64]]        [1, 101, 64]            0         Linear-115       [[1, 101, 64]]       [1, 101, 768]         49,920       Linear-112      [[1, 101, 768]]       [1, 101, 3072]       2,362,368       GELU-19       [[1, 101, 3072]]      [1, 101, 3072]           0         Dropout-59      [[1, 101, 768]]       [1, 101, 768]            0         Linear-113      [[1, 101, 3072]]      [1, 101, 768]        2,360,064       Mlp-19        [[1, 101, 768]]       [1, 101, 768]            0          Block-19       [[1, 101, 768]]       [1, 101, 768]            1        LayerNorm-40     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-116      [[1, 101, 768]]       [1, 101, 2304]       1,769,472     Dropout-60    [[1, 12, 101, 101]]   [1, 12, 101, 101]          0         Linear-117      [[1, 101, 768]]       [1, 101, 768]         590,592      Dropout-61      [[1, 101, 768]]       [1, 101, 768]            0        Attention-20     [[1, 101, 768]]       [1, 101, 768]            0         Identity-20     [[1, 101, 768]]       [1, 101, 768]            0        LayerNorm-41     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-120      [[1, 101, 768]]        [1, 101, 64]         49,216         ReLU-20        [[1, 101, 64]]        [1, 101, 64]            0         Linear-121       [[1, 101, 64]]       [1, 101, 768]         49,920       Linear-118      [[1, 101, 768]]       [1, 101, 3072]       2,362,368       GELU-20       [[1, 101, 3072]]      [1, 101, 3072]           0         Dropout-62      [[1, 101, 768]]       [1, 101, 768]            0         Linear-119      [[1, 101, 3072]]      [1, 101, 768]        2,360,064       Mlp-20        [[1, 101, 768]]       [1, 101, 768]            0          Block-20       [[1, 101, 768]]       [1, 101, 768]            1        LayerNorm-42     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-122      [[1, 101, 768]]       [1, 101, 2304]       1,769,472     Dropout-63    [[1, 12, 101, 101]]   [1, 12, 101, 101]          0         Linear-123      [[1, 101, 768]]       [1, 101, 768]         590,592      Dropout-64      [[1, 101, 768]]       [1, 101, 768]            0        Attention-21     [[1, 101, 768]]       [1, 101, 768]            0         Identity-21     [[1, 101, 768]]       [1, 101, 768]            0        LayerNorm-43     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-126      [[1, 101, 768]]        [1, 101, 64]         49,216         ReLU-21        [[1, 101, 64]]        [1, 101, 64]            0         Linear-127       [[1, 101, 64]]       [1, 101, 768]         49,920       Linear-124      [[1, 101, 768]]       [1, 101, 3072]       2,362,368       GELU-21       [[1, 101, 3072]]      [1, 101, 3072]           0         Dropout-65      [[1, 101, 768]]       [1, 101, 768]            0         Linear-125      [[1, 101, 3072]]      [1, 101, 768]        2,360,064       Mlp-21        [[1, 101, 768]]       [1, 101, 768]            0          Block-21       [[1, 101, 768]]       [1, 101, 768]            1        LayerNorm-44     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-128      [[1, 101, 768]]       [1, 101, 2304]       1,769,472     Dropout-66    [[1, 12, 101, 101]]   [1, 12, 101, 101]          0         Linear-129      [[1, 101, 768]]       [1, 101, 768]         590,592      Dropout-67      [[1, 101, 768]]       [1, 101, 768]            0        Attention-22     [[1, 101, 768]]       [1, 101, 768]            0         Identity-22     [[1, 101, 768]]       [1, 101, 768]            0        LayerNorm-45     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-132      [[1, 101, 768]]        [1, 101, 64]         49,216         ReLU-22        [[1, 101, 64]]        [1, 101, 64]            0         Linear-133       [[1, 101, 64]]       [1, 101, 768]         49,920       Linear-130      [[1, 101, 768]]       [1, 101, 3072]       2,362,368       GELU-22       [[1, 101, 3072]]      [1, 101, 3072]           0         Dropout-68      [[1, 101, 768]]       [1, 101, 768]            0         Linear-131      [[1, 101, 3072]]      [1, 101, 768]        2,360,064       Mlp-22        [[1, 101, 768]]       [1, 101, 768]            0          Block-22       [[1, 101, 768]]       [1, 101, 768]            1        LayerNorm-46     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-134      [[1, 101, 768]]       [1, 101, 2304]       1,769,472     Dropout-69    [[1, 12, 101, 101]]   [1, 12, 101, 101]          0         Linear-135      [[1, 101, 768]]       [1, 101, 768]         590,592      Dropout-70      [[1, 101, 768]]       [1, 101, 768]            0        Attention-23     [[1, 101, 768]]       [1, 101, 768]            0         Identity-23     [[1, 101, 768]]       [1, 101, 768]            0        LayerNorm-47     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-138      [[1, 101, 768]]        [1, 101, 64]         49,216         ReLU-23        [[1, 101, 64]]        [1, 101, 64]            0         Linear-139       [[1, 101, 64]]       [1, 101, 768]         49,920       Linear-136      [[1, 101, 768]]       [1, 101, 3072]       2,362,368       GELU-23       [[1, 101, 3072]]      [1, 101, 3072]           0         Dropout-71      [[1, 101, 768]]       [1, 101, 768]            0         Linear-137      [[1, 101, 3072]]      [1, 101, 768]        2,360,064       Mlp-23        [[1, 101, 768]]       [1, 101, 768]            0          Block-23       [[1, 101, 768]]       [1, 101, 768]            1        LayerNorm-48     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-140      [[1, 101, 768]]       [1, 101, 2304]       1,769,472     Dropout-72    [[1, 12, 101, 101]]   [1, 12, 101, 101]          0         Linear-141      [[1, 101, 768]]       [1, 101, 768]         590,592      Dropout-73      [[1, 101, 768]]       [1, 101, 768]            0        Attention-24     [[1, 101, 768]]       [1, 101, 768]            0         Identity-24     [[1, 101, 768]]       [1, 101, 768]            0        LayerNorm-49     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-144      [[1, 101, 768]]        [1, 101, 64]         49,216         ReLU-24        [[1, 101, 64]]        [1, 101, 64]            0         Linear-145       [[1, 101, 64]]       [1, 101, 768]         49,920       Linear-142      [[1, 101, 768]]       [1, 101, 3072]       2,362,368       GELU-24       [[1, 101, 3072]]      [1, 101, 3072]           0         Dropout-74      [[1, 101, 768]]       [1, 101, 768]            0         Linear-143      [[1, 101, 3072]]      [1, 101, 768]        2,360,064       Mlp-24        [[1, 101, 768]]       [1, 101, 768]            0          Block-24       [[1, 101, 768]]       [1, 101, 768]            1        LayerNorm-50     [[1, 101, 768]]       [1, 101, 768]          1,536       Linear-146         [[1, 768]]            [1, 100]           76,900     ===========================================================================Total params: 86,316,400Trainable params: 86,316,400Non-trainable params: 0---------------------------------------------------------------------------Input size (MB): 0.01Forward/backward pass size (MB): 170.98Params size (MB): 329.27Estimated Total Size (MB): 500.26---------------------------------------------------------------------------

       

{'total_params': 86316400, 'trainable_params': 86316400}

               

9.自定义数据集处理方式

In [10]

class ToArray(object):    def __call__(self, img):        img = np.array(img)        img = np.transpose(img, [2, 0, 1])        img = img / 255.        return img.astype('float32')class RandomApply(object):    def __init__(self, transform, p=0.5):        super().__init__()        self.p = p        self.transform = transform            def __call__(self, img):        if self.p = self.model._optimizer._learning_rate.warmup_steps:                self.warm_up = Falsedef _on_train_batch_end(self, step, logs=None):    logs = logs or {}    logs['lr'] = self.model._optimizer.get_lr()    self.train_step += 1    if self._is_write():        self._updates(logs, 'train')def _on_train_begin(self, logs=None):    self.epochs = self.params['epochs']    assert self.epochs    self.train_metrics = self.params['metrics'] + ['lr']    assert self.train_metrics    self._is_fit = True    self.train_step = 0callbacks.VisualDL.on_train_batch_end = _on_train_batch_endcallbacks.VisualDL.on_train_begin = _on_train_begin

   

10.模型实验

由于PaddleClas提供的Vision Transformer网络结构名称与本项目的网络名称定义不同,故无法使用官方的预训练模型

本次试验尝试通过在Cifar100数据集获取预训练模型,再迁移至Cifar10数据集,通过比较冻结网络与不冻结网络的Acc Top-1区别,探究AdaptFormer网络的可行性。

Cifar100数据集训练模型: AdaptFormer_BaseModel

训练参数为:

Epoch = 80learning_rate = 0.01weight_decay = 5e-4momentum = 0.9batch_size = 128In [ ]

model = paddle.Model(VisionTransformer(class_dim=100))# 加载checkpoint# model.load('output/AdaptFormer/80.pdparams', skip_mismatch=True)MAX_EPOCH = 80LR = 0.01WEIGHT_DECAY = 5e-4MOMENTUM = 0.9BATCH_SIZE = 128IS_STOP_GRADIENT = FalseCIFAR_MEAN = [0.5071, 0.4865, 0.4409]CIFAR_STD = [0.1942, 0.1918, 0.1958]DATA_FILE = Nonemodel.prepare(    paddle.optimizer.Momentum(        learning_rate=LinearWarmup(CosineAnnealingDecay(LR, MAX_EPOCH), 2000, 0., LR),        momentum=MOMENTUM,        parameters=model.parameters(),        weight_decay=WEIGHT_DECAY),    paddle.nn.CrossEntropyLoss(),    paddle.metric.Accuracy(topk=(1,5)))# 定义数据集增强方式transforms = Compose([    RandomCrop(32, padding=4),    RandomApply(BrightnessTransform(0.1)),    RandomApply(ContrastTransform(0.1)),    RandomHorizontalFlip(),    RandomRotation(15),    ToArray(),    Normalize(CIFAR_MEAN, CIFAR_STD),    # Resize(size=72)])val_transforms = Compose([ToArray(), Normalize(CIFAR_MEAN, CIFAR_STD)])# 加载训练和测试数据集train_set = Cifar100(DATA_FILE, mode='train', transform=transforms)test_set = Cifar100(DATA_FILE, mode='test', transform=val_transforms)# 定义保存方式和训练可视化checkpoint_callback = paddle.callbacks.ModelCheckpoint(save_freq=20, save_dir='output/AdaptFormer_BaseModel')callbacks = [LRSchedulerM(),checkpoint_callback, callbacks.VisualDL('vis_logs/AdaptFormer_BaseModel.log')]# 训练模型model.fit(    train_set,    test_set,    epochs=MAX_EPOCH,     batch_size=BATCH_SIZE,    shuffle=True,    num_workers=0,    verbose=1,     callbacks=callbacks,)

   

经过80轮的迭代,训练结果如图:

【AI达人特训营】AdaptFormer:一种新型fine-tuning方法复现 - 创想鸟        

Cifar10数据集迁移模型实验

训练参数:

Epoch = 10learning_rate = 0.01weight_decay = 5e-4momentum = 0.9batch_size = 128IS_STOP_GRADIENT = True (实验组)IS_STOP_GRADIENT = False (对照组)In [ ]

model = paddle.Model(VisionTransformer(class_dim=10))# 加载checkpointmodel.load('output/AdaptFormer_BaseModel/80.pdparams', skip_mismatch=True)MAX_EPOCH = 10LR = 0.01WEIGHT_DECAY = 5e-4MOMENTUM = 0.9BATCH_SIZE = 128IS_STOP_GRADIENT = True    # 实验组IS_STOP_GRADIENT = False   # 对照组CIFAR_MEAN = [0.5071, 0.4865, 0.4409]CIFAR_STD = [0.1942, 0.1918, 0.1958]DATA_FILE = Nonemodel.prepare(    paddle.optimizer.Momentum(        learning_rate=LinearWarmup(CosineAnnealingDecay(LR, MAX_EPOCH), 2000, 0., LR),        momentum=MOMENTUM,        parameters=model.parameters(),        weight_decay=WEIGHT_DECAY),    paddle.nn.CrossEntropyLoss(),    paddle.metric.Accuracy(topk=(1,5)))# 定义数据集增强方式transforms = Compose([    RandomCrop(32, padding=4),    RandomApply(BrightnessTransform(0.1)),    RandomApply(ContrastTransform(0.1)),    RandomHorizontalFlip(),    RandomRotation(15),    ToArray(),    Normalize(CIFAR_MEAN, CIFAR_STD),    # Resize(size=72)])val_transforms = Compose([ToArray(), Normalize(CIFAR_MEAN, CIFAR_STD)])# 加载训练和测试数据集train_set = Cifar10(DATA_FILE, mode='train', transform=transforms)test_set = Cifar10(DATA_FILE, mode='test', transform=val_transforms)# 定义保存方式和训练可视化checkpoint_callback = paddle.callbacks.ModelCheckpoint(save_freq=20, save_dir='output/AdaptFormer_BaseModel')callbacks = [LRSchedulerM(),checkpoint_callback, callbacks.VisualDL('vis_logs/AdaptFormer_BaseModel.log')]# 训练模型model.fit(    train_set,    test_set,    epochs=MAX_EPOCH,     batch_size=BATCH_SIZE,    shuffle=True,    num_workers=0,    verbose=1,     callbacks=callbacks,)

   

实验结果

冻结网络迁移训练(左图):
训练参数量:4.56 MB
8个Epoch后Acc Top-1:0.7784

不冻结网络迁移训练(右图):

训练参数量:329.27 MB

10个Epoech后Acc Top-1:0.7662

【AI达人特训营】AdaptFormer:一种新型fine-tuning方法复现 - 创想鸟【AI达人特训营】AdaptFormer:一种新型fine-tuning方法复现 - 创想鸟        

冻结后网络需要训练的参数仅为完整训练参数的1.38% ,但是模型的准确率在减少两个Epoch的情况下相对于完整训练反而增加了一个百分点,由此可以体现AdaptFormer网络在迁移学习中的优越性

以上就是【AI达人特训营】AdaptFormer:一种新型fine-tuning方法复现的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/738589.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
抖音赚钱功能在哪里 抖音赚钱入口与任务中心说明
上一篇 2025年11月25日 13:56:36
vscode怎么设置缩进
下一篇 2025年11月25日 13:56:39

相关推荐

  • composer require-dev和require有什么不同_Composer Require与Require-Dev区别解析

    require用于声明项目运行必需的依赖,如框架、数据库组件和第三方SDK,这些包会随项目部署到生产环境;2. require-dev用于声明仅在开发和测试阶段需要的工具,如PHPUnit、PHPStan、Faker等,不会默认部署到生产环境;3. 安装时composer install根据环境决定…

    2026年5月10日
    900
  • Golang JSON序列化:控制敏感字段暴露的最佳实践

    本教程探讨golang中如何高效控制结构体字段在json序列化时的可见性。当需要将包含敏感信息的结构体数组转换为json响应时,通过利用`encoding/json`包提供的结构体标签,特别是`json:”-“`,可以轻松实现对特定字段的忽略,从而避免敏感数据泄露,确保api…

    2026年5月10日
    000
  • 比特币新手教程 比特币交易平台有哪些

    比特币是一种去中心化的数字货币,基于区块链技术实现点对点交易,具有匿名性、有限发行和不可篡改等特点;新手可通过交易所购买,P2P交易获得比特币,常用平台包括Binance、OKX和Huobi;交易流程包括注册账户、实名认证、绑定支付方式、充值法币并下单购买,可选择市价单或限价单;比特币存储方式有交易…

    2026年5月10日
    000
  • c++中的SFINAE技术是什么_c++模板编程中的SFINAE原理与应用

    SFINAE 是“替换失败不是错误”的原则,指模板实例化时若参数替换导致错误,只要存在其他合法候选,编译器不报错而是继续重载决议。它用于条件启用模板、类型检测等场景,如通过 decltype 或 enable_if 控制函数重载,实现类型特征判断。尽管 C++20 引入 Concepts 简化了部分…

    2026年5月10日
    000
  • Go语言mgo查询构建:深入理解bson.M与日期范围查询的正确实践

    本文旨在解决go语言mgo库中构建复杂查询时,特别是涉及嵌套`bson.m`和日期范围筛选的常见错误。我们将深入剖析`bson.m`的类型特性,解释为何直接索引`interface{}`会导致“invalid operation”错误,并提供一种推荐的、结构清晰的代码重构方案,以确保查询条件能够正确…

    2026年5月10日
    100
  • Golang goroutine与channel调试技巧

    使用go run -race检测数据竞争,结合runtime.NumGoroutine监控协程数量,通过pprof分析阻塞调用栈,利用select超时避免永久阻塞,有效排查goroutine泄漏、死锁和数据竞争问题。 Go语言的goroutine和channel是并发编程的核心,但它们也带来了调试上…

    2026年5月10日
    000
  • 使用 Jupyter Notebook 进行探索性数据分析

    Jupyter Notebook通过单元格实现代码与Markdown结合,支持数据导入(pandas)、清洗(fillna)、探索(matplotlib/seaborn可视化)、统计分析(describe/corr)和特征工程,便于记录与分享分析过程。 Jupyter Notebook 是进行探索性…

    2026年5月10日
    000
  • 《魔兽世界》将于6月11日开启国服回归技术测试

    《魔兽世界》将于6月11日开启国服回归技术测试《魔兽世界》将于6月11日开启国服回归技术测试《魔兽世界》将于6月11日开启国服回归技术测试《魔兽世界》将于6月11日开启国服回归技术测试

    《%ign%ignore_a_1%re_a_1%》官方宣布,将于6月11日开启国服回归技术测试,时间为7天,并称可以在6月内正式开服,玩家们可以访问官网下载战网客户端并预下载“巫妖王之怒”客户端,技术测试详情见下图。 WordAi WordAI是一个AI驱动的内容重写平台 53 查看详情 以上就是《…

    2026年5月10日 用户投稿
    200
  • php常量怎么用_PHP常量(define/const)定义与使用方法

    PHP中可通过define函数和const关键字定义常量,用于存储不可变值。define适用于全局作用域,支持动态名称和条件定义,如define(‘SITE_NAME’, ‘MyWebsite’);const在编译时生效,语法简洁但限制多,只能在类或全…

    2026年5月10日
    000
  • 如何在HTML中插入表单元素_HTML表单控件与输入类型使用指南

    HTML表单通过标签构建,包含action和method属性定义数据提交目标与方式,常用input类型如text、password、email等适配不同输入需求,配合label、required、placeholder提升可用性,结合textarea、select、button等控件实现完整交互,是…

    2026年5月10日
    000
  • 创建指定大小并填充特定数据的Golang文件教程

    本文将介绍如何使用Golang创建一个指定大小的文件,并用特定数据填充它。我们将使用 `os` 包提供的函数来创建和截断文件,从而实现快速生成大文件的目的。示例代码展示了如何创建一个10MB的文件,并将其填充为全零数据。掌握这些方法,可以方便地在例如日志系统或磁盘队列等场景中,预先创建测试文件或初始…

    2026年5月10日
    000
  • Python命令怎样使用profile分析脚本性能 Python命令性能分析的基础教程

    使用Python的cProfile模块分析脚本性能最直接的方式是通过命令行执行python -m cProfile your_script.py,它会输出每个函数的调用次数、总耗时、累积耗时等关键指标,帮助定位性能瓶颈;为进一步分析,可将结果保存为文件python -m cProfile -o ou…

    2026年5月10日
    000
  • 如何插入查询结果数据_SQL插入Select查询结果方法

    如何插入查询结果数据_SQL插入Select查询结果方法如何插入查询结果数据_SQL插入Select查询结果方法如何插入查询结果数据_SQL插入Select查询结果方法如何插入查询结果数据_SQL插入Select查询结果方法

    使用INSERT INTO…SELECT语句可高效插入数据,通过NOT EXISTS、LEFT JOIN、MERGE语句或唯一约束避免重复;表结构不一致时可通过别名、类型转换、默认值或计算字段处理;结合存储过程可提升可维护性,支持参数化与动态SQL。 将查询结果数据插入到另一个表中,可以…

    2026年5月10日 用户投稿
    000
  • 使用 WebCodecs VideoDecoder 实现精确逐帧回退

    本文档旨在解决在使用 WebCodecs VideoDecoder 进行视频解码时,实现精确逐帧回退的问题。通过比较帧的时间戳与目标帧的时间戳,可以避免渲染中间帧,从而提高用户体验。本文将提供详细的解决方案和示例代码,帮助开发者实现精确的视频帧控制。 在使用 WebCodecs VideoDecod…

    2026年5月10日
    000
  • Discord.py 交互按钮超时与持久化解决方案

    本教程旨在解决Discord.py中交互按钮在一段时间后出现“This Interaction Failed”错误的问题。我们将深入探讨视图(View)的超时机制,并提供通过正确设置timeout参数以及利用bot.add_view()方法实现按钮持久化的具体方案,确保您的机器人交互功能稳定可靠,即…

    2026年5月10日
    000
  • Debian Copilot的社区活跃度如何

    debian copilot是codeberg社区维护的ai助手,旨在为debian用户提供服务。尽管搜索结果中没有直接提供关于debian copilot社区支持活跃度的具体数据,但我们可以通过debian社区的整体活跃度和特点来推断其活跃性。 Debian社区的一般情况: Debian拥有详尽的…

    2026年5月10日
    000
  • JavaScript 动态菜单点击高亮效果实现教程

    本教程详细介绍了如何使用 JavaScript 实现动态菜单的点击高亮功能。通过事件委托和状态管理,当用户点击菜单项时,被点击项会高亮显示(绿色),同时其他菜单项恢复默认样式(白色)。这种方法避免了不必要的DOM操作,提高了性能和代码可维护性,确保了无论点击方向如何,功能都能稳定运行。 动态菜单高亮…

    2026年5月10日
    200
  • c++如何实现UDP通信_c++基于UDP的网络通信示例

    UDP通信基于套接字实现,适用于实时性要求高的场景。1. 流程包括创建套接字、绑定地址(接收方)、发送(sendto)与接收(recvfrom)数据、关闭套接字;2. 服务端监听指定端口,接收客户端消息并回传;3. 客户端发送消息至服务端并接收响应;4. 跨平台需处理Winsock初始化与库链接,编…

    2026年5月10日
    000
  • JavaScript函数中插入加载动画(Spinner)的正确方法

    本文旨在解决在JavaScript函数中插入加载动画(Spinner)时遇到的异步问题。通过引入async/await和Promise.all,确保在数据处理完成前后正确显示和隐藏加载动画,提升用户体验。我们将提供两种实现方案,并详细解释其原理和优势。 在Web开发中,当执行耗时操作时,显示加载动画…

    2026年5月10日
    000
  • 使用 Pydantic v2 实现条件性必填字段

    本文介绍了如何在 Pydantic v2 模型中实现条件性必填字段。通过自定义验证器,可以根据模型中其他字段的值来动态地控制某些字段是否为必填项,从而满足 API 交互中数据验证的复杂需求。本文提供了一个具体的示例,展示了如何确保模型中至少有一个字段被赋值。 在 Pydantic v2 中,虽然没有…

    2026年5月10日
    000

发表回复

登录后才能评论
关注微信