I am trying to get a confidence from a model after giving it one sample to test. I am very new to this so I am not sure what I am doing. I read somewhere that I should use softmax to get a probability/confidence. I am using code from another implementation that doesn’t get the probability, it just returns a 1 or a 0. I am using Pytorch 3.0
Here is my code:
    for batch_idx, (x, y) in enumerate(dataloader): #comprised of one sample
        x = Variable(x.cuda())
        y = Variable(y.cuda())

        # forward pass
        y_model = model(x)

        # loss pass
        loss = loss_fct(y_model, y).mean()

        # predict pass
        _, predicted = torch.topk(y_model, k=1)
        correct = predicted.data.eq(y.data.view_as(predicted.data)).cpu().sum()

        # metrics
        total_loss += loss.data[0] * len(y)

        total_correct += correct
        total += len(y)

        print("{} set for {} {}: Average Loss: {:.4f}, Accuracy: {:.2f}%".format(
            "Test", "benign", "null?", total_loss / total,
                               total_correct * 100. / total))
        

I am not sure what a lot of this code means, or why it was used. The code was originally taken from here:

  
      github.com
  
  
    ALFA-group/robust-adv-malware-detection/blob/master/framework.py 61
# coding=utf-8
"""
Python module for performing adversarial training for malware detection
"""
import os
import torch
import random
import torch.nn as nn
import torch.optim as optim
from torch.autograd import Variable
from utils.utils import load_parameters, stack_tensors
from datasets.datasets import load_data
from inner_maximizers.inner_maximizers import inner_maximizer
from nets.ff_classifier import build_ff_classifier
from blindspot_coverage.covering_number import CoveringNumber
import losswise
import time
import json
import numpy as np



  This file has been truncated. show original

  
  
    
    
  
  


How to I feed the model the sample, which I assume is the variable “y” and get the confidence.
Thanks in advance.