我是深度学习的新手,我想建立一个可以识别相似图像的模型,我正在阅读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! :)
发布于 2021-05-13 22:14:07
为了计算层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)https://stackoverflow.com/questions/67513214
复制相似问题