pixmo-points / dataset_statistics_json.py
Jian Zhang
Upload 8 files
a03ed61 verified
import os
import hashlib
import datasets
import json
root_path = './Datasets/'
data = datasets.load_dataset("allenai/pixmo-points", split="train", cache_dir=root_path)
len_data = len(data)
image_folder = os.path.join(root_path,"pixmo_images")
hash_image_all = set()
indices_one_point_all = []
hash_image_one_point_all = set()
record = {'index':[],'image_hash':set()}
for i,example in enumerate(data):
print(i,len_data,f"{(i / len_data) * 100:.3f}%")
points = example['points']
image_hash = example["image_sha256"]
if len(points) == 1:
indices_one_point_all.append(i)
hash_image_one_point_all.add(image_hash)
hash_image_all.add(image_hash)
image_url = example["image_url"]
image_path = os.path.join(image_folder, f"{image_hash}.jpg")
if not os.path.exists(image_path):
print('image does not exist, skip')
continue # 图片不存在,跳过
if os.path.exists(image_path) and len(points)==1:
record['index'].append(i)
record['image_hash'].add(image_hash)
record['number of indices'] = len(record['index'])
record['number of images'] = len(record['image_hash'])
print('all images',len(hash_image_all))
print('all one point',len(indices_one_point_all),len(hash_image_one_point_all))
print('downloaded one ponit','number of indices',len(record['index']),'images:',len(record['image_hash']))
record['image_hash'] = list(record['image_hash'])
with open("valid_one_points_indices.json", "w") as f:
json.dump(record, f, indent=4)