27def build_model(cfg, device='cpu'):
28 """
29 세이프모션 라이브러리의 모델들을 빌드하는 기능
30 action, detect, pose, track 모델들을 빌드할 수 있음
31 args:
32 cfg (str or Config): 모델의 config 파일 경로 또는 mmengine.config.Config.fromfile()로 생성한 객체
33 device (str): 모델이 구동될 디바이스
34 return : 세이프모션 라이브러리의 모델
35 """
36
37
38 if isinstance(cfg, str):
39 cfg = Config.fromfile(cfg)
40
41 model = cfg.model
42 model_args = model.copy()
43
44
45 if model.type in det_runner_builders:
46 model = build_detect_runner(model_args)
47
48 elif model.type in pose_runner_builders:
49 model = build_pose_runner(model_args)
50
51 elif model.type in action_runner_builders:
52 model = build_action_runner(model_args)
53 if cfg.test.model_path is not None:
54 load_model(model, cfg.test.model_path, device=device)
55
56 elif model.type in track_runner_builders:
57 model = build_track_runner(model_args)
58 else:
59 return None
60
61 return model
62
63
64
65
66
67
68
69
70