Safemotion Lib
Loading...
Searching...
No Matches
cvt_labelmap.py
Go to the documentation of this file.
1import copy
2
3#초기 레이블맵, 21년도 제작 데이터, 서현호 소장님 업무 참조
4labelmap_v10={
5 0 : 'walk',
6 1 : 'stand',
7 2 : 'sit-Crouch',
8 3 : 'sit-sofa',
9 4 : 'sit-chair',
10 5 : 'sit-floor',
11 6 : 'falling-falling',
12 7 : 'lie',
13 8 : 'punch',
14 9 : 'kick',
15 10 : 'falling-fight',
16 11 : 'plunging',
17 12 : 'sit',
18 13 : 'falling'
19}
20
21#22년 레이블 맵, 행동 시나리오 확장
22labelmap_v20={
23 0: "없음",
24 1: "앉기-바닥",
25 2: "앉기-의자",
26 3: "구부리기",
27 4: "걷기-혼자",
28 5: "걷기-잡고",
29 6: "걷기-앉은상태",
30 7: "걷기-계단오르기",
31 8: "걷기-계단내려가기",
32 9: "뛰기-달리기",
33 10: "뛰기-외발뛰기",
34 11: "뛰기-갤로핑",
35 12: "뛰기-게걸음",
36 13: "일어서기-스스로",
37 14: "일어서기-짚고",
38 15: "눕기",
39 16: "눕기-업드려 머리들기",
40 17: "뒤집기-시도",
41 18: "뒤집기-성공",
42 19: "뒤집기-굴러가기",
43 20: "기어가기-무릎기기",
44 21: "기어가기-배밀이",
45 22: "기어가기-계단기기",
46 23: "기어오르기",
47 24: "점프-제자리",
48 25: "점프-두발",
49 26: "잡기",
50 27: "끼적이기",
51 28: "빨기-손",
52 29: "빨기-놀잇감",
53 30: "안기-안겨있기",
54 31: "안기-안고있기",
55 32: "빼앗기",
56 33: "먹기-스스로",
57 34: "먹기-마시기",
58 35: "먹기-받아먹기",
59 36: "먹여주기",
60 37: "넘어짐",
61 38: "부딪힘-벽",
62 39: "부딪힘-사람",
63 40: "할퀴기",
64 41: "물기",
65 42: "떨어짐",
66 43: "물건 던지기",
67 44: "손으로 때리기",
68 45: "물건으로 때리기",
69 46: "발로 때리기",
70 47: "양팔제압하기",
71 48: "밀치기",
72 49: "당기기",
73 50: "옷(기저귀) 갈아입기",
74 51: "쓰다듬기",
75 52: "토닥이기",
76 53: "머리 따주기",
77 54: "영유아를 들어서 옮기기",
78 55: "물건 건네주기",
79 56: "물건 받기",
80 57: "사진찍기"
81}
82
83#레이블맵 v10을 simple_lablemap으로 변환하는 맵, [클래스번호, 클래스명, 변환 라벨]
84cvt_labelmap_v10_action_to_simple_ver=[
85 [0 , 'walk', 6],
86 [1 , 'stand', 4],
87 [2 , 'sit-Crouch', 2],
88 [3 , 'sit-sofa', 1],
89 [4 , 'sit-chair', 1],
90 [5 , 'sit-floor', 0],
91 [6 , 'falling-falling', 14],
92 [7 , 'lie', 9],
93 [8 , 'punch', 15],
94 [9 , 'kick', 16],
95 [10 , 'falling-fight', 14],
96]
97
98#간소화 레이블
99simple_lablemap={
100 0 : "sit",#"앉기",
101 1 : "sit_chair",
102 2 : "sit_squat",
103 3 : "sit_move", #앉은상태로 이동
104 4 : "standing",#"서있기",
105 5 : "bend_over",#허리숙이기
106 6 : "walk",#"걷기",
107 7 : "run",#"뛰기",
108 #8 : "run_galloping", #갤로핑
109 8 : "stand",#"일어서기",
110 9 : "lying",#"누워있기",
111 10 : "crawl",#"기어가기",
112 11 : "crawl_pose",#"기어가기 자세",
113 12 : "jump",#"점프",
114 13 : "eating",#"먹기",
115 14 : "fall-down",#"넘어짐", "떨어짐"
116 15 : "punch", #"펀치"
117 16 : "kick", #"발차기",
118 #18 : "scrawl", #"끼적이기"
119}
120
121#v21 어노테이션 버전의 action 라벨을 simple_lablemap으로 변환하는 테이블
122cvt_labelmap_v21_action_to_simple_ver=[
123 [0, "없음", None],
124 [1, "앉기-바닥",None],
125 [2, "앉기-의자",None],
126 [3, "구부리기",None],
127 [4, "걷기-혼자",6],
128 [5, "걷기-잡고",6],
129 [6, "걷기-앉은상태",3],
130 [7, "걷기-계단오르기",6],
131 [8, "걷기-계단내려가기",6],
132 [9, "뛰기-달리기", 7],
133 [10, "뛰기-외발뛰기", 7],
134 [11, "뛰기-갤로핑", None],
135 [12, "뛰기-게걸음", None],
136 [13, "일어서기-스스로", 8],
137 [14, "일어서기-짚고", 8],
138 [15, "눕기", 9],
139 [16, "눕기-업드려 머리들기",9],
140 [17, "뒤집기-시도", 9],
141 [18, "뒤집기-성공", 9],
142 [19, "뒤집기-굴러가기", 9],
143 [20, "기어가기-무릎기기", 10],
144 [21, "기어가기-배밀이", None],
145 [22, "기어가기-계단기기", 10],
146 [23, "기어오르기", None],
147 [24, "점프-제자리", 12],
148 [25, "점프-두발", 12],
149 [26, "잡기", None],
150 [27, "끼적이기", None],
151 [28, "빨기-손", 13],
152 [29, "빨기-놀잇감", 13],
153 [30, "안기-안겨있기", None],
154 [31, "안기-안고있기", None],
155 [32, "빼앗기", None],
156 [33, "먹기-스스로", 13],
157 [34, "먹기-마시기", 13],
158 [35, "먹기-받아먹기", None],
159 [36, "먹여주기", None],
160 [37, "넘어짐", 14],
161 [38, "부딪힘-벽", None],
162 [39, "부딪힘-사람", None],
163 [40, "할퀴기", None],
164 [41, "물기", None],
165 [42, "떨어짐", None],
166 [43, "물건 던지기", None],
167 [44, "손으로 때리기", 15],
168 [45, "물건으로 때리기", 15],
169 [46, "발로 때리기", 16],
170 [47, "양팔제압하기", None],
171 [48, "밀치기", None],
172 [49, "당기기", None],
173 [50, "옷(기저귀) 갈아입기", None],
174 [51, "쓰다듬기", None],
175 [52, "토닥이기", None],
176 [53, "머리 따주기", None],
177 [54, "영유아를 들어서 옮기기", None],
178 [55, "물건 건네주기", None],
179 [56, "물건 받기", None],
180 [57, "사진찍기", None],
181 [58, "식별불가", -1]
182]
183
184#v21 어노테이션 버전의 foot 라벨을 simple_lablemap으로 변환하는 테이블
185cvt_labelmap_v21_foot_to_simple_ver=[
186 [0, "없음", None],
187 [1, "이동-느리게",6],
188 [2, "이동-빠르게",7],
189 [3, "이동-물건 위로",None],
190 [4, "이동-계단 오르기",None],
191 [5, "이동-계산 내려가기",None],
192]
193
194#v21 어노테이션 버전의 pose 라벨을 simple_lablemap으로 변환하는 테이블
195cvt_labelmap_v21_pose_to_simple_ver=[
196 [0, "앉기-바닥", 0],
197 [1, "앉기-의자", 1],
198 [2, "앉기-무릎꿇기", 0],
199 [3, "앉기-무릎서기", 4],
200 [4, "앉기-쪼그리기", 2],
201 [5, "서있기", 4],
202 [6, "서있기-한발들기", 4],
203 [7, "서있기-무릎구부리기", 4],
204 [8, "서있기-허리구부리기", 5],
205 [9, "누워있기-천장보고", 9],
206 [10, "누워있기-엎드리기", 9],
207 [11, "누워있기-옆으로", 9],
208 [12, "누워있기-엎드려 머리들기", 9],
209 [13, "누워있기-구부리기", 9],
210 [14, "무릎기기 자세", 11]
211]
212
213#상호행동의 간소화 레이블맵
214simple_mutual_labelmap={
215 0 : "None",
216 1 : "안기",
217 2 : "옷 갈아입히기(서서)",
218 3 : "옷 갈아입히기(눕혀서)",
219 4 : "쓰다듬기",
220 5 : "토닥이기",
221 6 : "머리따주기",
222 7 : "먹여주기",
223 8 : "물건 전달",
224 9 : "밀기",
225 10 : "당기기",
226 11 : "부딪힘",
227 12 : "손으로 때리기",
228 13 : "발로 때리기",
229 14 : "물기"
230}
231
232#상호행동 레이블맵
233mutual_action_lablemap={
234 0 : "None",
235 1 : "안겨있기", #
236 2 : "안고있기", #
237 3 : "영유아를 들어서 이동", #
238 4 : "옷(기저귀) 갈아입히기", #
239 5 : "쓰다듬기", #
240 6 : "토닥이기", #
241 7 : "머리따주기",
242 8 : "먹여주기", #
243 9 : "물건 건네주기", #
244 10 : "물건 받기", #
245 11 : "장난감 빼앗기",
246 12 : "손으로 때리기",
247 13 : "물건으로 때리기",
248 14 : "발로 때리기",
249 15 : "신체 밀치기", #
250 16 : "신체 당기기", #
251 17 : "친구와 부딪힘",
252 18 : "할퀴기",
253 19 : "물기"
254}
255
256
257cvt_labelmap_v21_action_to_simple_ver2=[
258 [0, "없음", None],
259 [1, "앉기-바닥",None],
260 [2, "앉기-의자",None],
261 [3, "구부리기",None],
262 [4, "걷기-혼자",1],
263 [5, "걷기-잡고",1],
264 [6, "걷기-앉은상태",None],
265 [7, "걷기-계단오르기",1],
266 [8, "걷기-계단내려가기",1],
267 [9, "뛰기-달리기", 2],
268 [10, "뛰기-외발뛰기", 2],
269 [11, "뛰기-갤로핑", None],
270 [12, "뛰기-게걸음", None],
271 [13, "일어서기-스스로", None],
272 [14, "일어서기-짚고", None],
273 [15, "눕기", None],
274 [16, "눕기-업드려 머리들기",None],
275 [17, "뒤집기-시도", None],
276 [18, "뒤집기-성공", None],
277 [19, "뒤집기-굴러가기", None],
278 [20, "기어가기-무릎기기", 3],
279 [21, "기어가기-배밀이", None],
280 [22, "기어가기-계단기기", 3],
281 [23, "기어오르기", None],
282 [24, "점프-제자리", 4],
283 [25, "점프-두발", 4],
284 [26, "잡기", None],
285 [27, "끼적이기", None],
286 [28, "빨기-손", 5],
287 [29, "빨기-놀잇감", 5],
288 [30, "안기-안겨있기", None],
289 [31, "안기-안고있기", None],
290 [32, "빼앗기", None],
291 [33, "먹기-스스로", 5],
292 [34, "먹기-마시기", 5],
293 [35, "먹기-받아먹기", None],
294 [36, "먹여주기", None],
295 [37, "넘어짐", 6],
296 [38, "부딪힘-벽", None],
297 [39, "부딪힘-사람", None],
298 [40, "할퀴기", None],
299 [41, "물기", None],
300 [42, "떨어짐", None],
301 [43, "물건 던지기", None],
302 [44, "손으로 때리기", 7],
303 [45, "물건으로 때리기", 7],
304 [46, "발로 때리기", 8],
305 [47, "양팔제압하기", None],
306 [48, "밀치기", None],
307 [49, "당기기", None],
308 [50, "옷(기저귀) 갈아입기", None],
309 [51, "쓰다듬기", None],
310 [52, "토닥이기", None],
311 [53, "머리 따주기", None],
312 [54, "영유아를 들어서 옮기기", None],
313 [55, "물건 건네주기", None],
314 [56, "물건 받기", None],
315 [57, "사진찍기", None],
316 [58, "식별불가", None]
317]
318
319cvt_labelmap_v21_pose_to_simple_ver2=[
320 [0, "앉기-바닥", 0],
321 [1, "앉기-의자", 0],
322 [2, "앉기-무릎꿇기", 0],
323 [3, "앉기-무릎서기", 1],
324 [4, "앉기-쪼그리기", 0],
325 [5, "서있기", 1],
326 [6, "서있기-한발들기", 1],
327 [7, "서있기-무릎구부리기", 1],
328 [8, "서있기-허리구부리기", 1],
329 [9, "누워있기-천장보고", 2],
330 [10, "누워있기-엎드리기", 2],
331 [11, "누워있기-옆으로", 2],
332 [12, "누워있기-엎드려 머리들기", 2],
333 [13, "누워있기-구부리기", 2],
334 [14, "무릎기기 자세", 3]
335]
336
337simple_lablemap_action={
338 0 : "None",
339 1 : "walk",
340 2 : "run",
341 3 : "crawl",
342 4 : "jump",
343 5 : "eat",
344 6 : "fall-down",
345 7 : "punch",
346 8 : "kick",
347}
348
349simple_lablemap_pose={
350 0 : "sit",
351 1 : "standing",
352 2 : "lying",
353 3 : "crawl_pose"
354}
355
356
357cvt_labelmap_v22_action_upper=[
358 #idx, name, cvt_label, min_clip_len, use_margin, check_train_frame
359 [0, "없음", 0, 0, False],
360 [1, "허리 구부리기", 1, 0, True],
361 [2, "허리 펴기", 2, 0, True],
362 [3, "먹기", -1, 0, True],
363 [4, "펀치", 3, 0, True],
364 [5, "휘두르기", -1, 0, True],
365 [6, "손흔들기", 4, 0, True],
366 [7, "가리키기", 5, 0, True],
367 [8, "밀치기", 3, 0, True],
368 [9, "끼적이기", -1, 0, True],
369 [10, "기타", -1, 0, True],
370]
371
372simple_labelmap_v22_action_upper = [
373 [0, "없음"],
374 [1, "허리 구부리기"],
375 [2, "허리 펴기"],
376 [3, "펀치"],
377 [4, "손흔들기"],
378 [5, "가리키기"]
379]
380
381cvt_labelmap_v22_action_lower=[
382 [0, "없음", 0, 0, False],
383 [1, "앉기", 1, 0, True],
384 [2, "일어서기", 2, 0, True],
385 [3, "서성이기", 3, 50, True],
386 [4, "걷기", 4, 50, True],
387 [5, "달리기", 5, 15, True], #
388 [6, "기어가기", 6, 20, True], #
389 [7, "점프-제자리", 7, 0, True], #
390 [8, "넘어짐", 8, 0, True],
391 [9, "떨어짐", -1, 0, True],
392 [10, "킥", 9, 0, True], #
393 [11, "턴", 10, 0, True],
394 [12, "점프-두발", 11, 0, True], #
395 [13, "기타", -1, 0, False], #
396]
397
398simple_labelmap_v22_action_lower = [
399 [0, "없음"],
400 [1, "앉기"],
401 [2, "일어서기"],
402 [3, "서성이기"],
403 [4, "걷기"],
404 [5, "달리기"],
405 [6, "기어가기"],
406 [7, "점프-제자리"],
407 [8, "넘어짐"],
408 [9, "킥"],
409 [10, "턴"],
410 [11, "점프-두발"],
411]
412
413
414# cvt_labelmap_v22_action_pose=[
415# [0, "앉기-바닥", 0, 10, False],
416# [1, "앉기-의자", 1, 10, False],
417# [2, "앉기-무릎꿇기", -1, 10, False],
418# [3, "앉기-무릎서기", -1, 10, False],
419# [4, "앉기-쪼그리기", 2, 10, False],
420# [5, "서있기", 3, 10, False],
421# [6, "서있기-한발들기", 3, 10, False],
422# [7, "서있기-허리구부리기", 4, 10, False],
423# [8, "스쿼트-허리세우기", 5, 10, False],
424# [9, "스쿼트-허리구부리기", 5, 10, False],
425# [10, "누워있기-천장보고", 6, 10, False],
426# [11, "누워있기-엎드리기", 6, 10, False],
427# [12, "누워있기-옆으로", 6, 10, False],
428# [13, "무릎기기 자세", 7, 10, False],
429# [14, "앉기-한쪽무릎굽히기", -1, 10, False],
430# [15, "식별불가", -1, 10, False]
431# ]
432
433# simple_labelmap_v22_pose = [
434# [0, "앉기-바닥"],
435# [1, "앉기-의자"],
436# [2, "앉기-쪼그리기"],
437# [3, "서있기"],
438# [4, "서있기-허리구부리기"],
439# [5, "스쿼트"],
440# [6, "누워있기"],
441# [7, "무릎기기 자세"],
442# ]
443
444pose_min_clip_range = 15
445cvt_labelmap_v22_action_pose=[
446 [0, "앉기-바닥", 0, pose_min_clip_range, False],
447 [1, "앉기-의자", 1, pose_min_clip_range, False],
448 [2, "앉기-무릎꿇기", 2, pose_min_clip_range, False],
449 [3, "앉기-무릎서기", 3, pose_min_clip_range, False],
450 [4, "앉기-쪼그리기", -1, pose_min_clip_range, False],
451 [5, "서있기", 4, pose_min_clip_range, False],
452 [6, "서있기-한발들기", 4, pose_min_clip_range, False],
453 [7, "서있기-허리구부리기", 5, pose_min_clip_range, False],
454 [8, "스쿼트-허리세우기", -1, pose_min_clip_range, False],
455 [9, "스쿼트-허리구부리기", -1, pose_min_clip_range, False],
456 [10, "누워있기-천장보고", 6, pose_min_clip_range, False],
457 [11, "누워있기-엎드리기", 6, pose_min_clip_range, False],
458 [12, "누워있기-옆으로", 6, pose_min_clip_range, False],
459 [13, "무릎기기 자세", 7, pose_min_clip_range, False],
460 [14, "앉기-한쪽무릎굽히기", -1, pose_min_clip_range, False],
461 [15, "식별불가", -1, pose_min_clip_range, False]
462]
463
464simple_labelmap_v22_pose = [
465 [0, "앉기"],
466 [1, "앉기-의자"],
467 [2, "앉기-무릎꿇기"],
468 [3, "앉기-무릎서기"],
469 [4, "서있기"],
470 [5, "서있기-허리구부리기"],
471 [6, "누워있기"],
472 [7, "무릎기기 자세"],
473]
474
475cvt_labelmap_v22_action_hand=[
476 [0, "없음", 0, pose_min_clip_range, False],
477 [1, "팔짱끼기", 1, pose_min_clip_range, False],
478 [2, "가리키기", 2, pose_min_clip_range, False],
479 [3, "기타", -1, pose_min_clip_range, False],
480 [4, "양팔들기", 3, pose_min_clip_range, False],
481]
482
483simple_labelmap_v22_hand = [
484 [0, "없음"],
485 [1, "팔짱끼기"],
486 [2, "가리키기"],
487 [3, "양팔들기"],
488]
489
490cvt_labelmap_v22_action_foot=[
491 [0, "없음", 0, pose_min_clip_range, False],
492 [1, "다리꼬기", 1, pose_min_clip_range, False],
493 [2, "기타", -1, pose_min_clip_range, False],
494]
495
496simple_labelmap_v22_foot = [
497 [0, "없음"],
498 [1, "다리꼬기"],
499]
500
501cvt_labelmap_v22_mutual_action=[
502 [0, "없음", 0],
503 [1, "안겨있기", 1],
504 [2, "안고있기", 2],
505 [3, "영유아를 들어서 이동", 3],
506 [4, "옷(기저귀) 갈아입히기", -1],
507 [5, "쓰다듬기", 4],
508 [6, "토닥이기", 5],
509 [7, "머리따주기", -1],
510 [8, "먹여주기", 6],
511 [9, "물건 건네주기", -1],
512 [10, "물건 받기", -1],
513 [11, "장난감 빼앗기", -1],
514 [12, "손으로 때리기", -1],
515 [13, "물건으로 때리기", -1],
516 [14, "발로 때리기", -1],
517 [15, "신체 밀치기", 7],
518 [16, "신체 당기기", 8],
519 [17, "친구와 부딪힘", -1],
520 [18, "할퀴기", -1],
521 [19, "물기", -1],
522 [20, "매달리기", -1],
523 [21, "안고있기-토닥이기", -1]
524]
525
526simple_labelmap_v22_mutual_action = [
527 [0, "없음", 0, False],
528 [1, "안겨있기", 50, False],
529 [2, "안고있기", 40, False],
530 [3, "영유아를 들어서 이동", 0, False],
531 [4, "쓰다듬기", 40, False],
532 [5, "토닥이기", 10, True],
533 [6, "먹여주기", 40, False],
534 [7, "신체 밀치기", 10, True],
535 [8, "신체 당기기", 50, False]
536]
537
538def cvt_labelmap_v21(annotations, cvt_action_info, cvt_pose_info):
539 ret_annotations = copy.deepcopy(annotations)
540 for i, anno in enumerate(annotations):
541 action_id = anno['action_id']['action']
542 new_action_id = cvt_action_info[action_id][2]
543
544 if action_id == 11 or action_id == 12:
545 move_id = anno['action_id']['foot']
546 new_action_id = cvt_labelmap_v21_foot_to_simple_ver[move_id][2]
547 elif new_action_id is None:
548 pose_id = anno['action_id']['pose']
549 new_action_id = cvt_pose_info[pose_id][2]
550
551 if anno['truncation'] > 2 or anno['occlusion'] > 2:
552 new_action_id = -1
553
554 ret_annotations[i]['action_id']['action'] = new_action_id
555
556 return ret_annotations
557
558def cvt_labelmap_v21_pose_and_action(annotations, cvt_action_info, cvt_pose_info):
559 ret_annotations = copy.deepcopy(annotations)
560 for i, anno in enumerate(annotations):
561 action_id = anno['action_id']['action']
562 pose_id = anno['action_id']['pose']
563 new_action_id = cvt_action_info[action_id][2]
564 if new_action_id is None:
565 new_action_id = 0
566
567 new_pose_id = cvt_pose_info[pose_id][2]
568
569 ret_annotations[i]['action_id']['action'] = new_action_id
570 ret_annotations[i]['action_id']['pose'] = new_pose_id
571
572 return ret_annotations
573
574def cvt_labelmap_v22(annotations):
575 ret_annotations = copy.deepcopy(annotations)
576 for i, anno in enumerate(annotations):
577 action_id = anno['action_id']
578 upper = action_id['action_upper']
579 lower = action_id['action_lower']
580 pose = action_id['pose']
581 hand = action_id['hand']
582 foot = action_id['foot']
583
584 new_upper = cvt_labelmap_v22_action_upper[upper][2]
585 new_lower = cvt_labelmap_v22_action_lower[lower][2]
586 new_pose = cvt_labelmap_v22_action_pose[pose][2]
587 new_hand = cvt_labelmap_v22_action_hand[hand][2]
588 new_foot = cvt_labelmap_v22_action_foot[foot][2]
589
590 ret_annotations[i]['action_id']['action_upper'] = new_upper
591 ret_annotations[i]['action_id']['action_lower'] = new_lower
592 ret_annotations[i]['action_id']['pose'] = new_pose
593 ret_annotations[i]['action_id']['hand'] = new_hand
594 ret_annotations[i]['action_id']['foot'] = new_foot
595
596 return ret_annotations
597
598
599def cvt_labelmap_v10_pkl(pkl_data, cvt_action_info):
600 ret_pkl = copy.deepcopy(pkl_data)
601 for i, anno in enumerate(pkl_data):
602 action_id = anno['label']
603 new_action_id = cvt_action_info[action_id][2]
604
605 ret_pkl[i]['label'] = new_action_id
606
607 return ret_pkl
cvt_labelmap_v21_pose_and_action(annotations, cvt_action_info, cvt_pose_info)
cvt_labelmap_v21(annotations, cvt_action_info, cvt_pose_info)
cvt_labelmap_v22(annotations)
cvt_labelmap_v10_pkl(pkl_data, cvt_action_info)