Wendy-Fly commited on
Commit
94bf4d8
·
verified ·
1 Parent(s): 0588bff

Upload infer_2.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. infer_2.py +6 -13
infer_2.py CHANGED
@@ -25,33 +25,26 @@ processor = AutoProcessor.from_pretrained(model_path)
25
  # processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
26
 
27
  messages = [
28
- {
29
- "role": "user",
30
- "content": [
31
- {
32
- "type": "image",
33
- "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
34
- },
35
- {"type": "text", "text": "Describe this image."},
36
- ],
37
- }
38
  ]
39
 
40
  # Preparation for inference
41
  text = processor.apply_chat_template(
42
  messages, tokenize=False, add_generation_prompt=True
43
  )
44
- image_inputs, video_inputs = process_vision_info(messages)
45
  inputs = processor(
46
  text=[text],
47
  images=image_inputs,
48
  videos=video_inputs,
 
49
  padding=True,
50
  return_tensors="pt",
 
51
  )
52
- inputs = inputs.to(model.device)
53
 
54
- # Inference: Generation of the output
55
  generated_ids = model.generate(**inputs, max_new_tokens=128)
56
  generated_ids_trimmed = [
57
  out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
 
25
  # processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
26
 
27
  messages = [
28
+ {'role': 'user', 'content': [{'type': 'video', 'video': '/home/zbz5349/WorkSpace/aigeeks/Qwen2.5-VL/dataset/data/new_Psychology_5.mp4', 'max_pixels': 151200, 'fps': 1.0}, {'type': 'image', 'image': '/home/zbz5349/WorkSpace/aigeeks/Qwen2.5-VL/dataset/images/new_Psychology_5.png', 'text': '<video> <image>Evaluate the following statements based on the video about different psychology research methods. Identify which statements are correct.\nStatements:\n1. A natural quasi-experiment involves the manipulation of independent variables by the researcher in a controlled environment to determine their effect on dependent variables.\n2. Naturalistic observation requires researchers to observe subjects in their natural environments without any interference or manipulation, thereby ensuring high ecological validity.\n3. Laboratory experiments allow researchers to control and manipulate variables precisely, which increases the internal validity of the study but may reduce its ecological validity.\n4. In a natural quasi-experiment, the independent variable is manipulated by the researcher to observe its effects on the dependent variable in a real-world setting.\n5. Correlational studies can establish causal relationships between variables by measuring the strength and direction of their association. this is a multiple-choice, options contain A : [Only Statements 2 and 3 are correct] B : [Statements 1, 2, and 3 are correct] C : [Statements 2, 3, and 4 are correct] D : [Statements 1, 3, and 5 are correct] E : [Only Statement 4 is correct] F : [Statements 2 and 4 are correct] G : [Statements 1, 2, 3, and 4 are correct] H : [Statements 3 and 5 are correct] I : [All statements are correct] J : [Statements 2, 3, 4, and 5 are correct] '}, {'type': 'text', 'text': 'Describe this video.'}]}
 
 
 
 
 
 
 
 
 
29
  ]
30
 
31
  # Preparation for inference
32
  text = processor.apply_chat_template(
33
  messages, tokenize=False, add_generation_prompt=True
34
  )
35
+ image_inputs, video_inputs, video_kwargs = process_vision_info(messages, return_video_kwargs=True)
36
  inputs = processor(
37
  text=[text],
38
  images=image_inputs,
39
  videos=video_inputs,
40
+ fps=fps,
41
  padding=True,
42
  return_tensors="pt",
43
+ **video_kwargs,
44
  )
45
+ inputs = inputs.to("cuda")
46
 
47
+ # Inference
48
  generated_ids = model.generate(**inputs, max_new_tokens=128)
49
  generated_ids_trimmed = [
50
  out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)