support frames packing for minicpmv4_5 video processing#8046
support frames packing for minicpmv4_5 video processing#8046fanqiNO1 wants to merge 5 commits intomodelscope:mainfrom
Conversation
Summary of ChangesHello @fanqiNO1, 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 enhances the video processing capabilities of the MiniCPM-V-4.5 model by implementing a frames packing mechanism. This feature allows for more optimized handling of video inputs through intelligent frame sampling and grouping, which is expected to improve performance and resource utilization for video-based tasks. The changes include the introduction of new configuration parameters and core logic for managing video frames. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
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.
Code Review
This pull request adds support for frames packing in video processing for the MiniCPM-V 4.5 model. The changes include adding a new video loading utility, updating the corresponding model template, and documenting the new command-line parameters.
My review focuses on improving code maintainability and documentation consistency. I've pointed out some code duplication in the template class and suggested refactoring opportunities in the vision utilities. I also found some minor formatting inconsistencies in the documentation files. Overall, the implementation of the new feature seems correct and follows the project's patterns.
| def map_to_nearest_scale(values, scale): | ||
| tree = cKDTree(np.asarray(scale)[:, None]) | ||
| _, indices = tree.query(np.asarray(values)[:, None]) | ||
| return np.asarray(scale)[indices] | ||
|
|
||
| def group_array(arr, size): | ||
| return [arr[i:i+size] for i in range(0, len(arr), size)] |
There was a problem hiding this comment.
The helper functions map_to_nearest_scale and group_array are defined inside load_video_minicpmv4_5. To improve code organization and potential reusability, consider moving them to the module level as private functions (e.g., _map_to_nearest_scale and _group_array), similar to how _uniform_sample was refactored.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
PR type
PR information
According to the "Chat With Video" feature of MiniCPM-V-4.5 on https://modelscope.cn/models/OpenBMB/MiniCPM-V-4_5, I implemented frames packing to enable more efficient video processing for MiniCPM-V 4.5.
Experiment results
I verified that the behavior of my implementation is consistent with that of the official provided script. The script is as follows:
script