【问题标题】:What is bias node in googlenet and how to remove it?什么是 googlenet 中的偏置节点以及如何删除它?
【发布时间】:2021-08-03 09:09:59
【问题描述】:

我是深度学习的新手,我想建立一个可以识别相似图像的模型,我正在阅读classification is a Strong Baseline for Deep Metric Learning 研究论文。这是他们使用的短语:"remove the bias term inthe last linear layer"。我不知道什么是偏置项以及如何从googlenet 或其他预训练模型中删除它。 if someone help me out with this it would be great! :)

【问题讨论】:

    标签: deep-learning neural-network computer-vision pytorch


    【解决方案1】:

    为了计算第 n 层的输出,线性神经网络为每个第 n 层的输出计算第 n-1 层的输出的线性组合,将标量常数值添加到每个第 n 层的输出(偏置项),然后应用一个激活函数。在 pytorch 中,可以使用以下方法禁用线性层中的偏差:

    layer = torch.nn.Linear(n_in_features, n_out_features, bias=False)
    

    要覆盖现有的结构,比如包含在torchvision.models 中定义的here 的googlenet,您可以简单地在初始化后覆盖最后一个全连接层:

    from torchvision.models import googlenet
    num_classes = 1000 # or whatever you need it to be
    
    model = googlenet(num_classes)
    model.fc = torch.nn.Linear(1000,num_classes,bias = False)
    

    【讨论】:

    • 我认为您的意思是 bias=False 而不是 pretrained=False
    • 好电话@GoodDeeds
    • 感谢@DerekG 的帮助。我认为在知道这一点后问这是一个愚蠢的问题,我本可以在提问之前进行研究:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多