mk-minchul / CVLface

MIT License
13 stars 1 forks source link

Error in running cvlface_adaface_vit_base_kprpe_webface4m pretrained model #6

Open GDistories opened 1 week ago

GDistories commented 1 week ago

Hi, i try to run the verify.py in your example using cvlface_adaface_vit_base_kprpe_webface4m pretrained model. However, i faced error below:

AttributeError                            Traceback (most recent call last)
Cell In[4], line 16
     13 align_end = time.time()
     15 recognize_start = time.time()
---> 16 feat1 = fr_model(aligned_x1)
     17 feat2 = fr_model(aligned_x2)
     18 recognize_end = time.time()

File /opt/jason/anaconda3/envs/cvlface/lib/python3.10/site-packages/torch/nn/modules/module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)
   1516     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1517 else:
-> 1518     return self._call_impl(*args, **kwargs)

File /opt/jason/anaconda3/envs/cvlface/lib/python3.10/site-packages/torch/nn/modules/module.py:1527, in Module._call_impl(self, *args, **kwargs)
   1522 # If we don't have any hooks, we want to skip the rest of the logic in
   1523 # this function, and just call forward.
   1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1525         or _global_backward_pre_hooks or _global_backward_hooks
   1526         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527     return forward_call(*args, **kwargs)
   1529 try:
   1530     result = None

File ~/.cache/huggingface/modules/transformers_modules/cvlface_adaface_vit_base_kprpe_webface4m/wrapper.py:27, in CVLFaceRecognitionModel.forward(self, *args, **kwargs)
     26 def forward(self, *args, **kwargs):
---> 27     return self.model(*args, **kwargs)

File /opt/jason/anaconda3/envs/cvlface/lib/python3.10/site-packages/torch/nn/modules/module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)
   1516     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1517 else:
-> 1518     return self._call_impl(*args, **kwargs)

File /opt/jason/anaconda3/envs/cvlface/lib/python3.10/site-packages/torch/nn/modules/module.py:1527, in Module._call_impl(self, *args, **kwargs)
   1522 # If we don't have any hooks, we want to skip the rest of the logic in
   1523 # this function, and just call forward.
   1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1525         or _global_backward_pre_hooks or _global_backward_hooks
   1526         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527     return forward_call(*args, **kwargs)
   1529 try:
   1530     result = None

File ~/github/CVLface/cvlface/pretrained_models/recognization/cvlface_adaface_vit_base_kprpe_webface4m/models/vit_kprpe/__init__.py:47, in ViTKPRPEModel.forward(self, x, *args, **kwargs)
     45 if self.input_color_flip:
     46     x = x.flip(1)
---> 47 return self.net(x, *args, **kwargs)

File /opt/jason/anaconda3/envs/cvlface/lib/python3.10/site-packages/torch/nn/modules/module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)
   1516     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1517 else:
-> 1518     return self._call_impl(*args, **kwargs)

File /opt/jason/anaconda3/envs/cvlface/lib/python3.10/site-packages/torch/nn/modules/module.py:1527, in Module._call_impl(self, *args, **kwargs)
   1522 # If we don't have any hooks, we want to skip the rest of the logic in
   1523 # this function, and just call forward.
   1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1525         or _global_backward_pre_hooks or _global_backward_hooks
   1526         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527     return forward_call(*args, **kwargs)
   1529 try:
   1530     result = None

File ~/github/CVLface/cvlface/pretrained_models/recognization/cvlface_adaface_vit_base_kprpe_webface4m/models/vit_kprpe/vit.py:310, in VisionTransformerWithKPRPE.forward(self, x, keypoints)
    309 def forward(self, x, keypoints=None):
--> 310     x = self.forward_features(x, keypoints=keypoints)
    311     x = self.feature(x)
    312     return x

File ~/github/CVLface/cvlface/pretrained_models/recognization/cvlface_adaface_vit_base_kprpe_webface4m/models/vit_kprpe/vit.py:288, in VisionTransformerWithKPRPE.forward_features(self, x, keypoints)
    285 if self.training and self.mask_ratio > 0:
    286     x, _, ids_restore = self.random_masking(x)
--> 288 extra_ctx = make_kprpe_input(keypoints, x, self.keypoint_linear, self.rpe_config, self.mask_ratio,
    289                              self.depth, self.num_heads, self.num_buckets)
    291 for block_idx, func in enumerate(self.blocks):
    292     if isinstance(extra_ctx, list):

File ~/github/CVLface/cvlface/pretrained_models/recognization/cvlface_adaface_vit_base_kprpe_webface4m/models/vit_kprpe/rpe_options.py:109, in make_kprpe_input(keypoints, x, keypoint_linear, rpe_config, mask_ratio, depth, num_heads, num_buckets)
    107 elif ctx_type == 'rel_keypoint_splithead_unshared':
    108     assert mask_ratio == 0
--> 109     rel_keypoints = relative_keypoints.make_rel_keypoints(keypoints, x)[:, :, :2 * num_kp]
    110     rel_keypoints = keypoint_linear(rel_keypoints)  # B H N D
    111     rel_keypoints = rel_keypoints.view(B, -1, num_heads * depth, num_buckets).transpose(1, 2)

File /opt/jason/anaconda3/envs/cvlface/lib/python3.10/site-packages/torch/utils/_contextlib.py:115, in context_decorator.<locals>.decorate_context(*args, **kwargs)
    112 @functools.wraps(func)
    113 def decorate_context(*args, **kwargs):
    114     with ctx_factory():
--> 115         return func(*args, **kwargs)

File ~/github/CVLface/cvlface/pretrained_models/recognization/cvlface_adaface_vit_base_kprpe_webface4m/models/vit_kprpe/RPE/KPRPE/relative_keypoints.py:16, in make_rel_keypoints(keypoints, query)
     14 x, y = torch.meshgrid(coord, coord, indexing='ij')
     15 grid = torch.stack([y, x], dim=-1).reshape(-1, 2).unsqueeze(0).unsqueeze(-2)  # BxNx1x2
---> 16 _keypoints = keypoints.unsqueeze(-3)  # Bx1x5x2
     17 diff = (grid - _keypoints)  # BxNx5x2
     18 diff = diff.flatten(2)  # BxNx10

AttributeError: 'NoneType' object has no attribute 'unsqueeze'

How to solve this?

GDistories commented 1 week ago

output for aligned_x1.shape, orig_pred_ldmks1.shape, aligned_ldmks1.shape, score1.shape, thetas1.shape, normalized_bbox1.shape:

(torch.Size([1, 3, 112, 112]),
 torch.Size([1, 5, 2]),
 torch.Size([1, 5, 2]),
 torch.Size([1, 1]),
 torch.Size([1, 2, 3]),
 torch.Size([1, 4]))
luser350 commented 6 days ago

I got the same error.

mk-minchul commented 1 day ago

It seems like the input may be None. I have added the pairs.csv file so you can run the example code. Simply go to apps/verification and run python verify.py. The output should be something like

   index      A      B  is_same    cossim
0      0  0.jpg  1.jpg     True  0.670952
1      1  2.png  3.png    False -0.019673
2      2  4.png  5.png    False  0.052606
luser350 commented 8 hours ago

Thanks for replying. I have printed out the paths and tensors, ensuring they are not None. Screenshot from 2024-07-09 15-56-33 Still the same error!