Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The confidence score #28

Open
martinhoang11 opened this issue Dec 27, 2021 · 1 comment
Open

The confidence score #28

martinhoang11 opened this issue Dec 27, 2021 · 1 comment

Comments

@martinhoang11
Copy link

Hi kprokofi, thanks for your great and very details training pipeline project.
I want to ask about the confidence score: it returns like [array([-0.04811478, -0.20894697, 0.00486435, ..., 0.3441045 , 0.04338361, -0.12098037], dtype=float32)] when i test on an image. And the label prediction is confidence[i][1], negative numbers sometimes returned.

  • Is it correct for the confidence score return ?
  • Do I have to sort the list ?
    It seems not the same as your video demo. Looking forward to hearing from you. Thank you
@stakanich
Copy link

Hi. For these who will have this problem later:
In trainer.py there is row:
output = self.make_output(input_, hot_target)
and in the definition of this function later:

features = self.model(input_)
...
all_tasks_output = model1.make_logits(features, all=True)

In models/model_tools.py you can find it:

def forward(self, x):
        x = self.features(x)
        x = self.conv_last(x)
        x = self.avgpool(x)
        return x
def make_logits(self, features, all=False):
        all = all if self.multi_heads else False
        output = features.view(features.size(0), -1)
        spoof_out = self.spoofer(output)
        if all:
            type_spoof = self.spoof_type(output)
            lightning_type = self.lightning(output)
            real_atr = torch.sigmoid(self.real_atr(output))
            return spoof_out, type_spoof, lightning_type, real_atr
        return spoof_out

So, during a training, this model uses not only forward method, but one additional too. And in utils.py in build_model you can find these rows multiple times:

elif mode == 'convert':
    model.forward = model.forward_to_onnx

which is:

def forward_to_onnx(self,x):
        x = self.features(x)
        x = self.conv_last(x)
        x = self.avgpool(x)
        x = x.view(x.size(0), -1)
        spoof_out = self.spoofer(x)
        if isinstance(spoof_out, tuple):
            spoof_out = spoof_out[0]
        probab = F.softmax(spoof_out*self.scaling, dim=-1)
        return probab

With using one of these methods you will get an output with a shape [N, 2] where N - batch-size. First element is the confidence that image is real, and the second is the score for 'spoof' answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants