FangSen9000 Claude commited on
Commit
875e074
·
1 Parent(s): 3a4b7bf

Add frame-annotated gloss files and documentation

Browse files

- Generated ASLLRP_utterances_with_frames.json with precise frame numbers for each gloss
- Added comprehensive documentation for ASLLRP dataset structure and usage
- Updated .gitignore to exclude xlsx files (using CSV instead)
- Moved analysis scripts to SignX/doc/ directory

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

.gitignore CHANGED
@@ -8,4 +8,4 @@
8
  .vscode
9
  .envrc
10
  *.jpg
11
- *.npz
 
8
  .vscode
9
  .envrc
10
  *.jpg
11
+ *.npz*.xlsx
ASLLRP_utterances_with_frames.json ADDED
The diff for this file is too large to render. See raw diff
 
SignX/doc/ASLLRP_DATA_STRUCTURE.md ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ASLLRP 数据集结构说明
2
+
3
+ ## 概述
4
+ 这是ASLLRP数据集的处理后数据,包含2108个手语utterance(句子)的视频、帧、姿态估计和精确的时间标注。
5
+
6
+ ## 数据文件结构
7
+
8
+ ### 1. ASLLRP_utterances_mapping.txt
9
+ **作用**: 每个视频utterance对应的gloss序列(简化标注)
10
+
11
+ **格式**:
12
+ ```
13
+ 视频ID: GLOSS1 GLOSS2 GLOSS3 ...
14
+ ```
15
+
16
+ **示例**:
17
+ ```
18
+ 10006709: THAT AMONG DIFFERENT KIND VARY BELONG MEAN FOR VOICE IX INCLUDE/INVOLVE OTHER VARY BELONG WITH FOCUS/NARROW "WHAT" NOT OF-COURSE
19
+ ```
20
+
21
+ **统计**:
22
+ - 总共2108个utterance
23
+ - 每个utterance包含5-25个gloss不等
24
+
25
+ ---
26
+
27
+ ### 2. asllrp_sentence_signs_2025_06_28.csv
28
+ **作用**: 精确标注每个sign(手语词)的时间、手型等详细信息
29
+
30
+ **重要列**:
31
+ | 列名 | 说明 | 示例 |
32
+ |------|------|------|
33
+ | Video ID number | Sign的唯一ID | 384585 |
34
+ | Main entry gloss label | 主要的gloss标签 | THAT |
35
+ | **Start frame of the sign video** | Sign的开始帧号 | 2409 |
36
+ | **End frame of the sign video** | Sign的结束帧号 | 2413 |
37
+ | **Start frame of the containing utterance** | 整个句子的开始帧 | 2400 |
38
+ | **End frame of the containing utterance** | 整个句子的结束帧 | 2680 |
39
+ | Dominant start handshape | 主手的起始手型 | Y |
40
+ | Non-dominant start handshape | 副手的起始手型 | - |
41
+ | **Utterance video filename** | 对应的视频文件名 | 10006709.mp4 |
42
+ | Sign type | Sign的类型 | Lexical Signs |
43
+ | Master video filename | 原始视频文件名 | 3-Voice-Life.mov |
44
+
45
+ **统计**:
46
+ - 总共17,522个sign标注
47
+ - 覆盖2,130个不同的utterance视频
48
+
49
+ **CSV文件的关键用途**:
50
+ 1. **精确的时间对齐**: 可以根据帧号从视频中提取特定sign的片段
51
+ 2. **Sign级别的分析**: 每个sign的详细语言学特征(手型、类型等)
52
+ 3. **Utterance级别的上下文**: 了解整个句子的范围
53
+
54
+ ---
55
+
56
+ ### 3. ASLLRP_utterances_results/
57
+ **作用**: 每个视频utterance的处理结果(裁剪视频、帧、姿态估计)
58
+
59
+ **目录结构**:
60
+ ```
61
+ ASLLRP_utterances_results/
62
+ ├── 10006709/
63
+ │ ├── crop_frame/ # 裁剪后的视频帧
64
+ │ │ ├── 00000001.jpg
65
+ │ │ ├── 00000002.jpg
66
+ │ │ └── ... (224帧)
67
+ │ ├── crop_original_video.mp4 # 裁剪后的视频
68
+ │ └── results_dwpose/ # DWPose姿态估计结果
69
+ │ └── npz/
70
+ │ ├── 00000001.npz
71
+ │ ├── 00000002.npz
72
+ │ └── ... (224个npz文件)
73
+ ├── 10036884/
74
+ │ └── ...
75
+ └── ... (2124个文件夹)
76
+ ```
77
+
78
+ **统计**:
79
+ - 总共2,124个视频文件夹
80
+ - 每个文件夹包含:
81
+ - 约224帧裁剪图片
82
+ - 1个裁剪视频(约0.2-0.5 MB)
83
+ - 224个DWPose姿态估计文件
84
+
85
+ ---
86
+
87
+ ## 数据之间的对应关系
88
+
89
+ ```
90
+ ASLLRP_utterances_mapping.txt asllrp_sentence_signs_2025_06_28.csv
91
+ ↓ ↓
92
+ 10006709: THAT AMONG ... "10006709.mp4", THAT, 2409, 2413, ...
93
+ "10006709.mp4", AMONG, 2427, 2432, ...
94
+ ↓ ↓
95
+ ASLLRP_utterances_results/10006709/
96
+ ├── crop_frame/
97
+ ├── crop_original_video.mp4
98
+ └── results_dwpose/
99
+ ```
100
+
101
+ **关系说明**:
102
+ 1. `mapping.txt` 中的视频ID (如 `10006709`) 对应
103
+ 2. `csv文件` 中的 `Utterance video filename` (如 `10006709.mp4`)
104
+ 3. `results目录` 中的文件夹名 (如 `10006709/`)
105
+
106
+ ---
107
+
108
+ ## 如何使用这些数据
109
+
110
+ ### 用例1: 提取特定utterance的所有signs及其时间
111
+
112
+ ```python
113
+ import csv
114
+
115
+ def get_signs_for_utterance(utterance_id):
116
+ """提取一个utterance中所有signs的信息"""
117
+ csv_file = "asllrp_sentence_signs_2025_06_28.csv"
118
+
119
+ signs = []
120
+ with open(csv_file, 'r') as f:
121
+ reader = csv.DictReader(f)
122
+ for row in reader:
123
+ if row['Utterance video filename'] == f"{utterance_id}.mp4":
124
+ signs.append({
125
+ 'gloss': row['Main entry gloss label'],
126
+ 'start_frame': int(row['Start frame of the sign video']),
127
+ 'end_frame': int(row['End frame of the sign video']),
128
+ 'sign_type': row['Sign type']
129
+ })
130
+
131
+ return signs
132
+
133
+ # 示例
134
+ signs = get_signs_for_utterance("10006709")
135
+ print(f"共{len(signs)}个signs:")
136
+ for sign in signs:
137
+ duration = sign['end_frame'] - sign['start_frame']
138
+ print(f" {sign['gloss']}: 帧{sign['start_frame']}-{sign['end_frame']} (持续{duration}帧)")
139
+ ```
140
+
141
+ ### 用例2: 从视频中提取特定sign的片段
142
+
143
+ ```python
144
+ import cv2
145
+
146
+ def extract_sign_frames(utterance_id, gloss, start_frame, end_frame):
147
+ """从裁剪视频中提取特定sign的帧"""
148
+ video_path = f"ASLLRP_utterances_results/{utterance_id}/crop_original_video.mp4"
149
+
150
+ cap = cv2.VideoCapture(video_path)
151
+ frames = []
152
+
153
+ cap.set(cv2.CAP_PROP_POS_FRAMES, start_frame)
154
+ for i in range(start_frame, end_frame + 1):
155
+ ret, frame = cap.read()
156
+ if ret:
157
+ frames.append(frame)
158
+
159
+ cap.release()
160
+ return frames
161
+ ```
162
+
163
+ ### 用例3: 加载DWPose姿态估计数据
164
+
165
+ ```python
166
+ import numpy as np
167
+
168
+ def load_dwpose_for_frame(utterance_id, frame_num):
169
+ """加载特定帧的DWPose姿态估计"""
170
+ npz_path = f"ASLLRP_utterances_results/{utterance_id}/results_dwpose/npz/{frame_num:08d}.npz"
171
+
172
+ # 需要allow_pickle=True来读取包含对象的npz文件
173
+ data = np.load(npz_path, allow_pickle=True)
174
+
175
+ return data
176
+ ```
177
+
178
+ ---
179
+
180
+ ## CSV文件中的帧号说明
181
+
182
+ **重要**: CSV文件中的帧号是相对于**原始master视频**的帧号,而不是裁剪后视频的帧号。
183
+
184
+ - **原始视频**: `Master video filename` (如 `3-Voice-Life.mov`)
185
+ - **Utterance范围**: 帧2400-2680(相对于原始视频)
186
+ - **Sign范围**: 帧2409-2413(相对于原始视频)
187
+
188
+ **如果要使用裁剪后的视频**:
189
+ ```python
190
+ # 计算相对于裁剪视频的帧号
191
+ utterance_start = 2400 # 从CSV获取
192
+ sign_start = 2409 # 从CSV获取
193
+
194
+ # 裁剪视频中的帧号 = sign帧号 - utterance开始帧号
195
+ cropped_frame_num = sign_start - utterance_start # = 9
196
+ ```
197
+
198
+ ---
199
+
200
+ ## 数据总结
201
+
202
+ | 项目 | 数量 |
203
+ |------|------|
204
+ | Utterance视频 | 2,108-2,130个 |
205
+ | Sign标注 | 17,522个 |
206
+ | 总帧数 | ~470,000帧 (2124 × 224) |
207
+ | 总视频大小 | ~500 MB |
208
+ | DWPose文件 | ~470,000个npz文件 |
209
+
210
+ ---
211
+
212
+ ## 训练建议
213
+
214
+ 基于这些数据,你可以进行:
215
+
216
+ 1. **Sign级别识别**: 使用CSV中的精确时间标注训练单个sign的识别模型
217
+ 2. **Utterance级别翻译**: 使用整个utterance的视频和gloss序列训练翻译模型
218
+ 3. **姿态驱动的手语生成**: 使用DWPose数据训练姿态估计或生成模型
219
+ 4. **时间对齐研究**: 研究sign的时间边界和持续时间模式
220
+
221
+ ---
222
+
223
+ ## 常见问题
224
+
225
+ **Q: 为什么mapping.txt有2108个条目,而CSV显示2130个视频?**
226
+ A: 可能有些utterance没有被包含在mapping.txt中,或者CSV包含了一些额外的变体。
227
+
228
+ **Q: DWPose npz文件包含什么数据?**
229
+ A: 包含姿态关键点、骨架信息等,需要使用`allow_pickle=True`读取。
230
+
231
+ **Q: 如何知道每个视频的帧率?**
232
+ A: 需要从原始视频metadata中获取,或者假设标准帧率(通常是25或30 FPS)。
233
+
234
+ ---
235
+
236
+ 生成日期: 2025-12-27
237
+ 作者: Claude Code
SignX/doc/FPS_AND_FRAME_NUMBERS.md ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ASLLRP 数据集 FPS 和帧号说明
2
+
3
+ ## 重要发现
4
+
5
+ ### 1. 帧率信息
6
+ - **CSV文件中的帧号**: 基于原始视频的**30 FPS** (ASLLRP原始数据集标准)
7
+ - **裁剪视频的帧率**: **24 FPS** (处理时可能重新编码)
8
+ - **crop_frame图片数量**: 与裁剪视频帧数一致
9
+
10
+ ### 2. 帧数不匹配问题
11
+
12
+ 以 `10006709` 为例:
13
+
14
+ | 项目 | 值 | 说明 |
15
+ |------|-----|------|
16
+ | CSV中utterance帧范围 | 2400-2680 | 280帧 (@ 30 FPS = 9.33秒) |
17
+ | 裁剪视频实际帧数 | 224帧 | @ 24 FPS = 9.33秒 |
18
+ | 裁剪视频时长 | 9.33秒 | 与CSV一致 |
19
+ | CSV最后一个sign帧号 | 2659-2668 | 相对起始点259-268 |
20
+
21
+ **关键问题**: CSV中的帧号(相对于utterance起始)最大到268,但裁剪视频只有224帧!
22
+
23
+ ### 3. 帧号转换公式
24
+
25
+ #### 情况A: CSV帧号是30 FPS,裁剪视频是24 FPS
26
+
27
+ ```python
28
+ # CSV中的帧号(30 FPS)转换为裁剪视频帧号(24 FPS)
29
+ csv_frame = 2409 # CSV中的sign开始帧
30
+ utterance_start = 2400 # CSV中的utterance开始帧
31
+
32
+ # 转换步骤:
33
+ # 1. 计算相对于utterance的帧号(30 FPS)
34
+ relative_frame_30fps = csv_frame - utterance_start # 2409 - 2400 = 9
35
+
36
+ # 2. 转换FPS: 30 FPS -> 24 FPS
37
+ relative_frame_24fps = int(relative_frame_30fps * 24 / 30) # 9 * 0.8 = 7.2 ≈ 7
38
+
39
+ # 3. 在裁剪视频中对应第7帧(从0开始计数)
40
+ ```
41
+
42
+ #### 情况B: 裁剪视频被截断了
43
+
44
+ 另一种可能是裁剪视频在处理过程中被截断,只保留了前224帧:
45
+
46
+ ```python
47
+ # 直接使用相对帧号,但注意边界
48
+ csv_frame = 2659 # 最后一个sign
49
+ relative_frame = csv_frame - utterance_start # 259
50
+
51
+ # 警告:超出裁剪视频范围(224帧)!
52
+ if relative_frame >= 224:
53
+ print("警告:此sign的帧号超出裁剪视频范围!")
54
+ ```
55
+
56
+ ## 实际使用建议
57
+
58
+ ### 使用 crop_frame 图片
59
+
60
+ 如果使用 `crop_frame/` 中的图片(最可靠):
61
+
62
+ ```python
63
+ import csv
64
+
65
+ def get_sign_frames_from_images(utterance_id, gloss):
66
+ """从图片文件夹提取sign的帧"""
67
+ csv_file = 'asllrp_sentence_signs_2025_06_28.csv'
68
+
69
+ with open(csv_file, 'r') as f:
70
+ reader = csv.DictReader(f)
71
+ for row in reader:
72
+ if row['Utterance video filename'] == f"{utterance_id}.mp4" and \
73
+ row['Main entry gloss label'] == gloss:
74
+
75
+ utterance_start = int(row['Start frame of the containing utterance'])
76
+ sign_start = int(row['Start frame of the sign video'])
77
+ sign_end = int(row['End frame of the sign video'])
78
+
79
+ # 方法1: 假设是30 FPS -> 24 FPS转换
80
+ start_24fps = int((sign_start - utterance_start) * 24 / 30)
81
+ end_24fps = int((sign_end - utterance_start) * 24 / 30)
82
+
83
+ # 方法2: 直接使用相对帧号(如果CSV也是24 FPS)
84
+ # start_frame = sign_start - utterance_start
85
+ # end_frame = sign_end - utterance_start
86
+
87
+ # 加载对应的图片
88
+ image_dir = f"ASLLRP_utterances_results/{utterance_id}/crop_frame"
89
+ frames = []
90
+ for i in range(start_24fps, min(end_24fps + 1, 224)): # 限制在224帧内
91
+ img_path = f"{image_dir}/{i+1:08d}.jpg" # 图片从00000001.jpg开始
92
+ frames.append(img_path)
93
+
94
+ return frames
95
+ ```
96
+
97
+ ### 使用裁剪视频
98
+
99
+ ```python
100
+ import cv2
101
+
102
+ def extract_from_cropped_video(utterance_id, start_frame_24fps, end_frame_24fps):
103
+ """从裁剪视频提取帧"""
104
+ video_path = f"ASLLRP_utterances_results/{utterance_id}/crop_original_video.mp4"
105
+
106
+ cap = cv2.VideoCapture(video_path)
107
+ fps = cap.get(cv2.CAP_PROP_FPS) # 应该是24
108
+ total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) # 224
109
+
110
+ print(f"视频FPS: {fps}, 总帧数: {total_frames}")
111
+
112
+ frames = []
113
+ for frame_num in range(start_frame_24fps, min(end_frame_24fps + 1, total_frames)):
114
+ cap.set(cv2.CAP_PROP_POS_FRAMES, frame_num)
115
+ ret, frame = cap.read()
116
+ if ret:
117
+ frames.append(frame)
118
+
119
+ cap.release()
120
+ return frames
121
+ ```
122
+
123
+ ## 测试验证
124
+
125
+ ```bash
126
+ cd /research/cbim/vast/sf895/code/Sign-X/output/huggingface_asllrp_repo
127
+
128
+ # 验证视频帧率
129
+ ffprobe -v error -select_streams v:0 -show_entries stream=r_frame_rate \
130
+ ASLLRP_utterances_results/10006709/crop_original_video.mp4
131
+
132
+ # 验证视频帧数
133
+ ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames \
134
+ ASLLRP_utterances_results/10006709/crop_original_video.mp4
135
+
136
+ # 验证图片数量
137
+ ls ASLLRP_utterances_results/10006709/crop_frame/*.jpg | wc -l
138
+ ```
139
+
140
+ ## 总结
141
+
142
+ 1. **CSV帧号**: 基于原始ASLLRP视频(可能是30 FPS)
143
+ 2. **裁剪视频**: 24 FPS,但帧数少于CSV显示的范围
144
+ 3. **建议**: 优先使用 `crop_frame/` 图片,它们的数量(224)是确定的
145
+ 4. **转换**: 使用 `csv_frame * 24/30` 来转换帧号(需要验证)
146
+
147
+ ## 未解决的问题
148
+
149
+ - [ ] 确认CSV中的帧号是30 FPS还是24 FPS
150
+ - [ ] 为什么裁剪视频���有224帧而不是280帧?
151
+ - [ ] crop_frame的图片编号(00000001-00000224)如何对应CSV的帧号?
152
+ - [ ] 是否所有utterance都有这个问题?
153
+
154
+ 建议检查多个视频来确认FPS转换规则!
SignX/doc/README.md ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ASLLRP 数据集说明
2
+
3
+ ## 数据概览
4
+
5
+ 这个目录包含ASLLRP手语数据集的处理后数据:
6
+
7
+ - **2,108个** 手语utterance(句子)视频
8
+ - **17,522个** sign(手语词)的精确标注
9
+ - **~470,000帧** 视频帧和DWPose姿态估计
10
+
11
+ ## 文件结构
12
+
13
+ ```
14
+ huggingface_asllrp_repo/
15
+ ├── ASLLRP_utterances_mapping.txt # 每个视频对应的gloss序列(原始)
16
+ ├── ASLLRP_utterances_with_frames.json # 带帧号的gloss数据(JSON,推荐)★
17
+ ├── ASLLRP_utterances_with_frames.txt # 带帧号的gloss数据(可读文本)
18
+ ├── ASLLRP_utterances_compact_frames.txt # 带帧号的gloss数据(紧凑格式)
19
+ ├── asllrp_sentence_signs_2025_06_28.csv # 每个sign的精确时间和手型标注
20
+ ├── ASLLRP_utterances_results/ # 处理后的视频和姿态数据
21
+ │ ├── 10006709/
22
+ │ │ ├── crop_frame/ # 裁剪后的视频帧(JPG)
23
+ │ │ ├── crop_original_video.mp4 # 裁剪后的视频(24 FPS)
24
+ │ │ └── results_dwpose/npz/ # DWPose姿态估计(NPZ)
25
+ │ └── ...
26
+ ├── ASLLRP_DATA_STRUCTURE.md # 详细的数据结构说明
27
+ ├── FPS_AND_FRAME_NUMBERS.md # FPS和帧号转换说明
28
+ ├── analyze_asllrp_data.py # 数据分析脚本
29
+ ├── query_asllrp_data.py # 数据查询工具
30
+ └── generate_gloss_with_frames.py # 生成带帧号的gloss数据
31
+ ```
32
+
33
+ ## 快速使用
34
+
35
+ ### 1. 查询特定视频的信息
36
+
37
+ ```bash
38
+ python query_asllrp_data.py --utterance 10006709
39
+ ```
40
+
41
+ 输出示例:
42
+ ```
43
+ Utterance ID: 10006709
44
+ Gloss序列 (19个): THAT AMONG DIFFERENT KIND VARY ...
45
+ Utterance帧范围: 2400 - 2680 (总共280帧)
46
+
47
+ 详细Signs列表:
48
+ 序号 Gloss 原始视频帧范围 裁剪视频帧范围 类型
49
+ 1 THAT 2409-2413 (4帧) 9-13 Lexical Signs
50
+ 2 AMONG 2427-2432 (5帧) 27-32 Lexical Signs
51
+ ...
52
+ ```
53
+
54
+ ### 2. 搜索特定的gloss
55
+
56
+ ```bash
57
+ python query_asllrp_data.py --search THAT
58
+ ```
59
+
60
+ ### 3. 查看数据集统计
61
+
62
+ ```bash
63
+ python query_asllrp_data.py --list
64
+ ```
65
+
66
+ 输出示例:
67
+ ```
68
+ Mapping.txt中的utterances: 2108
69
+ CSV中的utterances: 2130
70
+ 平均每个utterance: 8.0 个glosses
71
+
72
+ Sign类型分布:
73
+ Lexical Signs: 14736
74
+ Fingerspelled Signs: 1018
75
+ Loan Signs: 581
76
+ ```
77
+
78
+ ### 4. 提取特定sign的信息
79
+
80
+ ```bash
81
+ python query_asllrp_data.py --extract 10006709 THAT
82
+ ```
83
+
84
+ ## 数据说明
85
+
86
+ ### ASLLRP_utterances_mapping.txt
87
+ 简单的utterance到gloss序列的映射:
88
+ ```
89
+ 10006709: THAT AMONG DIFFERENT KIND VARY BELONG MEAN ...
90
+ ```
91
+
92
+ ### asllrp_sentence_signs_2025_06_28.csv
93
+ 详细的sign级别标注(CSV格式),包含:
94
+ - **时间信息**: Sign的开始/结束帧号
95
+ - **手型信息**: 主手和副手的起始/结束手型
96
+ - **分类信息**: Sign类型(Lexical Signs, Fingerspelled Signs等)
97
+
98
+ **重要**: CSV中的帧号是相对于**原始视频**的。如果使用裁剪视频,需要减去utterance的开始帧号。
99
+
100
+ ### ASLLRP_utterances_results/
101
+ 每个视频的处理结果:
102
+ - `crop_frame/`: ~224张裁剪后的JPG图片(每个视频的帧数不同)
103
+ - `crop_original_video.mp4`: 裁剪后的视频文件
104
+ - `results_dwpose/npz/`: DWPose姿态估计结果(每帧一个NPZ文件)
105
+
106
+ ## 新增功能:带帧号的Gloss数据 ★
107
+
108
+ 现在你可以直接使用 **`ASLLRP_utterances_with_frames.json`** 获取每个gloss词的精确帧号!
109
+
110
+ ### 使用JSON文件(推荐)
111
+
112
+ ```python
113
+ import json
114
+
115
+ # 加载带帧号的gloss数据
116
+ with open('ASLLRP_utterances_with_frames.json', 'r') as f:
117
+ data = json.load(f)
118
+
119
+ # 获取特定utterance的gloss和帧号
120
+ utterance = data['10006709']
121
+ print(f"总时长: {utterance['duration_seconds']} 秒")
122
+ print(f"总帧数: {utterance['total_frames_24fps']} 帧 (24fps)")
123
+
124
+ # 遍历每个gloss词
125
+ for gloss in utterance['glosses']:
126
+ print(f"{gloss['gloss']}: "
127
+ f"24fps[{gloss['start_24fps']}:{gloss['end_24fps']}] "
128
+ f"持续{gloss['duration_24fps']}帧")
129
+
130
+ # 输出:
131
+ # THAT: 24fps[7:10] 持续3帧
132
+ # AMONG: 24fps[21:25] 持续4帧
133
+ # ...
134
+ ```
135
+
136
+ ### 使用紧凑文本格式
137
+
138
+ ```python
139
+ # 读取紧凑格式(每行一个utterance)
140
+ with open('ASLLRP_utterances_compact_frames.txt', 'r') as f:
141
+ for line in f:
142
+ utterance_id, glosses = line.strip().split(': ', 1)
143
+ # 格式: GLOSS1|start-end GLOSS2|start-end ...
144
+ gloss_pairs = glosses.split()
145
+ for pair in gloss_pairs:
146
+ gloss, frames = pair.split('|')
147
+ start, end = frames.split('-')
148
+ print(f"{gloss}: 帧{start}-{end}")
149
+ ```
150
+
151
+ ## 代码示例
152
+
153
+ ### 提取utterance的所有signs(旧方法 - 需要FPS转换)
154
+
155
+ ```python
156
+ import csv
157
+
158
+ def get_signs(utterance_id):
159
+ with open('asllrp_sentence_signs_2025_06_28.csv', 'r') as f:
160
+ reader = csv.DictReader(f)
161
+ for row in reader:
162
+ if row['Utterance video filename'] == f"{utterance_id}.mp4":
163
+ print(f"{row['Main entry gloss label']}: 帧{row['Start frame of the sign video']}-{row['End frame of the sign video']}")
164
+
165
+ get_signs("10006709")
166
+ ```
167
+
168
+ ### 新方法:直接使用带帧号的数据(推荐)
169
+
170
+ ```python
171
+ import json
172
+
173
+ def get_signs_with_frames(utterance_id):
174
+ """获取utterance的所有signs及其24fps帧号(已转换)"""
175
+ with open('ASLLRP_utterances_with_frames.json', 'r') as f:
176
+ data = json.load(f)
177
+
178
+ if utterance_id in data:
179
+ for gloss in data[utterance_id]['glosses']:
180
+ print(f"{gloss['gloss']}: "
181
+ f"帧{gloss['start_24fps']}-{gloss['end_24fps']} "
182
+ f"({gloss['duration_24fps']}帧, {gloss['sign_type']})")
183
+
184
+ get_signs_with_frames("10006709")
185
+ ```
186
+
187
+ ### 从裁剪视频中提取sign的帧
188
+
189
+ ```python
190
+ import cv2
191
+
192
+ def extract_sign(utterance_id, start_frame, end_frame):
193
+ # 注意:需要转换为裁剪视频的帧号
194
+ video_path = f"ASLLRP_utterances_results/{utterance_id}/crop_original_video.mp4"
195
+ cap = cv2.VideoCapture(video_path)
196
+
197
+ frames = []
198
+ for frame_num in range(start_frame, end_frame + 1):
199
+ cap.set(cv2.CAP_PROP_POS_FRAMES, frame_num)
200
+ ret, frame = cap.read()
201
+ if ret:
202
+ frames.append(frame)
203
+
204
+ cap.release()
205
+ return frames
206
+ ```
207
+
208
+ ## 数据统计
209
+
210
+ | 项目 | 数量 |
211
+ |------|------|
212
+ | Utterance视频 | 2,108-2,130 |
213
+ | Sign标注 | 17,522 |
214
+ | Lexical Signs | 14,736 (84.1%) |
215
+ | Fingerspelled Signs | 1,018 (5.8%) |
216
+ | 平均每个utterance的glosses | 8.0个 |
217
+ | Gloss数量范围 | 2-30个 |
218
+
219
+ ## 更多信息
220
+
221
+ 详细的数据结构说明请参阅 [ASLLRP_DATA_STRUCTURE.md](ASLLRP_DATA_STRUCTURE.md)
SignX/doc/analyze_asllrp_data.py ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ 分析ASLLRP数据集的结构和关系
4
+ """
5
+ import os
6
+ import csv
7
+ from collections import defaultdict
8
+ import numpy as np
9
+
10
+ # 数据路径
11
+ BASE_PATH = "/research/cbim/vast/sf895/code/Sign-X/output/huggingface_asllrp_repo"
12
+ MAPPING_FILE = os.path.join(BASE_PATH, "ASLLRP_utterances_mapping.txt")
13
+ CSV_FILE = os.path.join(BASE_PATH, "asllrp_sentence_signs_2025_06_28.csv")
14
+ RESULTS_DIR = os.path.join(BASE_PATH, "ASLLRP_utterances_results")
15
+
16
+ def analyze_mapping_file():
17
+ """分析mapping文件"""
18
+ print("="*80)
19
+ print("分析 ASLLRP_utterances_mapping.txt")
20
+ print("="*80)
21
+
22
+ with open(MAPPING_FILE, 'r') as f:
23
+ lines = f.readlines()
24
+
25
+ print(f"总共有 {len(lines)} 个视频utterance")
26
+
27
+ # 示例
28
+ print("\n前5个示例:")
29
+ for i, line in enumerate(lines[:5], 1):
30
+ video_id, glosses = line.strip().split(': ', 1)
31
+ gloss_list = glosses.split()
32
+ print(f"{i}. 视频ID: {video_id}")
33
+ print(f" Gloss数量: {len(gloss_list)}")
34
+ print(f" Gloss序列: {' '.join(gloss_list[:10])}{'...' if len(gloss_list) > 10 else ''}")
35
+ print()
36
+
37
+ return lines
38
+
39
+ def analyze_csv_file(example_video_id="10006709"):
40
+ """分析CSV文件 - 包含每个sign的精确时间标注"""
41
+ print("="*80)
42
+ print("分析 asllrp_sentence_signs_2025_06_28.csv")
43
+ print("="*80)
44
+
45
+ # 读取CSV
46
+ utterance_signs = defaultdict(list)
47
+
48
+ with open(CSV_FILE, 'r') as f:
49
+ reader = csv.DictReader(f)
50
+ headers = reader.fieldnames
51
+
52
+ print(f"\nCSV文件包含以下列:")
53
+ for i, header in enumerate(headers, 1):
54
+ print(f" {i}. {header}")
55
+
56
+ # 按utterance video filename分组
57
+ for row in reader:
58
+ utterance_video = row['Utterance video filename']
59
+ utterance_signs[utterance_video].append(row)
60
+
61
+ print(f"\n总共有 {len(utterance_signs)} 个不同的utterance视频")
62
+ print(f"总共有 {sum(len(signs) for signs in utterance_signs.values())} 个sign标注")
63
+
64
+ # 分析示例视频
65
+ example_key = f"{example_video_id}.mp4"
66
+ if example_key in utterance_signs:
67
+ signs = utterance_signs[example_key]
68
+ print(f"\n示例视频 {example_video_id} 的详细信息:")
69
+ print(f" 包含 {len(signs)} 个sign")
70
+ print(f"\n 前5个signs:")
71
+ for i, sign in enumerate(signs[:5], 1):
72
+ print(f" {i}. {sign['Main entry gloss label']}")
73
+ print(f" - Sign开始帧: {sign['Start frame of the sign video']}")
74
+ print(f" - Sign结束帧: {sign['End frame of the sign video']}")
75
+ print(f" - Utterance开始帧: {sign['Start frame of the containing utterance']}")
76
+ print(f" - Utterance结束帧: {sign['End frame of the containing utterance']}")
77
+ print(f" - Sign类型: {sign['Sign type']}")
78
+ print()
79
+
80
+ return utterance_signs
81
+
82
+ def analyze_results_directory(example_video_id="10006709"):
83
+ """分析results目录结构"""
84
+ print("="*80)
85
+ print("分析 ASLLRP_utterances_results 目录")
86
+ print("="*80)
87
+
88
+ video_dirs = [d for d in os.listdir(RESULTS_DIR)
89
+ if os.path.isdir(os.path.join(RESULTS_DIR, d))]
90
+
91
+ print(f"\n总共有 {len(video_dirs)} 个视频文件夹")
92
+
93
+ # 分析示例文件夹
94
+ example_dir = os.path.join(RESULTS_DIR, example_video_id)
95
+ if os.path.exists(example_dir):
96
+ print(f"\n示例视频 {example_video_id} 的文件结构:")
97
+
98
+ # crop_frame
99
+ crop_frame_dir = os.path.join(example_dir, "crop_frame")
100
+ if os.path.exists(crop_frame_dir):
101
+ frames = sorted([f for f in os.listdir(crop_frame_dir) if f.endswith('.jpg')])
102
+ print(f" - crop_frame/: {len(frames)} 个裁剪帧")
103
+ print(f" 帧范围: {frames[0]} 到 {frames[-1]}")
104
+
105
+ # crop_original_video.mp4
106
+ video_path = os.path.join(example_dir, "crop_original_video.mp4")
107
+ if os.path.exists(video_path):
108
+ size_mb = os.path.getsize(video_path) / (1024 * 1024)
109
+ print(f" - crop_original_video.mp4: {size_mb:.2f} MB")
110
+
111
+ # results_dwpose
112
+ dwpose_dir = os.path.join(example_dir, "results_dwpose/npz")
113
+ if os.path.exists(dwpose_dir):
114
+ npz_files = sorted([f for f in os.listdir(dwpose_dir) if f.endswith('.npz')])
115
+ print(f" - results_dwpose/npz/: {len(npz_files)} 个姿态估计文件")
116
+
117
+ # 查看一个npz文件的内容
118
+ if npz_files:
119
+ sample_npz = np.load(os.path.join(dwpose_dir, npz_files[0]))
120
+ print(f" NPZ文件包含的数据:")
121
+ for key in sample_npz.files:
122
+ data = sample_npz[key]
123
+ print(f" - {key}: shape={data.shape}, dtype={data.dtype}")
124
+
125
+ def understand_csv_usage():
126
+ """说明如何使用CSV文件"""
127
+ print("\n" + "="*80)
128
+ print("如何使用 asllrp_sentence_signs_2025_06_28.csv")
129
+ print("="*80)
130
+
131
+ print("""
132
+ 这个CSV文件的主要用途:
133
+
134
+ 1. **精确的时间标注**
135
+ - 每一行代表一个sign(手语词)
136
+ - "Start frame of the sign video" 和 "End frame of the sign video"
137
+ 表示这个sign在整个视频中的精确帧范围
138
+ - 可以用来从视频中提取单个sign的片段
139
+
140
+ 2. **Utterance级别的上下文**
141
+ - "Start frame of the containing utterance" 和 "End frame of the containing utterance"
142
+ 表示包含这个sign的整个句子(utterance)的帧范围
143
+ - 一个utterance可能包含多个signs
144
+
145
+ 3. **手语学语言特征**
146
+ - Dominant/Non-dominant start/end handshape: 起始和结束手型
147
+ - Sign type: 手语类型(Lexical Signs, Fingerspelled Signs, etc.)
148
+ - Class label: 手语词的分类标签
149
+
150
+ 4. **数据关联**
151
+ - "Utterance video filename": 对应 ASLLRP_utterances_results 中的文件夹名
152
+ - "Sign video filename": 单个sign的视频文件名(在原始ASLLRP数据集中)
153
+
154
+ 使用示例代码:
155
+ """)
156
+
157
+ print("""
158
+ # 提取特定utterance的所有signs及其时间
159
+ import csv
160
+
161
+ utterance_id = "10006709"
162
+ with open(CSV_FILE, 'r') as f:
163
+ reader = csv.DictReader(f)
164
+ for row in reader:
165
+ if row['Utterance video filename'] == f"{utterance_id}.mp4":
166
+ gloss = row['Main entry gloss label']
167
+ start_frame = int(row['Start frame of the sign video'])
168
+ end_frame = int(row['End frame of the sign video'])
169
+ print(f"{gloss}: 帧 {start_frame}-{end_frame}")
170
+ """)
171
+
172
+ def create_example_script():
173
+ """创建一个示例脚本展示如何使用这些数据"""
174
+ print("\n" + "="*80)
175
+ print("示例:从CSV提取sign的时间信息并与视频对应")
176
+ print("="*80)
177
+
178
+ script = '''
179
+ import csv
180
+ import cv2
181
+ import os
182
+
183
+ def extract_signs_from_utterance(utterance_id):
184
+ """提取一个utterance中所有signs的信息"""
185
+ csv_file = "/research/cbim/vast/sf895/code/Sign-X/output/huggingface_asllrp_repo/asllrp_sentence_signs_2025_06_28.csv"
186
+
187
+ signs = []
188
+ with open(csv_file, 'r') as f:
189
+ reader = csv.DictReader(f)
190
+ for row in reader:
191
+ if row['Utterance video filename'] == f"{utterance_id}.mp4":
192
+ signs.append({
193
+ 'gloss': row['Main entry gloss label'],
194
+ 'start_frame': int(row['Start frame of the sign video']),
195
+ 'end_frame': int(row['End frame of the sign video']),
196
+ 'sign_type': row['Sign type']
197
+ })
198
+
199
+ return signs
200
+
201
+ # 示例使用
202
+ utterance_id = "10006709"
203
+ signs = extract_signs_from_utterance(utterance_id)
204
+ print(f"Utterance {utterance_id} 包含 {len(signs)} 个signs:")
205
+ for sign in signs[:5]:
206
+ print(f" {sign['gloss']}: 帧 {sign['start_frame']}-{sign['end_frame']} ({sign['sign_type']})")
207
+ '''
208
+
209
+ print(script)
210
+
211
+ if __name__ == "__main__":
212
+ print("\nASLLRP数据集结构分析")
213
+ print("作者: Claude Code")
214
+ print("日期: 2025-12-27\n")
215
+
216
+ # 分析三个主要组件
217
+ analyze_mapping_file()
218
+ print()
219
+
220
+ analyze_csv_file()
221
+ print()
222
+
223
+ analyze_results_directory()
224
+
225
+ # 使用说明
226
+ understand_csv_usage()
227
+
228
+ # 示例脚本
229
+ create_example_script()
230
+
231
+ print("\n" + "="*80)
232
+ print("分析完成!")
233
+ print("="*80)
SignX/doc/generate_gloss_with_frames.py ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ 为ASLLRP_utterances_mapping.txt中的每个gloss词添加起始和结束帧号
4
+
5
+ 输出格式:
6
+ {
7
+ "utterance_id": {
8
+ "glosses": [
9
+ {
10
+ "gloss": "THAT",
11
+ "start_30fps": 9, # 相对于utterance起始的帧号(30 FPS)
12
+ "end_30fps": 13,
13
+ "start_24fps": 7, # 转换为24 FPS后的帧号
14
+ "end_24fps": 10,
15
+ "duration_30fps": 4, # 持续帧数(30 FPS)
16
+ "duration_24fps": 3, # 持续帧数(24 FPS)
17
+ "sign_type": "Lexical Signs"
18
+ },
19
+ ...
20
+ ],
21
+ "total_frames_30fps": 280,
22
+ "total_frames_24fps": 224,
23
+ "duration_seconds": 9.33
24
+ }
25
+ }
26
+ """
27
+
28
+ import csv
29
+ import json
30
+ from collections import defaultdict, OrderedDict
31
+
32
+ # 文件路径
33
+ MAPPING_FILE = "ASLLRP_utterances_mapping.txt"
34
+ CSV_FILE = "asllrp_sentence_signs_2025_06_28.csv"
35
+ OUTPUT_JSON = "ASLLRP_utterances_with_frames.json"
36
+ OUTPUT_TXT = "ASLLRP_utterances_with_frames.txt"
37
+
38
+ def load_mapping():
39
+ """加载mapping文件"""
40
+ mapping = {}
41
+ with open(MAPPING_FILE, 'r') as f:
42
+ for line in f:
43
+ utterance_id, glosses = line.strip().split(': ', 1)
44
+ mapping[utterance_id] = glosses.split()
45
+ return mapping
46
+
47
+ def load_csv_signs():
48
+ """从CSV加载所有signs的详细信息"""
49
+ signs_by_utterance = defaultdict(list)
50
+ skipped_rows = 0
51
+
52
+ with open(CSV_FILE, 'r') as f:
53
+ reader = csv.DictReader(f)
54
+ for row in reader:
55
+ try:
56
+ utterance_video = row['Utterance video filename'].replace('.mp4', '')
57
+
58
+ # 提取帧号信息 - 添加错误处理
59
+ utterance_start = int(row['Start frame of the containing utterance'])
60
+ utterance_end = int(row['End frame of the containing utterance'])
61
+ sign_start = int(row['Start frame of the sign video'])
62
+ sign_end = int(row['End frame of the sign video'])
63
+ except (ValueError, KeyError) as e:
64
+ # 跳过有问题的行
65
+ skipped_rows += 1
66
+ continue
67
+
68
+ # 计算相对于utterance起始的帧号(假设CSV是30 FPS)
69
+ relative_start_30fps = sign_start - utterance_start
70
+ relative_end_30fps = sign_end - utterance_start
71
+
72
+ # 转换为24 FPS
73
+ relative_start_24fps = int(relative_start_30fps * 24 / 30)
74
+ relative_end_24fps = int(relative_end_30fps * 24 / 30)
75
+
76
+ sign_info = {
77
+ 'gloss': row['Main entry gloss label'],
78
+ 'start_30fps': relative_start_30fps,
79
+ 'end_30fps': relative_end_30fps,
80
+ 'start_24fps': relative_start_24fps,
81
+ 'end_24fps': relative_end_24fps,
82
+ 'duration_30fps': relative_end_30fps - relative_start_30fps,
83
+ 'duration_24fps': relative_end_24fps - relative_start_24fps,
84
+ 'sign_type': row['Sign type'],
85
+ 'utterance_start_frame': utterance_start,
86
+ 'utterance_end_frame': utterance_end,
87
+ }
88
+
89
+ signs_by_utterance[utterance_video].append(sign_info)
90
+
91
+ if skipped_rows > 0:
92
+ print(f" 警告: 跳过了 {skipped_rows} 个格式错误的CSV行")
93
+
94
+ return signs_by_utterance
95
+
96
+ def fps_convert_30_to_24(frame_30fps):
97
+ """将30 FPS帧号转换为24 FPS"""
98
+ return int(frame_30fps * 24 / 30)
99
+
100
+ def generate_gloss_with_frames():
101
+ """生成包含帧号的gloss数据"""
102
+ print("加载数据...")
103
+ mapping = load_mapping()
104
+ csv_signs = load_csv_signs()
105
+
106
+ result = OrderedDict()
107
+ missing_utterances = []
108
+
109
+ print(f"处理 {len(mapping)} 个utterances...")
110
+
111
+ for utterance_id, gloss_sequence in mapping.items():
112
+ if utterance_id not in csv_signs:
113
+ missing_utterances.append(utterance_id)
114
+ continue
115
+
116
+ signs = csv_signs[utterance_id]
117
+
118
+ # 计算总帧数
119
+ if signs:
120
+ total_frames_30fps = signs[0]['utterance_end_frame'] - signs[0]['utterance_start_frame']
121
+ total_frames_24fps = fps_convert_30_to_24(total_frames_30fps)
122
+ duration_seconds = total_frames_30fps / 30.0
123
+ else:
124
+ total_frames_30fps = 0
125
+ total_frames_24fps = 0
126
+ duration_seconds = 0
127
+
128
+ # 匹配gloss序列与CSV中的signs
129
+ # 注意:mapping.txt中的gloss数量可能与CSV中的不完全一致
130
+ glosses_with_frames = []
131
+
132
+ for sign in signs:
133
+ glosses_with_frames.append({
134
+ 'gloss': sign['gloss'],
135
+ 'start_30fps': sign['start_30fps'],
136
+ 'end_30fps': sign['end_30fps'],
137
+ 'start_24fps': sign['start_24fps'],
138
+ 'end_24fps': sign['end_24fps'],
139
+ 'duration_30fps': sign['duration_30fps'],
140
+ 'duration_24fps': sign['duration_24fps'],
141
+ 'sign_type': sign['sign_type']
142
+ })
143
+
144
+ result[utterance_id] = {
145
+ 'glosses': glosses_with_frames,
146
+ 'total_frames_30fps': total_frames_30fps,
147
+ 'total_frames_24fps': total_frames_24fps,
148
+ 'duration_seconds': round(duration_seconds, 2),
149
+ 'gloss_count': len(glosses_with_frames)
150
+ }
151
+
152
+ # 保存JSON格式
153
+ print(f"\n保存JSON格式到 {OUTPUT_JSON}...")
154
+ with open(OUTPUT_JSON, 'w', encoding='utf-8') as f:
155
+ json.dump(result, f, indent=2, ensure_ascii=False)
156
+
157
+ # 保存可读文本格式
158
+ print(f"保存文本格式到 {OUTPUT_TXT}...")
159
+ with open(OUTPUT_TXT, 'w', encoding='utf-8') as f:
160
+ for utterance_id, data in result.items():
161
+ # 格式: utterance_id: GLOSS1[s30:e30->s24:e24] GLOSS2[...] ...
162
+ gloss_strings = []
163
+ for g in data['glosses']:
164
+ gloss_str = f"{g['gloss']}[{g['start_30fps']}:{g['end_30fps']}->{g['start_24fps']}:{g['end_24fps']}]"
165
+ gloss_strings.append(gloss_str)
166
+
167
+ f.write(f"{utterance_id}: {' '.join(gloss_strings)}\n")
168
+
169
+ # 输出统计信息
170
+ print("\n" + "="*80)
171
+ print("处理完成!")
172
+ print("="*80)
173
+ print(f"总utterances: {len(mapping)}")
174
+ print(f"成功处理: {len(result)}")
175
+ print(f"缺失CSV数据: {len(missing_utterances)}")
176
+
177
+ if missing_utterances:
178
+ print(f"\n缺失的utterances (前10个): {missing_utterances[:10]}")
179
+
180
+ # 显示一些示例
181
+ print("\n示例数据 (前3个):")
182
+ print("-"*80)
183
+ for i, (utterance_id, data) in enumerate(list(result.items())[:3], 1):
184
+ print(f"\n{i}. Utterance {utterance_id}:")
185
+ print(f" 总帧数: {data['total_frames_30fps']} (30fps) / {data['total_frames_24fps']} (24fps)")
186
+ print(f" 时长: {data['duration_seconds']} 秒")
187
+ print(f" Gloss数量: {data['gloss_count']}")
188
+ print(f" 前5个glosses:")
189
+ for g in data['glosses'][:5]:
190
+ print(f" - {g['gloss']}: "
191
+ f"30fps[{g['start_30fps']}:{g['end_30fps']}] "
192
+ f"-> 24fps[{g['start_24fps']}:{g['end_24fps']}] "
193
+ f"({g['duration_24fps']}帧)")
194
+
195
+ return result
196
+
197
+ def create_compact_format():
198
+ """创建紧凑格式的输出(类似原始mapping.txt)"""
199
+ OUTPUT_COMPACT = "ASLLRP_utterances_compact_frames.txt"
200
+
201
+ print(f"\n创建紧凑格式 {OUTPUT_COMPACT}...")
202
+
203
+ mapping = load_mapping()
204
+ csv_signs = load_csv_signs()
205
+
206
+ with open(OUTPUT_COMPACT, 'w', encoding='utf-8') as f:
207
+ for utterance_id in mapping.keys():
208
+ if utterance_id not in csv_signs:
209
+ continue
210
+
211
+ signs = csv_signs[utterance_id]
212
+
213
+ # 格式: utterance_id: gloss1|s24-e24 gloss2|s24-e24 ...
214
+ gloss_parts = []
215
+ for sign in signs:
216
+ # 使用24fps帧号(更常用)
217
+ gloss_parts.append(f"{sign['gloss']}|{sign['start_24fps']}-{sign['end_24fps']}")
218
+
219
+ f.write(f"{utterance_id}: {' '.join(gloss_parts)}\n")
220
+
221
+ print(f"紧凑格式已保存到 {OUTPUT_COMPACT}")
222
+
223
+ if __name__ == "__main__":
224
+ print("ASLLRP Gloss帧号生成工具")
225
+ print("="*80)
226
+
227
+ result = generate_gloss_with_frames()
228
+ create_compact_format()
229
+
230
+ print("\n" + "="*80)
231
+ print("生成的文件:")
232
+ print(f" 1. {OUTPUT_JSON} - 完整JSON格式(包含30fps和24fps)")
233
+ print(f" 2. {OUTPUT_TXT} - 可读文本格式")
234
+ print(f" 3. ASLLRP_utterances_compact_frames.txt - 紧凑格式(24fps)")
235
+ print("="*80)
SignX/doc/query_asllrp_data.py ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ ASLLRP数据集查询工具
4
+ 用于快速查询和提取特定utterance或sign的信息
5
+ """
6
+ import csv
7
+ import os
8
+ import argparse
9
+ from collections import defaultdict
10
+
11
+ # 数据路径
12
+ BASE_PATH = "/research/cbim/vast/sf895/code/Sign-X/output/huggingface_asllrp_repo"
13
+ MAPPING_FILE = os.path.join(BASE_PATH, "ASLLRP_utterances_mapping.txt")
14
+ CSV_FILE = os.path.join(BASE_PATH, "asllrp_sentence_signs_2025_06_28.csv")
15
+ RESULTS_DIR = os.path.join(BASE_PATH, "ASLLRP_utterances_results")
16
+
17
+ def load_csv_data():
18
+ """加载CSV数据"""
19
+ data = defaultdict(list)
20
+ with open(CSV_FILE, 'r') as f:
21
+ reader = csv.DictReader(f)
22
+ for row in reader:
23
+ utterance_video = row['Utterance video filename']
24
+ data[utterance_video].append(row)
25
+ return data
26
+
27
+ def load_mapping_data():
28
+ """加载mapping数据"""
29
+ mapping = {}
30
+ with open(MAPPING_FILE, 'r') as f:
31
+ for line in f:
32
+ video_id, glosses = line.strip().split(': ', 1)
33
+ mapping[video_id] = glosses.split()
34
+ return mapping
35
+
36
+ def query_utterance(utterance_id):
37
+ """查询特定utterance的详细信息"""
38
+ print("="*80)
39
+ print(f"Utterance ID: {utterance_id}")
40
+ print("="*80)
41
+
42
+ # 从mapping获取gloss序列
43
+ mapping = load_mapping_data()
44
+ if utterance_id in mapping:
45
+ glosses = mapping[utterance_id]
46
+ print(f"\nGloss序列 ({len(glosses)}个):")
47
+ print(" " + " ".join(glosses))
48
+ else:
49
+ print(f"\n警告: 在mapping.txt中找不到{utterance_id}")
50
+
51
+ # 从CSV获取详细信息
52
+ csv_data = load_csv_data()
53
+ utterance_key = f"{utterance_id}.mp4"
54
+
55
+ if utterance_key in csv_data:
56
+ signs = csv_data[utterance_key]
57
+ print(f"\nCSV中的Signs ({len(signs)}个):")
58
+
59
+ # 获取utterance的总帧范围
60
+ if signs:
61
+ utterance_start = int(signs[0]['Start frame of the containing utterance'])
62
+ utterance_end = int(signs[0]['End frame of the containing utterance'])
63
+ utterance_duration = utterance_end - utterance_start
64
+ print(f"\nUtterance帧范围: {utterance_start} - {utterance_end} (总共{utterance_duration}帧)")
65
+
66
+ print(f"\n详细Signs列表:")
67
+ print(f"{'序号':<4} {'Gloss':<30} {'原始视频帧范围':<20} {'裁剪视频帧范围':<20} {'类型':<20}")
68
+ print("-"*100)
69
+
70
+ for i, sign in enumerate(signs, 1):
71
+ gloss = sign['Main entry gloss label']
72
+ start = int(sign['Start frame of the sign video'])
73
+ end = int(sign['End frame of the sign video'])
74
+ sign_type = sign['Sign type']
75
+
76
+ # 计算在裁剪视频中的帧号
77
+ cropped_start = start - utterance_start
78
+ cropped_end = end - utterance_start
79
+
80
+ print(f"{i:<4} {gloss:<30} {start}-{end} ({end-start}帧)".ljust(58) +
81
+ f"{cropped_start}-{cropped_end}".ljust(24) +
82
+ f"{sign_type}")
83
+ else:
84
+ print(f"\n警告: 在CSV文件中找不到{utterance_id}")
85
+
86
+ # 检查results目录
87
+ results_path = os.path.join(RESULTS_DIR, utterance_id)
88
+ if os.path.exists(results_path):
89
+ print(f"\n处理结果目录: {results_path}")
90
+
91
+ # 检查crop_frame
92
+ crop_frame_dir = os.path.join(results_path, "crop_frame")
93
+ if os.path.exists(crop_frame_dir):
94
+ frames = [f for f in os.listdir(crop_frame_dir) if f.endswith('.jpg')]
95
+ print(f" - 裁剪帧数: {len(frames)}")
96
+
97
+ # 检查视频
98
+ video_path = os.path.join(results_path, "crop_original_video.mp4")
99
+ if os.path.exists(video_path):
100
+ size_mb = os.path.getsize(video_path) / (1024 * 1024)
101
+ print(f" - 裁剪视频大小: {size_mb:.2f} MB")
102
+
103
+ # 检查dwpose
104
+ dwpose_dir = os.path.join(results_path, "results_dwpose/npz")
105
+ if os.path.exists(dwpose_dir):
106
+ npz_files = [f for f in os.listdir(dwpose_dir) if f.endswith('.npz')]
107
+ print(f" - DWPose文件数: {len(npz_files)}")
108
+ else:
109
+ print(f"\n警告: 在results目录中找不到{utterance_id}")
110
+
111
+ def search_gloss(gloss_query):
112
+ """搜索包含特定gloss的utterances"""
113
+ print("="*80)
114
+ print(f"搜索Gloss: {gloss_query}")
115
+ print("="*80)
116
+
117
+ csv_data = load_csv_data()
118
+ matches = []
119
+
120
+ for utterance_video, signs in csv_data.items():
121
+ for sign in signs:
122
+ if gloss_query.upper() in sign['Main entry gloss label'].upper():
123
+ utterance_id = utterance_video.replace('.mp4', '')
124
+ matches.append({
125
+ 'utterance_id': utterance_id,
126
+ 'gloss': sign['Main entry gloss label'],
127
+ 'start_frame': int(sign['Start frame of the sign video']),
128
+ 'end_frame': int(sign['End frame of the sign video']),
129
+ 'sign_type': sign['Sign type']
130
+ })
131
+
132
+ print(f"\n找到 {len(matches)} 个匹配的signs:")
133
+ print(f"{'Utterance ID':<15} {'Gloss':<30} {'帧范围':<20} {'类型':<20}")
134
+ print("-"*90)
135
+
136
+ for match in matches[:20]: # 只显示前20个
137
+ print(f"{match['utterance_id']:<15} {match['gloss']:<30} "
138
+ f"{match['start_frame']}-{match['end_frame']}".ljust(24) +
139
+ f"{match['sign_type']}")
140
+
141
+ if len(matches) > 20:
142
+ print(f"\n... 还有 {len(matches) - 20} 个结果未显示")
143
+
144
+ def list_all_utterances():
145
+ """列出所有utterances的统计信息"""
146
+ print("="*80)
147
+ print("所有Utterances统计")
148
+ print("="*80)
149
+
150
+ mapping = load_mapping_data()
151
+ csv_data = load_csv_data()
152
+
153
+ print(f"\nMapping.txt中的utterances: {len(mapping)}")
154
+ print(f"CSV中的utterances: {len(csv_data)}")
155
+
156
+ results_dirs = [d for d in os.listdir(RESULTS_DIR)
157
+ if os.path.isdir(os.path.join(RESULTS_DIR, d))]
158
+ print(f"Results目录中的文件夹: {len(results_dirs)}")
159
+
160
+ # 统计gloss数量分布
161
+ gloss_counts = [len(glosses) for glosses in mapping.values()]
162
+ avg_gloss = sum(gloss_counts) / len(gloss_counts) if gloss_counts else 0
163
+ min_gloss = min(gloss_counts) if gloss_counts else 0
164
+ max_gloss = max(gloss_counts) if gloss_counts else 0
165
+
166
+ print(f"\nGloss统计:")
167
+ print(f" 平均每个utterance: {avg_gloss:.1f} 个glosses")
168
+ print(f" 最少: {min_gloss} 个glosses")
169
+ print(f" 最多: {max_gloss} 个glosses")
170
+
171
+ # 统计sign类型
172
+ sign_types = defaultdict(int)
173
+ for signs in csv_data.values():
174
+ for sign in signs:
175
+ sign_types[sign['Sign type']] += 1
176
+
177
+ print(f"\nSign类型分布:")
178
+ for sign_type, count in sorted(sign_types.items(), key=lambda x: x[1], reverse=True):
179
+ print(f" {sign_type}: {count}")
180
+
181
+ def extract_sign_info(utterance_id, gloss):
182
+ """提取特定sign的信息,用于代码中使用"""
183
+ csv_data = load_csv_data()
184
+ utterance_key = f"{utterance_id}.mp4"
185
+
186
+ if utterance_key not in csv_data:
187
+ print(f"错误: 找不到utterance {utterance_id}")
188
+ return None
189
+
190
+ signs = csv_data[utterance_key]
191
+ for sign in signs:
192
+ if gloss.upper() == sign['Main entry gloss label'].upper():
193
+ utterance_start = int(sign['Start frame of the containing utterance'])
194
+ start = int(sign['Start frame of the sign video'])
195
+ end = int(sign['End frame of the sign video'])
196
+
197
+ info = {
198
+ 'gloss': sign['Main entry gloss label'],
199
+ 'start_frame_original': start,
200
+ 'end_frame_original': end,
201
+ 'start_frame_cropped': start - utterance_start,
202
+ 'end_frame_cropped': end - utterance_start,
203
+ 'duration': end - start,
204
+ 'sign_type': sign['Sign type']
205
+ }
206
+
207
+ print(f"Sign信息:")
208
+ print(f" Gloss: {info['gloss']}")
209
+ print(f" 原始视频帧: {info['start_frame_original']} - {info['end_frame_original']}")
210
+ print(f" 裁剪视频帧: {info['start_frame_cropped']} - {info['end_frame_cropped']}")
211
+ print(f" 持续时间: {info['duration']} 帧")
212
+ print(f" 类型: {info['sign_type']}")
213
+
214
+ return info
215
+
216
+ print(f"错误: 在utterance {utterance_id} 中找不到gloss '{gloss}'")
217
+ return None
218
+
219
+ if __name__ == "__main__":
220
+ parser = argparse.ArgumentParser(description='ASLLRP数据集查询工具')
221
+ parser.add_argument('--utterance', '-u', help='查询特定utterance ID')
222
+ parser.add_argument('--search', '-s', help='搜索包含特定gloss的utterances')
223
+ parser.add_argument('--list', '-l', action='store_true', help='列出所有utterances的统计')
224
+ parser.add_argument('--extract', '-e', nargs=2, metavar=('UTTERANCE_ID', 'GLOSS'),
225
+ help='提取特定sign的信息')
226
+
227
+ args = parser.parse_args()
228
+
229
+ if args.utterance:
230
+ query_utterance(args.utterance)
231
+ elif args.search:
232
+ search_gloss(args.search)
233
+ elif args.list:
234
+ list_all_utterances()
235
+ elif args.extract:
236
+ extract_sign_info(args.extract[0], args.extract[1])
237
+ else:
238
+ print("使用示例:")
239
+ print(" 查询utterance: python query_asllrp_data.py --utterance 10006709")
240
+ print(" 搜索gloss: python query_asllrp_data.py --search THAT")
241
+ print(" 列出统计: python query_asllrp_data.py --list")
242
+ print(" 提取sign: python query_asllrp_data.py --extract 10006709 THAT")
243
+ parser.print_help()
SignX/inference_output.txt DELETED
@@ -1 +0,0 @@
1
- <unk> #IF FRIEND GROUP/TOGE@@ TH@@ E@@ R DEPART PARTY IX-1p FINISH JO@@ I@@ N IX-1p
 
 
SignX/inference_output.txt.clean DELETED
@@ -1 +0,0 @@
1
- <unk> #IF FRIEND GROUP/TOGETHER DEPART PARTY IX-1p FINISH JOIN IX-1p
 
 
asllrp_sentence_signs_2025_06_28.csv ADDED
The diff for this file is too large to render. See raw diff