PawanratRung commited on
Commit
9c0446b
·
verified ·
1 Parent(s): eaddd48

Create utils.py

Browse files
Files changed (1) hide show
  1. 3rdparty/densepose/data/utils.py +38 -0
3rdparty/densepose/data/utils.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Facebook, Inc. and its affiliates.
2
+
3
+ import os
4
+ from typing import Dict, Optional
5
+
6
+ from detectron2.config import CfgNode
7
+
8
+
9
+ def is_relative_local_path(path: str) -> bool:
10
+ path_str = os.fsdecode(path)
11
+ return ("://" not in path_str) and not os.path.isabs(path)
12
+
13
+
14
+ def maybe_prepend_base_path(base_path: Optional[str], path: str):
15
+ """
16
+ Prepends the provided path with a base path prefix if:
17
+ 1) base path is not None;
18
+ 2) path is a local path
19
+ """
20
+ if base_path is None:
21
+ return path
22
+ if is_relative_local_path(path):
23
+ return os.path.join(base_path, path)
24
+ return path
25
+
26
+
27
+ def get_class_to_mesh_name_mapping(cfg: CfgNode) -> Dict[int, str]:
28
+ return {
29
+ int(class_id): mesh_name
30
+ for class_id, mesh_name in cfg.DATASETS.CLASS_TO_MESH_NAME_MAPPING.items()
31
+ }
32
+
33
+
34
+ def get_category_to_class_mapping(dataset_cfg: CfgNode) -> Dict[str, int]:
35
+ return {
36
+ category: int(class_id)
37
+ for category, class_id in dataset_cfg.CATEGORY_TO_CLASS_MAPPING.items()
38
+ }