-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
released coin dataset scripts; preprocessing scripts with instruction…
…s; fix some typos
- Loading branch information
Showing
17 changed files
with
410 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,4 @@ __pycache__/ | |
*.json | ||
*.wav | ||
/demo/rendering/*.mp4 | ||
.DS_Store | ||
/data/preprocess | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +0,0 @@ | ||
|
||
- (optional) Also recommend to use higher ffmpeg version to get better video preprocessing: | ||
|
||
``` | ||
wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz | ||
tar xvf ffmpeg-release-amd64-static.tar.xz | ||
rm ffmpeg-release-amd64-static.tar.xz | ||
mv ffmpeg-6.1-amd64-static ffmpeg | ||
``` | ||
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import json, re | ||
|
||
annos = json.load(open('goalstep_livechat_trainval.json')) | ||
|
||
new_annos = [] | ||
for anno in annos: | ||
if not anno['conversation']: | ||
continue | ||
maintain = True | ||
anno['duration'] = anno['conversation'][-1]['time'] - anno['conversation'][0]['time'] | ||
if anno['duration'] < 60 or anno['duration'] > 3600: | ||
continue | ||
for message in anno['conversation']: | ||
if 'second' in message['content'] or re.match(r'\b\d+s\b', message['content']): # if the generated content contains time related text, it may leak the future ground-truth | ||
maintain = False | ||
break | ||
if maintain: | ||
new_annos.append(anno) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
### Distributed Preprocess Video Frames for VideoLLM-online | ||
|
||
#### Sample video frames to 2 FPS and max resolution 384 (with zero padding) | ||
|
||
``` | ||
python -m data.preprocess.ffmpeg --num_gpus 8 --frame_fps 2 --frame_resolution 384 --video_dir datasets/ego4d/v2/full_scale | ||
``` | ||
|
||
- Please run the script in ```videollm-online/``` root folder. | ||
|
||
- The results will be saved in a new folder with '{fps}fps_{resolution}' suffix. For example, ```datasets/ego4d/v2/full_scale -> datasets/ego4d/v2/full_scale_2fps_384```. | ||
|
||
- If you are on a cluster, you can set ```--num_nodes ... --slurm_partition ...``` to use them. The more nodes and GPUs, the faster preprocessing. | ||
|
||
#### Encode sampled 2fps_384 video frames | ||
|
||
``` | ||
python -m data.preprocess.encode --num_gpus 8 --video_dir datasets/ego4d/v2/full_scale_2fps_384 --vision_pretrained google/siglip-large-patch16-384 | ||
``` | ||
|
||
- Please run the script in ```videollm-online/``` root folder. | ||
|
||
- The results will be saved in a new folder with '{embed_mark}_{model}' suffix. For example, ```datasets/ego4d/v2/full_scale_2fps_384 -> datasets/ego4d/v2/full_scale_2fps_384_1+3x3_google--siglip-large-patch16-384```. | ||
|
||
- If you are on a cluster, you can set ```--num_nodes ... --slurm_partition ...``` to use them. The more nodes and GPUs, the faster preprocessing. | ||
|
||
#### Narration Refinement | ||
|
||
``` | ||
python -m data.preprocess.ego4d_narration_refinement --llm_pretrained meta-llama/Meta-Llama-3-8B-Instruct --anno_root datasets/ego4d/v2/annotations --split train | ||
python -m data.preprocess.ego4d_narration_refinement --llm_pretrained meta-llama/Meta-Llama-3-8B-Instruct --anno_root datasets/ego4d/v2/annotations --split val | ||
``` | ||
|
||
- Please run the script in ```videollm-online/``` root folder. | ||
|
||
- The results will be saved in a new json of 'refined_narration_stream_{args.split}' name. For example, ```datasets/ego4d/v2/annotations/narration_stream_train.json -> datasets/ego4d/v2/annotations/refined_narration_stream_train.json```. | ||
|
||
- If you are on a cluster, you can set ```--num_nodes ... --slurm_partition ...``` to use them. The more nodes and GPUs, the faster preprocessing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import json, torch, tqdm, os, functools, submitit | ||
from transformers import AutoModelForCausalLM, AutoTokenizer, HfArgumentParser | ||
from dataclasses import dataclass | ||
|
||
from models.arguments_live import LiveOnePlusTrainingArguments | ||
|
||
@dataclass | ||
class LiveOnePlusEncodingArguments(LiveOnePlusTrainingArguments): | ||
num_nodes: int = 1 | ||
num_gpus: int = 8 | ||
anno_root: str = 'datasets/ego4d/v2/annotations' | ||
split: str = 'train' | ||
|
||
@torch.no_grad() | ||
def distributed_refine_narration(args: LiveOnePlusEncodingArguments): | ||
env = submitit.JobEnvironment() | ||
torch.cuda.set_device(env.local_rank) | ||
|
||
model = AutoModelForCausalLM.from_pretrained(args.llm_pretrained, torch_dtype='auto', attn_implementation='sdpa') | ||
tokenizer = AutoTokenizer.from_pretrained(args.llm_pretrained, use_fast=True) | ||
tokenizer.pad_token = tokenizer.eos_token | ||
model.eval() | ||
model.to('cuda') | ||
generator = functools.partial(model.generate, max_new_tokens=64, do_sample=False, top_p=1.0, temperature=1.0, use_cache=True, pad_token_id=tokenizer.pad_token_id) | ||
|
||
anno_path = os.path.join(args.ego4d_anno_root, f'narration_stream_{args.split}.json') | ||
save_dir = os.path.join(args.ego4d_anno_root, f'refined_narration_stream_{args.split}') | ||
annos = json.load(open(anno_path)) | ||
os.makedirs(save_dir, exist_ok=True) | ||
mapping = {} | ||
|
||
annos = {video_uid: _annotation_uid_narrations for i, (video_uid, _annotation_uid_narrations) in tqdm.tqdm(enumerate(annos.items())) if not os.path.exists(os.path.join(save_dir, f'{video_uid}.json'))} | ||
for i, (video_uid, _annotation_uid_narrations) in tqdm.tqdm(enumerate(annos.items())): | ||
if i % env.num_tasks != env.global_rank: | ||
continue | ||
save_path = os.path.join(save_dir, f'{video_uid}.json') | ||
for _annotation_uid, narrations in _annotation_uid_narrations.items(): | ||
for narration in narrations: | ||
if narration['text'] not in mapping: | ||
chat = [ | ||
{ | ||
"role": "user", "content": ("Please help me to refine the text, e.g., [C looks around.] -> [You look around.]" | ||
"In the text, There are many uppercase letters to denote persons. Rewrite the sentence to avoid these uppercase letters, improve the text quality, make the text clear and concise. " | ||
"For example:\n[C looks around.] -> [You look around.]\n[A man X watches the phone.] -> [A man watches the phone.]\n" | ||
f"[C plays a piano, and a woman O comes to him.] -> [You play a piano, and a woman comes to you.]\n[Man A approaches C] -> [A man approaches you.]\n\nNow, please refine [{narration['text']}] -> ?, make the answer in [].") | ||
}, | ||
{"role": "assistant", "content": f"[{narration['text']}] -> ["} | ||
] | ||
input_ids = tokenizer.apply_chat_template(chat, tokenize=True, return_tensors='pt')[:,:-1].cuda() | ||
output_ids = generator(input_ids)[:, input_ids.size(1):] | ||
text = tokenizer.decode(output_ids[0], skip_special_tokens=True, clean_up_tokenization_spaces=True) | ||
try: | ||
mapping[narration['text']] = text[:text.index(']')] | ||
except: | ||
print('fuck', narration['text'], text) | ||
mapping[narration['text']] = 'Not sure what you are doing.' | ||
narration['text'] = mapping[narration['text']] | ||
|
||
json.dump(_annotation_uid_narrations, open(save_path, 'w'), indent=4) | ||
|
||
if __name__ == "__main__": | ||
args, = HfArgumentParser(LiveOnePlusEncodingArguments).parse_args_into_dataclasses() | ||
executor = submitit.AutoExecutor(folder=f"outputs/preprocess/") | ||
executor.update_parameters( | ||
tasks_per_node=args.num_gpus, | ||
nodes=args.num_nodes, | ||
gpus_per_node=args.num_gpus, | ||
cpus_per_task=10, | ||
mem_gb=240, | ||
slurm_time='24:00:00', | ||
) | ||
job = executor.submit(distributed_refine_narration, args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import submitit, functools, transformers | ||
from dataclasses import asdict, dataclass | ||
from models.vision_live import build_live_vision | ||
|
||
from models.configuration_live import LiveConfigMixin | ||
from models.arguments_live import LiveOnePlusTrainingArguments | ||
from ..utils import distributed_encode | ||
|
||
@dataclass | ||
class LiveOnePlusEncodingArguments(LiveOnePlusTrainingArguments): | ||
num_nodes: int = 1 | ||
num_gpus: int = 8 | ||
video_dir: str = 'datasets/ego4d/v2/full_scale_2fps_384' | ||
slurm_partition: str = None | ||
|
||
if __name__ == "__main__": | ||
args, = transformers.HfArgumentParser(LiveOnePlusEncodingArguments).parse_args_into_dataclasses() | ||
vision_config = LiveConfigMixin(**asdict(args)) | ||
_, vision_encode = build_live_vision(vision_config) | ||
task = functools.partial( | ||
distributed_encode, src_root=args.video_dir, | ||
vision_pretrained=args.vision_pretrained, | ||
embed_mark=args.embed_mark, | ||
vision_encode=vision_encode, | ||
batch_size=256, save_bf16=True | ||
) | ||
executor = submitit.AutoExecutor(folder=f"outputs/preprocess/") | ||
executor.update_parameters( | ||
tasks_per_node=args.num_gpus, | ||
nodes=args.num_nodes, | ||
gpus_per_node=args.num_gpus, | ||
cpus_per_task=10, | ||
slurm_partition=args.slurm_partition, | ||
mem_gb=240, | ||
slurm_time='24:00:00', | ||
) | ||
job = executor.submit(task) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from functools import partial | ||
import submitit, transformers | ||
from dataclasses import dataclass | ||
|
||
from models.arguments_live import LiveOnePlusTrainingArguments | ||
from ..utils import distributed_ffmpeg | ||
|
||
@dataclass | ||
class LiveOnePlusEncodingArguments(LiveOnePlusTrainingArguments): | ||
num_nodes: int = 1 | ||
num_gpus: int = 8 | ||
video_dir: str = 'datasets/ego4d/v2/full_scale' | ||
slurm_partition: str = None | ||
|
||
if __name__ == "__main__": | ||
args, = transformers.HfArgumentParser(LiveOnePlusEncodingArguments).parse_args_into_dataclasses() | ||
executor = submitit.AutoExecutor(folder=f"outputs/preprocess/") | ||
task = partial(distributed_ffmpeg, src_root=args.video_dir, resolution=args.frame_resolution, fps=args.frame_fps) | ||
executor.update_parameters( | ||
tasks_per_node=args.num_gpus, | ||
nodes=args.num_nodes, | ||
gpus_per_node=args.num_gpus, | ||
slurm_partition=args.slurm_partition, | ||
cpus_per_task=10, | ||
mem_gb=240, | ||
slurm_time='24:00:00', | ||
) | ||
job = executor.submit(task) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.