shajiayu1
commited on
Commit
·
f79f576
1
Parent(s):
ce834df
add json
Browse files
count_media_types_and_check_files.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
from tqdm import tqdm # 导入 tqdm 库
|
| 4 |
+
|
| 5 |
+
def count_media_types_and_check_files(json_file, base_paths):
|
| 6 |
+
counts = {
|
| 7 |
+
"audio_caption": {"total": 0, "missing": 0},
|
| 8 |
+
"audio_asr": {"total": 0, "missing": 0},
|
| 9 |
+
"image": {"total": 0, "missing": 0},
|
| 10 |
+
"video": {"total": 0, "missing": 0}
|
| 11 |
+
}
|
| 12 |
+
audio_caption_items = []
|
| 13 |
+
with open(json_file, 'r', encoding='utf-8') as file:
|
| 14 |
+
data = json.load(file)
|
| 15 |
+
# 使用 tqdm 包装循环,显示进度条
|
| 16 |
+
for item in tqdm(data, desc="Processing files", unit="file"):
|
| 17 |
+
if "audio_caption" in item:
|
| 18 |
+
counts["audio_caption"]["total"] += 1
|
| 19 |
+
file_path = os.path.join(base_paths["audio_caption"], item["audio_caption"])
|
| 20 |
+
if not os.path.exists(file_path):
|
| 21 |
+
counts["audio_caption"]["missing"] += 1
|
| 22 |
+
if item["audio_caption"].startswith("vggsound"):
|
| 23 |
+
continue
|
| 24 |
+
audio_caption_items.append(item)
|
| 25 |
+
|
| 26 |
+
if "image" in item:
|
| 27 |
+
counts["image"]["total"] += 1
|
| 28 |
+
file_path = os.path.join(base_paths["image"], item["image"])
|
| 29 |
+
if not os.path.exists(file_path):
|
| 30 |
+
counts["image"]["missing"] += 1
|
| 31 |
+
audio_caption_items.append(item)
|
| 32 |
+
'''
|
| 33 |
+
if "video" in item:
|
| 34 |
+
counts["video"]["total"] += 1
|
| 35 |
+
file_path = os.path.join(base_paths["video"], item["video"])
|
| 36 |
+
if not os.path.exists(file_path):
|
| 37 |
+
counts["video"]["missing"] += 1
|
| 38 |
+
else:
|
| 39 |
+
# audio_caption_items.append(item)
|
| 40 |
+
'''
|
| 41 |
+
if "audio_asr" in item:
|
| 42 |
+
counts["audio_asr"]["total"] += 1
|
| 43 |
+
file_path = os.path.join(base_paths["audio_asr"], item["audio_asr"])
|
| 44 |
+
if not os.path.exists(file_path):
|
| 45 |
+
counts["audio_asr"]["missing"] += 1
|
| 46 |
+
audio_caption_items.append(item)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
'''
|
| 50 |
+
# 重新编号 id
|
| 51 |
+
for i, item in enumerate(audio_caption_items):
|
| 52 |
+
item["id"] = str(i)
|
| 53 |
+
audio_caption_output_file = 'image_stage3_04013.json'
|
| 54 |
+
# 写入audio_caption的 JSON 文件
|
| 55 |
+
with open(audio_caption_output_file, 'w', encoding='utf-8') as file:
|
| 56 |
+
json.dump(audio_caption_items, file, ensure_ascii=False, indent=4)
|
| 57 |
+
'''
|
| 58 |
+
return counts
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
# 使用示例
|
| 63 |
+
json_file = 'image_asr_caption_stage3_0409.json'
|
| 64 |
+
base_paths = {
|
| 65 |
+
"audio_caption": "/media/yu/18TB/audio_asr",
|
| 66 |
+
"audio_asr": "/home/yu/Downloads",
|
| 67 |
+
"image": "/media/yu/18TB/videollava",
|
| 68 |
+
"video": "/media/yu/18TB/videollava"
|
| 69 |
+
}
|
| 70 |
+
counts = count_media_types_and_check_files(json_file, base_paths)
|
| 71 |
+
print(counts)
|
image_asr_caption_stage3_0409.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:03bb48530a9c1e3654b970b56312c2c8f8ae7222cb15a34148d07412b52e1fb3
|
| 3 |
+
size 1496205036
|