facenet-pytorch icon indicating copy to clipboard operation
facenet-pytorch copied to clipboard

Question when using it as features extractor

Open hanssssssss opened this issue 3 years ago • 1 comments

Hi ! Thanks for sharing your great work. I tried to use it as a features extractor for my work and I used the cosine similarity to evaluate the similarity of two outputs from the InceptionResnetV1.But I found that the cosine similarity of two similiar pictures can be a negative value(like -0.530). Here is my code. Is there something wrong with my code? Thanks again.

def perceptual_use(input_imgs):

    model = InceptionResnetV1(pretrained='vggface2').to('cuda:0').eval()
    input_imgs_r = torch.reshape(input_imgs,[-1,224,224,3])
    input_imgs_r = torch.clamp(input_imgs_r,0,255).to(torch.float32)
    input_imgs_r = (input_imgs_r - 127.5) / 128.0
    input_imgs_r = input_imgs_r.permute(0,3,1,2)
    output = model(input_imgs_r)
    return output

hanssssssss avatar Mar 31 '21 17:03 hanssssssss