Args: region_target_height (int): Height without the padding, the padding will be scaled together region_target_width (int): Width without the padding, the padding will be scaled together test_num_frames (int): Sampled number of frames f
(data_parent_path, region_target_height, region_target_width, is_frame_in=True)
| 23 | |
| 24 | |
| 25 | def INO_VLM_evaluation(data_parent_path, region_target_height, region_target_width, is_frame_in=True): |
| 26 | ''' |
| 27 | Args: |
| 28 | region_target_height (int): Height without the padding, the padding will be scaled together |
| 29 | region_target_width (int): Width without the padding, the padding will be scaled together |
| 30 | test_num_frames (int): Sampled number of frames from the GT and GEN generated results |
| 31 | is_frame_in (bool): Whether frame_in or frame out |
| 32 | ''' |
| 33 | |
| 34 | |
| 35 | # Prepare the pretrained weight |
| 36 | vlm_model_path = "Qwen/Qwen2.5-VL-32B-Instruct" |
| 37 | |
| 38 | |
| 39 | # Prepare the VLM Setting |
| 40 | device = "cuda" |
| 41 | llm_fps = 1 |
| 42 | test_num_frames = 14 # Override it, Qwen cannot take in too many frames; 14 is a moderate value |
| 43 | |
| 44 | |
| 45 | # Define the Instruction Prompt |
| 46 | if not is_frame_in: # Frame Out Instruction Prompt |
| 47 | instruction_prompt = "Please check if the object leave the frame. Return a Yes/No as the only response." |
| 48 | else: # Frame In |
| 49 | instruction_prompt = "Please check if the object enter the frame. Return a Yes/No as the only response." |
| 50 | |
| 51 | |
| 52 | # Messages containing a local video path and a text query |
| 53 | messages = [ |
| 54 | { |
| 55 | "role": "user", |
| 56 | "content": [ |
| 57 | { |
| 58 | "type": "video", |
| 59 | # "video": video_path, |
| 60 | "max_pixels": 360 * 420, # The video information here should be deprecated |
| 61 | "fps": llm_fps, |
| 62 | }, |
| 63 | { |
| 64 | "type": "text", |
| 65 | "text": instruction_prompt, |
| 66 | }, |
| 67 | ], |
| 68 | } |
| 69 | ] |
| 70 | |
| 71 | |
| 72 | |
| 73 | # Init the QWen VLM Model |
| 74 | processor = AutoProcessor.from_pretrained(vlm_model_path) |
| 75 | bnb_config = BitsAndBytesConfig( |
| 76 | load_in_4bit=True, |
| 77 | bnb_4bit_compute_dtype=torch.float16, # Use float16 for computations |
| 78 | bnb_4bit_use_double_quant=True, |
| 79 | bnb_4bit_quant_type='nf4', # NormalFloat4 quantization |
| 80 | ) |
| 81 | model = Qwen2_5_VLForConditionalGeneration.from_pretrained( |
| 82 | vlm_model_path, |
no test coverage detected