Download dataset_analysis.py from SitongGong/Ref_LVOS: direct link, hf CLI and curl.
- Browser
- Download file 2.57 kB
-
https://huggingface.co/datasets/SitongGong/Ref_LVOS/resolve/main/dataset_analysis.py
- Command line
-
hf download hf://datasets/SitongGong/Ref_LVOS/dataset_analysis.py
-
curl -L -o dataset_analysis.py https://huggingface.co/datasets/SitongGong/Ref_LVOS/resolve/main/dataset_analysis.py
2.57 kB
| import json | |
| import os | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| from PIL import Image | |
| num_objects = 0 | |
| num_frames = 0 | |
| num_masks = 0 | |
| category_item = [] | |
| json_path = "/Users/gongsitong/Desktop/dataset_processing/Ref_LVOS/video_exp.json" | |
| json_dict = json.load(open(json_path, 'r'))["videos"] | |
| # category_list = json.load(open("/[REDACTED_PHONE]/RefLVOS/category.json", "r"))["category"] | |
| # category_dict = dict() | |
| # for category in category_list: | |
| # category_dict[category] = 0 | |
| category_list = [] | |
| word_number = [] | |
| num_objects = 0 | |
| for video_name, video_dict in json_dict.items(): | |
| new_obj_id = -1 | |
| num_frames += len(video_dict["frames"]) | |
| for exp_id, exp_dict in video_dict["expressions"].items(): | |
| if type(exp_dict["category"]) != list: | |
| category_list.append(exp_dict["category"]) | |
| word_number.append(len(exp_dict["human_exp"].strip().split())) | |
| for obj_id in exp_dict["obj_id"]: | |
| if int(obj_id) != new_obj_id: | |
| new_obj_id = int(obj_id) | |
| num_objects += 1 | |
| num_masks += len(video_dict["frames"]) * (new_obj_id + 1) | |
| print("the categories: ", set(category_list)) | |
| print("total number of objects: ", num_objects) | |
| print("mean word number of references", sum(word_number) / len(word_number)) | |
| print("num masks", num_masks) | |
| # for obj_id in exp_dict["obj_id"]: | |
| # if int(obj_id) != new_obj_id: | |
| # new_obj_id = int(obj_id) | |
| # num_objects += 1 | |
| # num_masks += len(video_dict["frames"]) * (new_obj_id + 1) | |
| # print(num_objects) | |
| # print(num_frames) | |
| # print(num_masks) | |
| meta_video_dict = dict() | |
| vid_id = 0 | |
| new_video_dict = dict() | |
| for video_name, video_dict in json_dict.items(): | |
| new_exp_dict = dict() | |
| for exp_id, exp_dict in video_dict["expressions"].items(): | |
| new_exp_dict[exp_id] = {"exp": exp_dict["human_exp"], | |
| "obj_id": exp_dict["obj_id"], | |
| "category": exp_dict["category"]} | |
| new_video_dict[video_name] = {"expressions": new_exp_dict, | |
| "vid_id": vid_id, | |
| "height": video_dict["height"], | |
| "width": video_dict["width"], | |
| "frames": video_dict["frames"]} | |
| output_dict = {"videos": new_video_dict} | |
| output_path = "/Users/gongsitong/Desktop/dataset_processing/Ref_LVOS/final_meta_expressions.json" | |
| with open(output_path, 'w') as f: | |
| json_string = json.dumps(output_dict, indent=4) | |
| f.write(json_string) |