File size: 4,006 Bytes
7bd850b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import json
import os
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from matplotlib.patches import Patch

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("/Users/gongsitong/Desktop/dataset_processing/Ref_LVOS/category.json", "r"))["category"]
category_dict = dict()

for category in category_list:
    category_dict[category] = 0
    
category_list = []
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"])
            category_dict[exp_dict["category"]] += 1
        else:
            for category in exp_dict["category"]:
                category_dict[category] += 1
        
# print(set(category_list))
print(category_dict)

# 分组字典
category_group_map = {
    "Transportation": ['car', 'bus', 'motorcycle', 'helicopter'],
    "Daily Object": [
        'bag', 'electronic', 'furniture', 'sign', 'rope', 'cup', 'bottle', 'can', 'tool', 'box', 'card', 'food', "accessory"
    ],
    # "Food": [  ], 
    "Animal": [
        'bird', 'cattle', 'sheep', 'squirrel', 'cat', 'giraffe', 'elephant',
        'kangaroo', 'rabbit', 'zebra', 'bear', 'dog', 'fish', 'primate'
    ],
    "Sports": [ 'dartboard', 'bowling', 'puck', 'billiards', 'basketball', 'frisbee', 'paddle', "pusher", "kite"],
    "Person": ['pedestrian', 'performer', 'exerciser', 'worker', 'observer', 'athlete', 'player', 'dancer', 'skator']
}

# 创建 DataFrame
df = pd.DataFrame(list(category_dict.items()), columns=['Category', 'Count'])

# 颜色映射
color_map = {
    "Transportation": '#00BFFF',
    "Daily Object": '#F5516F',
    "Animal": '#ADFF2F',
    "Sports": '#BBBBBB',
    "Person": '#FFCD5C'
    # "Other": '#BBBBBB',
    # "Food": '#D94F4F',   
}

# 添加 Group 列
def assign_group(cat):
    for group, members in category_group_map.items():
        if cat in members:
            return group
    return 'Other'

df['Group'] = df['Category'].apply(assign_group)
df['Color'] = df['Group'].map(color_map)

df = df.sort_values(by=['Group', 'Count'], ascending=[True, False])

# 排序
# df = df.sort_values(by='Count', ascending=False)

# 绘图
# plt.rcParams['font.family'] = 'serif'
# plt.figure(figsize=(24, 6))
# bars = plt.bar(df['Category'], df['Count'], color=df['Color']) #, edgecolor='black')
# plt.yscale("log")
# plt.xticks(rotation=90)
# plt.ylabel("Expression Count (log scale)")
# # plt.title("Expression References per Object Category by Group")
# plt.margins(x=0.01)  # ✅ 减少图像两边空白

# # 添加图例
# legend_elements = [Patch(facecolor=color_map[g], label=g) for g in color_map]
# plt.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(1.01, 1))
# # 保存图像
# plt.tight_layout()
# plt.savefig("category_expression.png", dpi=300, bbox_inches="tight")
# plt.close()


# ================= 修改部分开始 =================

# 1. 设置全局字体大小 (基础大小)
plt.rcParams['font.family'] = 'serif'
plt.rcParams['font.size'] = 14  # 调大基础字体

plt.figure(figsize=(24, 6))
bars = plt.bar(df['Category'], df['Count'], color=df['Color'])

plt.yscale("log")

# 2. 调大 X 轴刻度字体
plt.xticks(rotation=90, fontsize=18) 

# 3. 调大 Y 轴标签字体
plt.ylabel("Expression Count (log scale)", fontsize=16)

plt.margins(x=0.01)

# 4. 调大图例字体
legend_elements = [Patch(facecolor=color_map[g], label=g) for g in color_map]
plt.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(1.01, 1), fontsize=14)

plt.tight_layout()
plt.savefig("category_expression_large_font.png", dpi=300, bbox_inches="tight")
plt.close() # 显示图片

# ================= 修改部分结束 =================