-
Notifications
You must be signed in to change notification settings - Fork 283
[WIP] support mmpose and image tagging with vlm #800
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @Cathy0908, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly expands the multimodal processing capabilities by introducing new mappers for advanced image analysis. It enables the generation of detailed image tags using Visual Language Models and facilitates human keypoint detection through MMPose models, leveraging Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces support for mmpose and VLM-based image tagging by adding two new mappers, MMPoseMapper and ImageTaggingVLMMapper, along with supporting utility functions and tests. My review focuses on improving correctness, performance, and test quality. Key findings include a bug in prompt construction for the VLM mapper, inefficient batch handling in the mmpose mapper, and several issues in the new tests such as hardcoded paths and reliance on external models, which should be mocked for better reliability and portability.
| def test(self): | ||
| ds_list = [{ | ||
| 'images': [self.img1_path] | ||
| }, { | ||
| 'images': [self.img2_path] | ||
| }, { | ||
| 'images': [self.img3_path] | ||
| }] | ||
| tgt_list = [{ | ||
| 'images': [self.img1_path], | ||
| Fields.meta: { | ||
| MetaKeys.image_tags: [[ | ||
| 'bed', 'pillow', 'mattress', 'bedroom', 'home', 'comfort', 'sleeping', 'house']]}, | ||
| }, { | ||
| 'images': [self.img2_path], | ||
| Fields.meta: { | ||
| MetaKeys.image_tags: [[ | ||
| 'bus', 'advertisement', 'street scene', 'city life', 'tour bus', | ||
| 'travel service', 'urban environment', 'local transportation', 'daylight']]}, | ||
| }, { | ||
| 'images': [self.img3_path], | ||
| Fields.meta: { | ||
| MetaKeys.image_tags: [[ | ||
| 'urban', 'alley', 'rainy-day', 'building', 'person', 'umbrella', 'sidewalk', | ||
| 'black-and-white', '/blackandwhite', 'shoe', 'clothing', 'architecture', | ||
| 'trees', 'reflection', 'exploration']]}, | ||
| }] | ||
| op = ImageTaggingVLMMapper( | ||
| api_or_hf_model="Qwen2.5-VL-7B-Instruct", | ||
| is_api_model=False, | ||
| model_params={"tensor_parallel_size": 1} | ||
| ) | ||
| self._run_image_tagging_vlm_mapper(op, ds_list, tgt_list) | ||
|
|
||
| def test_no_images(self): | ||
| ds_list = [{ | ||
| 'images': [] | ||
| }, { | ||
| 'images': [self.img2_path] | ||
| }] | ||
| tgt_list = [{ | ||
| 'images': [], | ||
| Fields.meta: { | ||
| MetaKeys.image_tags: [[]]}, | ||
| }, { | ||
| 'images': [self.img2_path], | ||
| Fields.meta: { | ||
| MetaKeys.image_tags: [[ | ||
| 'bus', 'advertisement', 'street scene', 'city life', 'tour bus', | ||
| 'travel service', 'urban environment', 'local transportation', 'daylight']]}, | ||
| }] | ||
| op = ImageTaggingVLMMapper( | ||
| api_or_hf_model="Qwen2.5-VL-7B-Instruct", | ||
| is_api_model=False, | ||
| model_params={"tensor_parallel_size": 1} | ||
| ) | ||
| self._run_image_tagging_vlm_mapper(op, ds_list, tgt_list) | ||
|
|
||
| def test_api_model(self): | ||
|
|
||
| ds_list = [{ | ||
| 'images': [] | ||
| }, { | ||
| 'images': [self.img2_path] | ||
| }] | ||
| tgt_list = [{ | ||
| 'images': [], | ||
| Fields.meta: { | ||
| MetaKeys.image_tags: [[]]}, | ||
| }, { | ||
| 'images': [self.img2_path], | ||
| Fields.meta: { | ||
| MetaKeys.image_tags: [[ | ||
| 'bus', 'advertisement', 'street scene', 'city life', 'tour bus', | ||
| 'travel service', 'urban environment', 'local transportation', 'daylight']]}, | ||
| }] | ||
|
|
||
| op = ImageTaggingVLMMapper( | ||
| api_or_hf_model='qwen2.5-vl-3b-instruct', | ||
| is_api_model=True, | ||
| ) | ||
| self._run_image_tagging_vlm_mapper(op, ds_list, tgt_list) | ||
|
|
||
| def test_specify_tag_fieldl(self): | ||
| tag_field_name = 'my_tags' | ||
|
|
||
| ds_list = [{ | ||
| 'images': [] | ||
| }, { | ||
| 'images': [self.img2_path] | ||
| }] | ||
| tgt_list = [{ | ||
| 'images': [], | ||
| Fields.meta: { | ||
| tag_field_name: [[]]}, | ||
| }, { | ||
| 'images': [self.img2_path], | ||
| Fields.meta: { | ||
| tag_field_name: [[ | ||
| 'bus', 'advertisement', 'street scene', 'city life', 'tour bus', | ||
| 'travel service', 'urban environment', 'local transportation', 'daylight']]}, | ||
| }] | ||
|
|
||
| op = ImageTaggingVLMMapper( | ||
| api_or_hf_model="Qwen2.5-VL-7B-Instruct", | ||
| is_api_model=False, | ||
| tag_field_name=tag_field_name, | ||
| model_params={"tensor_parallel_size": 1} | ||
| ) | ||
| self._run_image_tagging_vlm_mapper(op, ds_list, tgt_list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are implemented as integration tests that rely on real model inference and external API calls. This makes them slow, non-deterministic, and dependent on specific hardware (GPU) and environment setup (API keys). Unit tests should be fast, deterministic, and isolated. Please refactor these tests to use mocking to simulate the model's output, which will make them more reliable and suitable for a CI/CD pipeline.
| def test_mmpose_mapper(self): | ||
| data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'data') | ||
| img1 = os.path.join(data_path, 'img3.jpg') | ||
| img2 = os.path.join(data_path, 'img8.jpg') | ||
|
|
||
| base_dir = '/mnt/workspace/mmdeploy/' | ||
| deploy_cfg = base_dir + 'configs/mmpose/pose-detection_onnxruntime_static.py' | ||
| model_cfg = base_dir + 'td-hm_hrnet-w32_8xb64-210e_coco-256x192.py' | ||
| backend_model = [base_dir + 'mmdeploy_models/mmpose/ort/end2end.onnx'] | ||
|
|
||
| ds_list = [{ | ||
| 'text': f'{SpecialTokens.image}a photo', | ||
| 'images': [img2] | ||
| }, { | ||
| 'text': f'{SpecialTokens.image}a photo, a women with an umbrella', | ||
| 'images': [img1] | ||
| }] | ||
| dataset = Dataset.from_list(ds_list) | ||
|
|
||
| visualization_dir=os.path.join(self.tmp_dir, 'vis_outs') | ||
| op = MMPoseMapper( | ||
| deploy_cfg=deploy_cfg, | ||
| model_cfg=model_cfg, | ||
| model_files=backend_model, | ||
| visualization_dir=visualization_dir | ||
| ) | ||
|
|
||
| dataset = dataset.map(op.process, with_rank=True) | ||
| dataset_list = dataset.to_list() | ||
|
|
||
| for out in dataset_list: | ||
| pose_info = out[Fields.meta][MetaKeys.pose_info][0] | ||
| self.assertEqual(np.array(pose_info['bbox_scores']), (1, )) | ||
| self.assertEqual(np.array(pose_info['bboxes']).shape, (1, 4)) | ||
| self.assertEqual(np.array(pose_info['keypoint_names']).shape, (17, )) | ||
| self.assertEqual(np.array(pose_info['keypoint_scores'][0]).shape, (17, )) | ||
| self.assertEqual(np.array(pose_info['keypoints'][0]).shape, (17, 2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test relies on a real mmpose model and specific model files, making it an integration test. This approach is slow, brittle, and has external dependencies. For a unit test, you should mock the model calls and verify that the mapper processes the mocked output correctly. This will lead to faster and more reliable tests.
No description provided.