|
|
import json |
|
|
from collections import Counter, OrderedDict |
|
|
import matplotlib.pyplot as plt |
|
|
|
|
|
|
|
|
file_path = '/share/project/sunshuang/deep_search/data_for_rl/musique_tagged/final_selected_dataset.json' |
|
|
|
|
|
with open(file_path, 'r') as f: |
|
|
data = json.load(f) |
|
|
|
|
|
|
|
|
key_points_counter = Counter() |
|
|
|
|
|
for entry in data: |
|
|
domain_keypoints = entry.get('domain_keypoints', {}) |
|
|
key_points = domain_keypoints.get('key_points', []) |
|
|
key_points_counter.update(key_points) |
|
|
|
|
|
|
|
|
|
|
|
key_points_counter = OrderedDict(sorted(key_points_counter.items(), key=lambda item: item[1], reverse=True)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
key_points_count_file = 'key_points_count.json' |
|
|
with open(key_points_count_file, 'w') as f: |
|
|
json.dump(dict(key_points_counter), f, indent=4) |
|
|
|
|
|
print(f"Key points count saved to '{key_points_count_file}'") |
|
|
|
|
|
|
|
|
labels = [f'{key} ({count})' for key, count in key_points_counter.items()] |
|
|
sizes = list(key_points_counter.values()) |
|
|
|
|
|
plt.figure(figsize=(12, 7)) |
|
|
plt.pie( |
|
|
sizes, |
|
|
labels=labels, |
|
|
autopct='%1.1f%%', |
|
|
startangle=140 |
|
|
) |
|
|
plt.title('Key Points Distribution') |
|
|
plt.tight_layout() |
|
|
plt.savefig('key_points_distribution_pie.png', bbox_inches='tight') |
|
|
plt.close() |
|
|
|
|
|
print("Pie chart saved as 'key_points_distribution_pie.png'") |