Repository navigation
๐ [i18n-KO] Translated vitpose.md to Korean
#39575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,302 @@ | ||
| <!--Copyright 2024 The HuggingFace Team. All rights reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations under the License. | ||
| --> | ||
|
|
||
| <div style="float: right;"> | ||
| <div class="flex flex-wrap space-x-1"> | ||
| <img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white"> | ||
| </div> | ||
| </div> | ||
|
|
||
| # ViTPose[[vitpose]] | ||
|
|
||
| [ViTPose](https://huggingface.co/papers/2204.12484)๋ ํคํฌ์ธํธ(ํฌ์ฆ) ์ถ์ ์ ์ํ ๋น์ ํธ๋์คํฌ๋จธ ๊ธฐ๋ฐ ๋ชจ๋ธ์ ๋๋ค. ๊ฐ๋จํ๊ณ ๋น๊ณ์ธต์ ์ธ [ViT](./vit) ๋ฐฑ๋ณธ๊ณผ ๊ฒฝ๋ ๋์ฝ๋ ํค๋๋ฅผ ์ฌ์ฉํฉ๋๋ค. ์ด ์ํคํ ์ฒ๋ ๋ชจ๋ธ ์ค๊ณ๋ฅผ ๋จ์ํํ๊ณ , ํธ๋์คํฌ๋จธ์ ํ์ฅ์ฑ์ ํ์ฉํ๋ฉฐ, ๋ค์ํ ํ๋ จ ์ ๋ต์ ์ ์ํ ์ ์์ต๋๋ค. | ||
|
|
||
| [ViTPose++](https://huggingface.co/papers/2212.04246)๋ ๋ฐฑ๋ณธ์ ์ ๋ฌธ๊ฐ ํผํฉ(MoE) ๋ชจ๋์ ํตํฉํ๊ณ ๋ ๋ค์ํ ์ฌ์ ํ๋ จ ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ์ฌ ViTPose๋ฅผ ๊ฐ์ ํฉ๋๋ค. | ||
|
|
||
| <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/vitpose-architecture.png" | ||
| alt="drawing" width="600"/> | ||
|
|
||
| ๋ชจ๋ ViTPose์ ViTPose++ ์ฒดํฌํฌ์ธํธ๋ [ViTPose collection](https://huggingface.co/collections/usyd-community/vitpose-677fcfd0a0b2b5c8f79c4335)์์ ์ฐพ์ ์ ์์ต๋๋ค. | ||
|
|
||
| ์๋ ์์๋ [`VitPoseForPoseEstimation`] ํด๋์ค๋ฅผ ์ฌ์ฉํ ํฌ์ฆ ์ถ์ ์ ๋ณด์ฌ์ค๋๋ค. | ||
|
|
||
| ```py | ||
| import torch | ||
| import requests | ||
| import numpy as np | ||
| import supervision as sv | ||
| from PIL import Image | ||
| from transformers import AutoProcessor, RTDetrForObjectDetection, VitPoseForPoseEstimation | ||
|
|
||
| device = "cuda" if torch.cuda.is_available() else "cpu" | ||
|
|
||
| url = "https://www.fcbarcelona.com/fcbarcelona/photo/2021/01/31/3c55a19f-dfc1-4451-885e-afd14e890a11/mini_2021-01-31-BARCELONA-ATHLETIC-BILBAOI-30.JPG" | ||
| image = Image.open(requests.get(url, stream=True).raw) | ||
|
|
||
| # ์ด๋ฏธ์ง์์ ์ฌ๋์ ๊ฐ์งํฉ๋๋ค | ||
| person_image_processor = AutoProcessor.from_pretrained("PekingU/rtdetr_r50vd_coco_o365") | ||
| person_model = RTDetrForObjectDetection.from_pretrained("PekingU/rtdetr_r50vd_coco_o365", device_map=device) | ||
|
|
||
| inputs = person_image_processor(images=image, return_tensors="pt").to(device) | ||
|
|
||
| with torch.no_grad(): | ||
| outputs = person_model(**inputs) | ||
|
|
||
| results = person_image_processor.post_process_object_detection( | ||
| outputs, target_sizes=torch.tensor([(image.height, image.width)]), threshold=0.3 | ||
| ) | ||
| result = results[0] | ||
|
|
||
| # ์ฌ๋ ๋ผ๋ฒจ์ COCO ๋ฐ์ดํฐ์ ์์ 0 ์ธ๋ฑ์ค๋ฅผ ์ฐธ์กฐํฉ๋๋ค | ||
| person_boxes = result["boxes"][result["labels"] == 0] | ||
| person_boxes = person_boxes.cpu().numpy() | ||
|
|
||
| # ๋ฐ์ค๋ฅผ VOC (x1, y1, x2, y2)์์ COCO (x1, y1, w, h) ํ์์ผ๋ก ๋ณํํฉ๋๋ค | ||
| person_boxes[:, 2] = person_boxes[:, 2] - person_boxes[:, 0] | ||
| person_boxes[:, 3] = person_boxes[:, 3] - person_boxes[:, 1] | ||
|
|
||
| # ๋ฐ๊ฒฌ๋ ๊ฐ ์ฌ๋์ ๋ํด ํคํฌ์ธํธ๋ฅผ ๊ฐ์งํฉ๋๋ค | ||
| image_processor = AutoProcessor.from_pretrained("usyd-community/vitpose-base-simple") | ||
| model = VitPoseForPoseEstimation.from_pretrained("usyd-community/vitpose-base-simple", device_map=device) | ||
|
|
||
| inputs = image_processor(image, boxes=[person_boxes], return_tensors="pt").to(device) | ||
|
|
||
| with torch.no_grad(): | ||
| outputs = model(**inputs) | ||
|
|
||
| pose_results = image_processor.post_process_pose_estimation(outputs, boxes=[person_boxes]) | ||
| image_pose_result = pose_results[0] | ||
|
|
||
| xy = torch.stack([pose_result['keypoints'] for pose_result in image_pose_result]).cpu().numpy() | ||
| scores = torch.stack([pose_result['scores'] for pose_result in image_pose_result]).cpu().numpy() | ||
|
|
||
| key_points = sv.KeyPoints( | ||
| xy=xy, confidence=scores | ||
| ) | ||
|
|
||
| edge_annotator = sv.EdgeAnnotator( | ||
| color=sv.Color.GREEN, | ||
| thickness=1 | ||
| ) | ||
| vertex_annotator = sv.VertexAnnotator( | ||
| color=sv.Color.RED, | ||
| radius=2 | ||
| ) | ||
| annotated_frame = edge_annotator.annotate( | ||
| scene=image.copy(), | ||
| key_points=key_points | ||
| ) | ||
| annotated_frame = vertex_annotator.annotate( | ||
| scene=annotated_frame, | ||
| key_points=key_points | ||
| ) | ||
| annotated_frame | ||
| ``` | ||
|
|
||
| <div class="flex justify-center"> | ||
| <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/vitpose.png"/> | ||
| </div> | ||
|
|
||
| ์์ํ๋ ๊ฐ์ค์น๋ฅผ ๋ ๋ฎ์ ์ ๋ฐ๋๋ก ํํํ์ฌ ๋ํ ๋ชจ๋ธ์ ๋ฉ๋ชจ๋ฆฌ ๋ถ๋ด์ ์ค์ ๋๋ค. ์ฌ์ฉ ๊ฐ๋ฅํ ๋ ๋ง์ ์์ํ ๋ฐฑ์๋์ ๋ํด์๋ [Quantization](../quantization/overview) ๊ฐ์๋ฅผ ์ฐธ์กฐํ์ธ์. | ||
|
|
||
| ์๋ ์์๋ [torchao](../quantization/torchao)๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ์ค์น๋ง int4๋ก ์์ํํฉ๋๋ค. | ||
|
|
||
| ```py | ||
| # pip install torchao | ||
| import torch | ||
| import requests | ||
| import numpy as np | ||
| from PIL import Image | ||
| from transformers import AutoProcessor, RTDetrForObjectDetection, VitPoseForPoseEstimation, TorchAoConfig | ||
|
|
||
| url = "https://www.fcbarcelona.com/fcbarcelona/photo/2021/01/31/3c55a19f-dfc1-4451-885e-afd14e890a11/mini_2021-01-31-BARCELONA-ATHLETIC-BILBAOI-30.JPG" | ||
| image = Image.open(requests.get(url, stream=True).raw) | ||
|
|
||
| person_image_processor = AutoProcessor.from_pretrained("PekingU/rtdetr_r50vd_coco_o365") | ||
| person_model = RTDetrForObjectDetection.from_pretrained("PekingU/rtdetr_r50vd_coco_o365", device_map=device) | ||
|
|
||
| inputs = person_image_processor(images=image, return_tensors="pt").to(device) | ||
|
|
||
| with torch.no_grad(): | ||
| outputs = person_model(**inputs) | ||
|
|
||
| results = person_image_processor.post_process_object_detection( | ||
| outputs, target_sizes=torch.tensor([(image.height, image.width)]), threshold=0.3 | ||
| ) | ||
| result = results[0] | ||
|
|
||
| person_boxes = result["boxes"][result["labels"] == 0] | ||
| person_boxes = person_boxes.cpu().numpy() | ||
|
|
||
| person_boxes[:, 2] = person_boxes[:, 2] - person_boxes[:, 0] | ||
| person_boxes[:, 3] = person_boxes[:, 3] - person_boxes[:, 1] | ||
|
|
||
| quantization_config = TorchAoConfig("int4_weight_only", group_size=128) | ||
|
|
||
| image_processor = AutoProcessor.from_pretrained("usyd-community/vitpose-plus-huge") | ||
| model = VitPoseForPoseEstimation.from_pretrained("usyd-community/vitpose-plus-huge", device_map=device, quantization_config=quantization_config) | ||
|
|
||
| inputs = image_processor(image, boxes=[person_boxes], return_tensors="pt").to(device) | ||
|
|
||
| with torch.no_grad(): | ||
| outputs = model(**inputs) | ||
|
|
||
| pose_results = image_processor.post_process_pose_estimation(outputs, boxes=[person_boxes]) | ||
| image_pose_result = pose_results[0] | ||
| ``` | ||
|
|
||
| ## ์ฃผ์์ฌํญ[[notes]] | ||
|
|
||
| - [`AutoProcessor`]๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ด๋ฉ ๋ฐ์ค์ ์ด๋ฏธ์ง ์ ๋ ฅ์ ์๋์ผ๋ก ์ค๋นํ์ธ์. | ||
| - ViTPose๋ ํ๋ค์ด ๋ฐฉ์์ ํฌ์ฆ ์ถ์ ๊ธฐ์ ๋๋ค. ํคํฌ์ธํธ ์์ธก ์ ์ ๋จผ์ ๊ฐ์ฒด ๊ฐ์ง๊ธฐ๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ์ธ์ ๊ฐ์งํฉ๋๋ค. | ||
| - ViTPose++๋ 6๊ฐ์ ๋ค๋ฅธ MoE ์ ๋ฌธ๊ฐ ํค๋(COCO validation `0`, AiC `1`, MPII `2`, AP-10K `3`, APT-36K `4`, COCO-WholeBody `5`)๋ฅผ ๊ฐ์ง๊ณ ์์ด 6๊ฐ์ ๋ค๋ฅธ ๋ฐ์ดํฐ์ ์ ์ง์ํฉ๋๋ค. ์ฌ์ฉํ ์ ๋ฌธ๊ฐ๋ฅผ ๋ํ๋ด๊ธฐ ์ํด ๋ฐ์ดํฐ์ ์ ํด๋นํ๋ ํน์ ๊ฐ์ `dataset_index`์ ์ ๋ฌํ์ธ์. | ||
|
|
||
| ```py | ||
| from transformers import AutoProcessor, VitPoseForPoseEstimation | ||
|
|
||
| device = "cuda" if torch.cuda.is_available() else "cpu" | ||
|
|
||
| image_processor = AutoProcessor.from_pretrained("usyd-community/vitpose-plus-base") | ||
| model = VitPoseForPoseEstimation.from_pretrained("usyd-community/vitpose-plus-base", device=device) | ||
|
|
||
| inputs = image_processor(image, boxes=[person_boxes], return_tensors="pt").to(device) | ||
| dataset_index = torch.tensor([0], device=device) # (batch_size,) ํํ์ ํ ์์ฌ์ผ ํฉ๋๋ค | ||
|
|
||
| with torch.no_grad(): | ||
| outputs = model(**inputs, dataset_index=dataset_index) | ||
| ``` | ||
|
|
||
| - [OpenCV](https://opencv.org/)๋ ์ถ์ ๋ ํฌ์ฆ๋ฅผ ์๊ฐํํ๋ ๋์์ ์ธ ์ต์ ์ ๋๋ค. | ||
|
|
||
| ```py | ||
| # pip install opencv-python | ||
| import math | ||
| import cv2 | ||
|
|
||
| def draw_points(image, keypoints, scores, pose_keypoint_color, keypoint_score_threshold, radius, show_keypoint_weight): | ||
| if pose_keypoint_color is not None: | ||
| assert len(pose_keypoint_color) == len(keypoints) | ||
| for kid, (kpt, kpt_score) in enumerate(zip(keypoints, scores)): | ||
| x_coord, y_coord = int(kpt[0]), int(kpt[1]) | ||
| if kpt_score > keypoint_score_threshold: | ||
| color = tuple(int(c) for c in pose_keypoint_color[kid]) | ||
| if show_keypoint_weight: | ||
| cv2.circle(image, (int(x_coord), int(y_coord)), radius, color, -1) | ||
| transparency = max(0, min(1, kpt_score)) | ||
| cv2.addWeighted(image, transparency, image, 1 - transparency, 0, dst=image) | ||
| else: | ||
| cv2.circle(image, (int(x_coord), int(y_coord)), radius, color, -1) | ||
|
|
||
| def draw_links(image, keypoints, scores, keypoint_edges, link_colors, keypoint_score_threshold, thickness, show_keypoint_weight, stick_width = 2): | ||
| height, width, _ = image.shape | ||
| if keypoint_edges is not None and link_colors is not None: | ||
| assert len(link_colors) == len(keypoint_edges) | ||
| for sk_id, sk in enumerate(keypoint_edges): | ||
| x1, y1, score1 = (int(keypoints[sk[0], 0]), int(keypoints[sk[0], 1]), scores[sk[0]]) | ||
| x2, y2, score2 = (int(keypoints[sk[1], 0]), int(keypoints[sk[1], 1]), scores[sk[1]]) | ||
| if ( | ||
| x1 > 0 | ||
| and x1 < width | ||
| and y1 > 0 | ||
| and y1 < height | ||
| and x2 > 0 | ||
| and x2 < width | ||
| and y2 > 0 | ||
| and y2 < height | ||
| and score1 > keypoint_score_threshold | ||
| and score2 > keypoint_score_threshold | ||
| ): | ||
| color = tuple(int(c) for c in link_colors[sk_id]) | ||
| if show_keypoint_weight: | ||
| X = (x1, x2) | ||
| Y = (y1, y2) | ||
| mean_x = np.mean(X) | ||
| mean_y = np.mean(Y) | ||
| length = ((Y[0] - Y[1]) ** 2 + (X[0] - X[1]) ** 2) ** 0.5 | ||
| angle = math.degrees(math.atan2(Y[0] - Y[1], X[0] - X[1])) | ||
| polygon = cv2.ellipse2Poly( | ||
| (int(mean_x), int(mean_y)), (int(length / 2), int(stick_width)), int(angle), 0, 360, 1 | ||
| ) | ||
| cv2.fillConvexPoly(image, polygon, color) | ||
| transparency = max(0, min(1, 0.5 * (keypoints[sk[0], 2] + keypoints[sk[1], 2]))) | ||
| cv2.addWeighted(image, transparency, image, 1 - transparency, 0, dst=image) | ||
| else: | ||
| cv2.line(image, (x1, y1), (x2, y2), color, thickness=thickness) | ||
|
|
||
| # ์ฃผ์: keypoint_edges์ ์์ ํ๋ ํธ๋ ๋ฐ์ดํฐ์ ๋ณ๋ก ๋ค๋ฆ ๋๋ค | ||
| keypoint_edges = model.config.edges | ||
|
|
||
| palette = np.array( | ||
| [ | ||
| [255, 128, 0], | ||
| [255, 153, 51], | ||
| [255, 178, 102], | ||
| [230, 230, 0], | ||
| [255, 153, 255], | ||
| [153, 204, 255], | ||
| [255, 102, 255], | ||
| [255, 51, 255], | ||
| [102, 178, 255], | ||
| [51, 153, 255], | ||
| [255, 153, 153], | ||
| [255, 102, 102], | ||
| [255, 51, 51], | ||
| [153, 255, 153], | ||
| [102, 255, 102], | ||
| [51, 255, 51], | ||
| [0, 255, 0], | ||
| [0, 0, 255], | ||
| [255, 0, 0], | ||
| [255, 255, 255], | ||
| ] | ||
| ) | ||
|
|
||
| link_colors = palette[[0, 0, 0, 0, 7, 7, 7, 9, 9, 9, 9, 9, 16, 16, 16, 16, 16, 16, 16]] | ||
| keypoint_colors = palette[[16, 16, 16, 16, 16, 9, 9, 9, 9, 9, 9, 0, 0, 0, 0, 0, 0]] | ||
|
|
||
| numpy_image = np.array(image) | ||
|
|
||
| for pose_result in image_pose_result: | ||
| scores = np.array(pose_result["scores"]) | ||
| keypoints = np.array(pose_result["keypoints"]) | ||
|
|
||
| # ์ด๋ฏธ์ง์ ๊ฐ ํฌ์ธํธ๋ฅผ ๊ทธ๋ฆฝ๋๋ค | ||
|
jihyun-0611 marked this conversation as resolved.
Resolved
|
||
| draw_points(numpy_image, keypoints, scores, keypoint_colors, keypoint_score_threshold=0.3, radius=4, show_keypoint_weight=False) | ||
|
|
||
| # ๋งํฌ๋ฅผ ๊ทธ๋ฆฝ๋๋ค | ||
|
jihyun-0611 marked this conversation as resolved.
Resolved
|
||
| draw_links(numpy_image, keypoints, scores, keypoint_edges, link_colors, keypoint_score_threshold=0.3, thickness=1, show_keypoint_weight=False) | ||
|
|
||
| pose_image = Image.fromarray(numpy_image) | ||
| pose_image | ||
| ``` | ||
|
|
||
| ## ๋ฆฌ์์ค[[resources]] | ||
|
|
||
| ViTPose ์ฌ์ฉ์ ๋ํด ๋ ์์๋ณด๋ ค๋ฉด ์๋ ๋ฆฌ์์ค๋ฅผ ์ฐธ์กฐํ์ธ์. | ||
|
|
||
| - ์ด [notebook](https://github.com/NielsRogge/Transformers-Tutorials/blob/master/ViTPose/Inference_with_ViTPose_for_body_pose_estimation.ipynb)์ ์ถ๋ก ๊ณผ ์๊ฐํ๋ฅผ ๋ณด์ฌ์ค๋๋ค. | ||
| - ์ด [Space](https://huggingface.co/spaces/hysts/ViTPose-transformers)๋ ์ด๋ฏธ์ง์ ๋น๋์ค์์ ViTPose๋ฅผ ๋ณด์ฌ์ค๋๋ค. | ||
|
|
||
| ## VitPoseImageProcessor | ||
|
|
||
| [[autodoc]] VitPoseImageProcessor | ||
| - preprocess | ||
| - post_process_pose_estimation | ||
|
|
||
| ## VitPoseConfig | ||
|
|
||
| [[autodoc]] VitPoseConfig | ||
|
|
||
| ## VitPoseForPoseEstimation | ||
|
|
||
| [[autodoc]] VitPoseForPoseEstimation | ||
| - forward | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.