MuggleWang / CosFace_pytorch

Pytorch implementation of CosFace
MIT License
242 stars 52 forks source link

RuntimeError: mat1 and mat2 shapes cannot be multiplied (1x131072 and 21504x512 #16

Closed zhoufengfan closed 2 years ago

zhoufengfan commented 2 years ago

After I run python lfw_eval.py, there occurs this error:

Traceback (most recent call last):
  File "lfw_eval.py", line 122, in <module>
    _, result = eval(net.sphere().to('cuda'), model_path='checkpoint/CosFace_24_checkpoint.pth')
  File "lfw_eval.py", line 101, in eval
    f1 = extractDeepFeature(img1, model, is_gray)
  File "lfw_eval.py", line 30, in extractDeepFeature
    ft = torch.cat((model(img), model(img_)), 1)[0].to('cpu')
  File "/miniconda3/cosface/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/code/CosFace_pytorch/net.py", line 66, in forward
    x = self.fc(x)
  File "/miniconda3/cosface/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/miniconda3/cosface/lib/python3.8/site-packages/torch/nn/modules/linear.py", line 103, in forward
    return F.linear(input, self.weight, self.bias)
  File "/miniconda3/cosface/lib/python3.8/site-packages/torch/nn/functional.py", line 1848, in linear
    return torch._C._nn.linear(input, weight, bias)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (1x131072 and 21504x512)
jingyig01 commented 2 years ago

You should check your input size first. Cosface takes the 112*96 image as input. 建议检查一下你所用的LFW图像尺寸。cosface的输入是112 X 96.

zhoufengfan commented 2 years ago

Could you provide the code to crop the faces in the LFW dataset or disclose the method to crop the faces in the LFW dataset?

jingyig01 commented 2 years ago

Face detection and alignment are performed by MTCNN. For its Pytorch implement, please refer https://github.com/TropComplique/mtcnn-pytorch .

jingyig01 commented 2 years ago

Yule-li has provided the preprocessed 112 X 96 lfw dataset. His / her project page is https://awesomeopensource.com/project/yule-li/CosFace. You may download the preprocessed data via Baidu disk here.

zhoufengfan commented 2 years ago

Thanks for your response.

Now, the issue has been fixed.