1adrianb / 1adrianb/face-alignment

Tensor size mismatch getting predictions for a picture

Đang mở
#366 1 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
7.5k
Fork
1.4k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Hi,

This is my code, modeled after the sample in description.

`import face_alignment`
`from skimage import io`

`model = face_alignment.FaceAlignment(landmarks_type= face_alignment.LandmarksType.THREE_D,device='cpu',flip_input=False)`

`input = io.imread('test.png')`
`preds = model.get_landmarks(input)`

Running it I get the error:

`Traceback (most recent call last):`

`File ~\anaconda3\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)`

`File facealignment.py:14
preds = model.get_landmarks(input)`

`File ~\anaconda3\Lib\site-packages\face_alignment\api.py:113 in get_landmarks
return self.get_landmarks_from_image(image_or_path, detected_faces, return_bboxes, return_landmark_score)`

` File ~\anaconda3\Lib\site-packages\torch\utils\_contextlib.py:116 in decorate_context
return func(*args, **kwargs)`

` File ~\anaconda3\Lib\site-packages\face_alignment\api.py:144 in get_landmarks_from_image
detected_faces = self.face_detector.detect_from_image(image.copy())`

`File ~\anaconda3\Lib\site-packages\face_alignment\detection\sfd\sfd_detector.py:45 in detect_from_image
bboxlist = detect(self.face_detector, image, device=self.device)[0]`

` File ~\anaconda3\Lib\site-packages\face_alignment\detection\sfd\detect.py:17 in detect
return batch_detect(net, img, device)`

` File ~\anaconda3\Lib\site-packages\face_alignment\detection\sfd\detect.py:33 in batch_detect
img_batch = img_batch - torch.tensor([104.0, 117.0, 123.0], device=device).view(1, 3, 1, 1)`

`RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 1`

I've tried different types of files, different models (dlib and default sfd, 2D and 3D) and it always results in the same. I'm running Python 3.11 and torch 2.5.1.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

The error occurs in face_alignment/detection/sfd/detect.py at line 33 where a tensor size mismatch happens. The image likely has 4 channels (e.g., RGBA) but the model expects 3 (RGB). Start by checking the image shape in the debugger or by printing input.shape. Convert the image to RGB if needed. Look at the detect.py file to understand the preprocessing. Run the provided code with a known RGB image to verify the fix.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python, pytorch
Lĩnh vực
computer-vision
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.