timesler / facenet-pytorch

Pretrained Pytorch face detection (MTCNN) and facial recognition (InceptionResnet) models
MIT License
4.49k stars 945 forks source link

Question when using it as features extractor #157

Open hanssssssss opened 3 years ago

hanssssssss commented 3 years ago

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
jasuriy commented 3 months ago

@hanssssssss hi did you solve your problem ? I also wanted to use this model as a feature extractor. so I was wondering if this repo will do it well.