-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_dataset.py
38 lines (32 loc) · 935 Bytes
/
prepare_dataset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json
import torch
import copy
from PIL import Image
from PIL import ImageFile
import os
from pathlib import Path
from phi3v_dataset import Phi3VDataset, Phi3VEvalDataset
def apply_chat_template(
example,
tokenizer,
):
messages = example["messages"]
example["text"] = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False)
return example
def create_dataset(data_dir, processor):
"""
Using dataset from preprocessed folder
"""
data_path = Path(data_dir)
train_dataset = Phi3VDataset(
jsonl_file=str(data_path / 'quilt_1m_train.jsonl'),
image_dir=str(data_path / 'quilt_1m'),
processor=processor,
)
eval_dataset = Phi3VEvalDataset(
jsonl_file=str(data_path / 'quilt_1m_val.jsonl'),
image_dir=str(data_path / 'quilt_1m'),
processor=processor,
)
return train_dataset, eval_dataset