13、基于模型的多样性采样与异常值检测

基于模型的多样性采样与异常值检测

1. 从PyTorch隐藏层获取信息

在模型中获取隐藏层的值(z值,即logits),需要修改代码以访问这些信息。在PyTorch中,代码相对简单。

原始的前向传播代码如下:

def forward(self, feature_vec):
    # Define how data is passed through the model
    hidden1 = self.linear1(feature_vec).clamp(min=0) # ReLU
    output = self.linear2(hidden1)
    return F.log_softmax(output, dim=1)

为了返回所有层的信息,我们可以添加一个参数 return_all_layers ,修改后的代码如下:

def forward(self, feature_vec, return_all_layers=False):
    # Define how data is passed through the model and what is returned
    hidden1 = self.linear1(feature_vec).clamp(min=0) # ReLU
    output = self.linear2(hidden1)
    log_softmax = F.log_softmax(output, dim=1)   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值