Upload VideoX-Fun/get_prompt_qa3.py
Browse files- VideoX-Fun/get_prompt_qa3.py +90 -0
VideoX-Fun/get_prompt_qa3.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import json
|
| 3 |
+
import pdb
|
| 4 |
+
import csv
|
| 5 |
+
import torch
|
| 6 |
+
import os
|
| 7 |
+
import itertools
|
| 8 |
+
# df = pd.read_csv('/nfs/ywang29/video_reward/VideoAlign/datasets/train/ours_reasoning_dataset.csv')
|
| 9 |
+
# df = pd.read_csv('/nfs/ywang29/Reward_finetuning/VideoX-Fun/ours_data_binary.csv', sep='\t')
|
| 10 |
+
# df = df.drop_duplicates(subset=['prompt'])
|
| 11 |
+
def clean_text(x: str) -> str:
|
| 12 |
+
"""去掉多余的换行、制表符、引号"""
|
| 13 |
+
if not isinstance(x, str):
|
| 14 |
+
x = str(x)
|
| 15 |
+
return (
|
| 16 |
+
x.replace("\n", " ") # 换行变空格
|
| 17 |
+
.replace("\r", " ")
|
| 18 |
+
.replace('"""', '"')
|
| 19 |
+
.replace("'''", "'")
|
| 20 |
+
.strip()
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
path ='/nfs/ywang29/Reward_finetuning/VideoX-Fun/data/preprocess_general'
|
| 24 |
+
root = '/nfs/ywang29/Reward_finetuning/VideoX-Fun'
|
| 25 |
+
rg_dict = {}
|
| 26 |
+
rg_dict1 = {}
|
| 27 |
+
with open('/nfs/ywang29/vr_datasets.json', 'r') as f:
|
| 28 |
+
data = json.load(f)
|
| 29 |
+
for sample in data:
|
| 30 |
+
# pdb.set_trace()
|
| 31 |
+
rg_dict1[sample['video_id'].split('.mp4')[0]] = sample['prompt']
|
| 32 |
+
rg_dict[sample['video_id']] = sample['real_video']
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
new_data = []
|
| 36 |
+
top_row = ['video_id', 'real_video_path', 'ref_video', 'prompt', 'questions', 'gt_answers']
|
| 37 |
+
new_data.append(top_row)
|
| 38 |
+
|
| 39 |
+
# pdb.set_trace()
|
| 40 |
+
for file in os.listdir(path):
|
| 41 |
+
video_id = file.split('.pt')[0]
|
| 42 |
+
prompt = rg_dict1[video_id]
|
| 43 |
+
content = torch.load(f"{path}/{file}")
|
| 44 |
+
|
| 45 |
+
if len(content) == 0:
|
| 46 |
+
continue
|
| 47 |
+
for question in content.keys():
|
| 48 |
+
ref_video = content[question]['ref_video']
|
| 49 |
+
import pdb
|
| 50 |
+
# pdb.set_trace()
|
| 51 |
+
# ref_video = f'/s3-code/ywang29/video_reward/WanI2V/WanI2V-480p-{video_id}.mp4'
|
| 52 |
+
if not os.path.exists(ref_video):
|
| 53 |
+
continue
|
| 54 |
+
|
| 55 |
+
new_line = [video_id, ref_video, ref_video, clean_text(prompt), [question.replace('<video>', '')], [content[question]['response']]]
|
| 56 |
+
new_data.append(new_line)
|
| 57 |
+
|
| 58 |
+
phy_question = f'''You are a careful video forensics assistant. You are given two videos: a test video (the first 24 frames) which is ai-generated and a real video (the last 12 frames). The test video is generated by the caption of the real video. The caption is "{prompt}"
|
| 59 |
+
Your task is evaluating whether the test video shows physics-related defects. You should compared both videos and use the provided caption as high-level intent. Focus on physical plausibility, not style or aesthetics.
|
| 60 |
+
You need to analyze it in these aspects:
|
| 61 |
+
- Liquid flow irregularity – e.g., non-inertial or discontinuous flow, volume popping, gravity-inconsistent motion, impossible splashes.
|
| 62 |
+
- Abnormal object deformation – e.g., rigid objects bending/stretching without cause, topology changes (parts merging/splitting).
|
| 63 |
+
- Abnormal texture/material change – e.g., surface turns matte→glossy without cause, texture swimming/flicker detached from geometry.
|
| 64 |
+
- Abnormal motion – e.g., inertia/acceleration violations, teleporting, time reversals, jitter not explained by camera motion.
|
| 65 |
+
- Unnatural interpenetration – e.g., objects passing through each other or ground, missing collisions/contacts.
|
| 66 |
+
If the prompt doesn't have related physical aspects, you should answer 'No'.
|
| 67 |
+
'''
|
| 68 |
+
# Output strictly as JSON with this schema (no extra text):
|
| 69 |
+
# {{
|
| 70 |
+
# "liquid_flow_irregularity": "Yes/No",
|
| 71 |
+
# "abnormal_deformation": "Yes/No",
|
| 72 |
+
# "abnormal_texture_change": "Yes/No",
|
| 73 |
+
# "abnormal_motion": "Yes/No",
|
| 74 |
+
# "unnatural_interpenetration": "Yes/No",
|
| 75 |
+
# }}
|
| 76 |
+
# phy_gt = '''```json\n{\n "liquid_flow_irregularity": "No",\n "abnormal_deformation": "No",\n "abnormal_texture_change": "No",\n "abnormal_motion": "No",\n "unnatural_interpenetration": "No"\n}\n```'''
|
| 77 |
+
phy_gt = '{\n "liquid_flow_irregularity": "No",\n "abnormal_deformation": "No",\n "abnormal_texture_change": "No",\n "abnormal_motion": "No",\n "unnatural_interpenetration": "No"\n}'
|
| 78 |
+
|
| 79 |
+
new_line = [video_id, ref_video, ref_video, clean_text(prompt), [phy_question], [phy_gt]]
|
| 80 |
+
# new_data.append(new_line)
|
| 81 |
+
|
| 82 |
+
# pdb.set_trace()
|
| 83 |
+
|
| 84 |
+
with open(f'{root}/ours_data_large_binary_single_question_with_gt_general.csv', 'w', newline='', encoding='utf-8-sig') as csvfile:
|
| 85 |
+
# 创建一个 csv writer 对象
|
| 86 |
+
writer = csv.writer(csvfile, delimiter='\t')
|
| 87 |
+
# 写入所有数据行
|
| 88 |
+
writer.writerows(new_data)
|
| 89 |
+
|
| 90 |
+
# * Fair: Some requirements are satisfied but some not.
|