|
|
import os |
|
|
import json |
|
|
from datasets import load_dataset |
|
|
|
|
|
def load_json(file_path): |
|
|
with open(file_path, 'r', encoding='utf-8') as f: |
|
|
data = json.load(f) |
|
|
return data |
|
|
|
|
|
class DatasetSaver: |
|
|
def __init__(self, data_root): |
|
|
self.data_root = data_root |
|
|
|
|
|
self.split_file = os.path.join(self.data_root, "valid_one_points_indices.json") |
|
|
self.one_point_indices = load_json(self.split_file)["index"] |
|
|
|
|
|
|
|
|
def save_data(self): |
|
|
dataset = load_dataset("allenai/pixmo-points", split="train", cache_dir=self.data_root) |
|
|
|
|
|
for idx in self.one_point_indices: |
|
|
|
|
|
print(f" {idx + 1} files...",idx/len(dataset)*100,"%") |
|
|
|
|
|
data = dataset[idx] |
|
|
file_path = os.path.join(self.data_root, f"pixmo_data/{idx}.json") |
|
|
with open(file_path, "w", encoding="utf-8") as f: |
|
|
json.dump(data, f, ensure_ascii=False, indent=4) |
|
|
print('saved') |
|
|
|
|
|
|
|
|
|
|
|
print("All data saved successfully.") |
|
|
|
|
|
|
|
|
data_saver = DatasetSaver('/home/rongtao/jianzhang/pixmo-points/Datasets') |
|
|
data_saver.save_data() |
|
|
|