python-wml 3.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of python-wml might be problematic. Click here for more details.

Files changed (164) hide show
  1. python_wml-3.0.0.dist-info/LICENSE +23 -0
  2. python_wml-3.0.0.dist-info/METADATA +51 -0
  3. python_wml-3.0.0.dist-info/RECORD +164 -0
  4. python_wml-3.0.0.dist-info/WHEEL +5 -0
  5. python_wml-3.0.0.dist-info/top_level.txt +1 -0
  6. wml/__init__.py +0 -0
  7. wml/basic_data_def/__init__.py +2 -0
  8. wml/basic_data_def/detection_data_def.py +279 -0
  9. wml/basic_data_def/io_data_def.py +2 -0
  10. wml/basic_img_utils.py +816 -0
  11. wml/img_patch.py +92 -0
  12. wml/img_utils.py +571 -0
  13. wml/iotoolkit/__init__.py +17 -0
  14. wml/iotoolkit/aic_keypoint.py +115 -0
  15. wml/iotoolkit/baidu_mask_toolkit.py +244 -0
  16. wml/iotoolkit/base_dataset.py +210 -0
  17. wml/iotoolkit/bboxes_statistics.py +515 -0
  18. wml/iotoolkit/build.py +0 -0
  19. wml/iotoolkit/cityscapes_toolkit.py +183 -0
  20. wml/iotoolkit/classification_data_statistics.py +25 -0
  21. wml/iotoolkit/coco_data_fwd.py +225 -0
  22. wml/iotoolkit/coco_keypoints.py +118 -0
  23. wml/iotoolkit/coco_keypoints_fmt2.py +103 -0
  24. wml/iotoolkit/coco_toolkit.py +397 -0
  25. wml/iotoolkit/coco_wholebody.py +269 -0
  26. wml/iotoolkit/common.py +108 -0
  27. wml/iotoolkit/crowd_pose.py +146 -0
  28. wml/iotoolkit/fast_labelme.py +110 -0
  29. wml/iotoolkit/image_folder.py +95 -0
  30. wml/iotoolkit/imgs_cache.py +58 -0
  31. wml/iotoolkit/imgs_reader_mt.py +73 -0
  32. wml/iotoolkit/labelme_base.py +102 -0
  33. wml/iotoolkit/labelme_json_to_img.py +49 -0
  34. wml/iotoolkit/labelme_toolkit.py +117 -0
  35. wml/iotoolkit/labelme_toolkit_fwd.py +733 -0
  36. wml/iotoolkit/labelmemckeypoints_dataset.py +169 -0
  37. wml/iotoolkit/lspet.py +48 -0
  38. wml/iotoolkit/mapillary_vistas_toolkit.py +269 -0
  39. wml/iotoolkit/mat_data.py +90 -0
  40. wml/iotoolkit/mckeypoints_statistics.py +28 -0
  41. wml/iotoolkit/mot_datasets.py +62 -0
  42. wml/iotoolkit/mpii.py +108 -0
  43. wml/iotoolkit/npmckeypoints_dataset.py +164 -0
  44. wml/iotoolkit/o365_to_coco.py +136 -0
  45. wml/iotoolkit/object365_toolkit.py +156 -0
  46. wml/iotoolkit/object365v2_toolkit.py +71 -0
  47. wml/iotoolkit/pascal_voc_data.py +51 -0
  48. wml/iotoolkit/pascal_voc_toolkit.py +194 -0
  49. wml/iotoolkit/pascal_voc_toolkit_fwd.py +473 -0
  50. wml/iotoolkit/penn_action.py +57 -0
  51. wml/iotoolkit/rawframe_dataset.py +129 -0
  52. wml/iotoolkit/rewrite_pascal_voc.py +28 -0
  53. wml/iotoolkit/semantic_data.py +49 -0
  54. wml/iotoolkit/split_file_by_type.py +29 -0
  55. wml/iotoolkit/sports_mot_datasets.py +78 -0
  56. wml/iotoolkit/vis_objectdetection_dataset.py +70 -0
  57. wml/iotoolkit/vis_torch_data.py +39 -0
  58. wml/iotoolkit/yolo_toolkit.py +38 -0
  59. wml/object_detection2/__init__.py +4 -0
  60. wml/object_detection2/basic_visualization.py +37 -0
  61. wml/object_detection2/bboxes.py +812 -0
  62. wml/object_detection2/data_process_toolkit.py +146 -0
  63. wml/object_detection2/keypoints.py +292 -0
  64. wml/object_detection2/mask.py +120 -0
  65. wml/object_detection2/metrics/__init__.py +3 -0
  66. wml/object_detection2/metrics/build.py +15 -0
  67. wml/object_detection2/metrics/classifier_toolkit.py +440 -0
  68. wml/object_detection2/metrics/common.py +71 -0
  69. wml/object_detection2/metrics/mckps_toolkit.py +338 -0
  70. wml/object_detection2/metrics/toolkit.py +1953 -0
  71. wml/object_detection2/npod_toolkit.py +361 -0
  72. wml/object_detection2/odtools.py +243 -0
  73. wml/object_detection2/standard_names.py +75 -0
  74. wml/object_detection2/visualization.py +956 -0
  75. wml/object_detection2/wmath.py +34 -0
  76. wml/semantic/__init__.py +0 -0
  77. wml/semantic/basic_toolkit.py +65 -0
  78. wml/semantic/mask_utils.py +156 -0
  79. wml/semantic/semantic_test.py +21 -0
  80. wml/semantic/structures.py +1 -0
  81. wml/semantic/toolkit.py +105 -0
  82. wml/semantic/visualization_utils.py +658 -0
  83. wml/threadtoolkit.py +50 -0
  84. wml/walgorithm.py +228 -0
  85. wml/wcollections.py +212 -0
  86. wml/wfilesystem.py +487 -0
  87. wml/wml_utils.py +657 -0
  88. wml/wstructures/__init__.py +4 -0
  89. wml/wstructures/common.py +9 -0
  90. wml/wstructures/keypoints_train_toolkit.py +149 -0
  91. wml/wstructures/kps_structures.py +579 -0
  92. wml/wstructures/mask_structures.py +1161 -0
  93. wml/wtorch/__init__.py +8 -0
  94. wml/wtorch/bboxes.py +104 -0
  95. wml/wtorch/classes_suppression.py +24 -0
  96. wml/wtorch/conv_module.py +181 -0
  97. wml/wtorch/conv_ws.py +144 -0
  98. wml/wtorch/data/__init__.py +16 -0
  99. wml/wtorch/data/_utils/__init__.py +45 -0
  100. wml/wtorch/data/_utils/collate.py +183 -0
  101. wml/wtorch/data/_utils/fetch.py +47 -0
  102. wml/wtorch/data/_utils/pin_memory.py +121 -0
  103. wml/wtorch/data/_utils/signal_handling.py +72 -0
  104. wml/wtorch/data/_utils/worker.py +227 -0
  105. wml/wtorch/data/base_data_loader_iter.py +93 -0
  106. wml/wtorch/data/dataloader.py +501 -0
  107. wml/wtorch/data/datapipes/__init__.py +1 -0
  108. wml/wtorch/data/datapipes/iter/__init__.py +12 -0
  109. wml/wtorch/data/datapipes/iter/batch.py +126 -0
  110. wml/wtorch/data/datapipes/iter/callable.py +92 -0
  111. wml/wtorch/data/datapipes/iter/listdirfiles.py +37 -0
  112. wml/wtorch/data/datapipes/iter/loadfilesfromdisk.py +30 -0
  113. wml/wtorch/data/datapipes/iter/readfilesfromtar.py +60 -0
  114. wml/wtorch/data/datapipes/iter/readfilesfromzip.py +63 -0
  115. wml/wtorch/data/datapipes/iter/sampler.py +94 -0
  116. wml/wtorch/data/datapipes/utils/__init__.py +0 -0
  117. wml/wtorch/data/datapipes/utils/common.py +65 -0
  118. wml/wtorch/data/dataset.py +354 -0
  119. wml/wtorch/data/datasets/__init__.py +4 -0
  120. wml/wtorch/data/datasets/common.py +53 -0
  121. wml/wtorch/data/datasets/listdirfilesdataset.py +36 -0
  122. wml/wtorch/data/datasets/loadfilesfromdiskdataset.py +30 -0
  123. wml/wtorch/data/distributed.py +135 -0
  124. wml/wtorch/data/multi_processing_data_loader_iter.py +866 -0
  125. wml/wtorch/data/sampler.py +267 -0
  126. wml/wtorch/data/single_process_data_loader_iter.py +24 -0
  127. wml/wtorch/data/test_data_loader.py +26 -0
  128. wml/wtorch/dataset_toolkit.py +67 -0
  129. wml/wtorch/depthwise_separable_conv_module.py +98 -0
  130. wml/wtorch/dist.py +591 -0
  131. wml/wtorch/dropblock/__init__.py +6 -0
  132. wml/wtorch/dropblock/dropblock.py +228 -0
  133. wml/wtorch/dropblock/dropout.py +40 -0
  134. wml/wtorch/dropblock/scheduler.py +48 -0
  135. wml/wtorch/ema.py +61 -0
  136. wml/wtorch/fc_module.py +73 -0
  137. wml/wtorch/functional.py +34 -0
  138. wml/wtorch/iter_dataset.py +26 -0
  139. wml/wtorch/loss.py +69 -0
  140. wml/wtorch/nets/__init__.py +0 -0
  141. wml/wtorch/nets/ckpt_toolkit.py +219 -0
  142. wml/wtorch/nets/fpn.py +276 -0
  143. wml/wtorch/nets/hrnet/__init__.py +0 -0
  144. wml/wtorch/nets/hrnet/config.py +2 -0
  145. wml/wtorch/nets/hrnet/hrnet.py +494 -0
  146. wml/wtorch/nets/misc.py +249 -0
  147. wml/wtorch/nets/resnet/__init__.py +0 -0
  148. wml/wtorch/nets/resnet/layers/__init__.py +17 -0
  149. wml/wtorch/nets/resnet/layers/aspp.py +144 -0
  150. wml/wtorch/nets/resnet/layers/batch_norm.py +231 -0
  151. wml/wtorch/nets/resnet/layers/blocks.py +111 -0
  152. wml/wtorch/nets/resnet/layers/wrappers.py +110 -0
  153. wml/wtorch/nets/resnet/r50_config.py +38 -0
  154. wml/wtorch/nets/resnet/resnet.py +691 -0
  155. wml/wtorch/nets/shape_spec.py +20 -0
  156. wml/wtorch/nets/simple_fpn.py +101 -0
  157. wml/wtorch/nms.py +109 -0
  158. wml/wtorch/nn.py +896 -0
  159. wml/wtorch/ocr_block.py +193 -0
  160. wml/wtorch/summary.py +331 -0
  161. wml/wtorch/train_toolkit.py +603 -0
  162. wml/wtorch/transformer_blocks.py +266 -0
  163. wml/wtorch/utils.py +719 -0
  164. wml/wtorch/wlr_scheduler.py +100 -0
@@ -0,0 +1,183 @@
1
+ import json
2
+ import wml.wml_utils as wmlu
3
+ import numpy as np
4
+ import os
5
+ import cv2 as cv
6
+ import sys
7
+ import random
8
+ from wml.iotoolkit.labelme_toolkit import get_labels_and_bboxes
9
+ from .common import *
10
+
11
+ def read_json(file_path):
12
+ annotations_list = []
13
+ image = {}
14
+ with open(file_path, "r", encoding="gb18030") as f:
15
+ print(file_path)
16
+ data_str = f.read()
17
+ try:
18
+ json_data = json.loads(data_str)
19
+ img_width = int(json_data["imgWidth"])
20
+ img_height = int(json_data["imgHeight"])
21
+ image["height"] = int(img_height)
22
+ image["width"] = int(img_width)
23
+ image["file_name"] = wmlu.base_name(file_path)
24
+ for shape in json_data["objects"]:
25
+ mask = np.zeros(shape=[img_height, img_width], dtype=np.uint8)
26
+ all_points = np.array([shape["polygon"]]).astype(np.int32)
27
+ if len(all_points) < 1:
28
+ continue
29
+ points = np.transpose(all_points[0])
30
+ print(points.shape)
31
+ x, y = np.vsplit(points, 2)
32
+ x = np.reshape(x, [-1])
33
+ y = np.reshape(y, [-1])
34
+ x = np.minimum(np.maximum(0, x), img_width - 1)
35
+ y = np.minimum(np.maximum(0, y), img_height - 1)
36
+ xmin = np.min(x)
37
+ xmax = np.max(x)
38
+ ymin = np.min(y)
39
+ ymax = np.max(y)
40
+ segmentation = cv.drawContours(mask, all_points, -1, color=(1), thickness=cv.FILLED)
41
+ label = shape["label"]
42
+ annotations_list.append({"bbox": (xmin, ymin, xmax - xmin + 1, ymax - ymin + 1),
43
+ "segmentation": segmentation,
44
+ "category_id": label,
45
+ "points_x": x,
46
+ "points_y": y})
47
+ except:
48
+ print(f"Read file {os.path.basename(file_path)} faild.")
49
+ pass
50
+
51
+ if len(annotations_list) > 2:
52
+ mask = 1 - annotations_list[-1]['segmentation']
53
+ for i in reversed(range(len(annotations_list) - 1)):
54
+ annotations_list[i]['segmentation'] = np.logical_and(annotations_list[i]['segmentation'], mask)
55
+ mask = np.logical_and(mask, 1 - annotations_list[i]['segmentation'])
56
+
57
+ return image, annotations_list
58
+
59
+ def get_files(dir_path, sub_dir_name):
60
+ img_dir = os.path.join(dir_path, 'leftImg8bit', sub_dir_name)
61
+ label_dir = os.path.join(dir_path, 'gtFine', sub_dir_name)
62
+ dir_names = wmlu.get_subdir_in_dir(label_dir)
63
+ res = []
64
+ for dir_name in dir_names:
65
+ l_label_dir = os.path.join(label_dir, dir_name)
66
+ l_img_dir = os.path.join(img_dir, dir_name)
67
+ json_files = wmlu.recurse_get_filepath_in_dir(l_label_dir,suffix=".json")
68
+ for jf in json_files:
69
+ base_name = wmlu.base_name(jf)[:-15]+"leftImg8bit"
70
+ igf = os.path.join(l_img_dir, base_name + ".png")
71
+ if os.path.exists(igf):
72
+ res.append((igf, jf))
73
+ else:
74
+ print(f"ERROR: Find {igf} faild, json file is {jf}")
75
+
76
+ return res
77
+
78
+ class CityscapesData(object):
79
+ def __init__(self, label_text2id=None, shuffle=False, sub_dir_name="train"):
80
+ self.files = None
81
+ self.label_text2id = label_text2id
82
+ self.shuffle = shuffle
83
+ self.sub_dir_name = sub_dir_name
84
+
85
+ def read_data(self, dir_path):
86
+ self.files = get_files(dir_path, self.sub_dir_name)
87
+ if self.shuffle:
88
+ random.shuffle(self.files)
89
+
90
+ def get_items(self):
91
+ '''
92
+ :return:
93
+ full_path,img_size,category_ids,category_names,boxes,binary_masks,area,is_crowd,num_annotations_skipped
94
+ '''
95
+ for i, (img_file, json_file) in enumerate(self.files):
96
+ print(img_file,json_file)
97
+ sys.stdout.write('\r>> read data %d/%d' % (i + 1, len(self.files)))
98
+ sys.stdout.flush()
99
+ image, annotations_list = read_json(json_file)
100
+ labels_names, bboxes = get_labels_and_bboxes(image, annotations_list)
101
+ masks = [ann["segmentation"] for ann in annotations_list]
102
+ if len(masks) > 0:
103
+ try:
104
+ masks = np.stack(masks, axis=0)
105
+ except:
106
+ print("ERROR: stack masks faild.")
107
+ masks = None
108
+
109
+ if self.label_text2id is not None:
110
+ labels = [self.label_text2id(x) for x in labels_names]
111
+ else:
112
+ labels = None
113
+
114
+ yield DetData(img_file, [image['height'], image['width']], labels, labels_names, bboxes, masks, None, None, None)
115
+
116
+ def get_boxes_items(self):
117
+ '''
118
+ :return:
119
+ full_path,img_size,category_ids,boxes,is_crowd
120
+ '''
121
+ for i, (img_file, json_file) in enumerate(self.files):
122
+ sys.stdout.write('\r>> read data %d/%d' % (i + 1, len(self.files)))
123
+ sys.stdout.flush()
124
+ image, annotations_list = read_json(json_file)
125
+ labels_names, bboxes = get_labels_and_bboxes(image, annotations_list)
126
+ labels = [self.label_text2id(x) for x in labels_names]
127
+ yield DetBboxesData(img_file, [image['height'], image['width']], labels,bboxes, None)
128
+
129
+ if __name__ == "__main__":
130
+ # data_statistics("/home/vghost/ai/mldata/qualitycontrol/rdatasv3")
131
+ import wml.img_utils as wmli
132
+ import object_detection_tools.visualization as odv
133
+ import matplotlib.pyplot as plt
134
+
135
+ NAME2ID = {}
136
+ ID2NAME = {}
137
+ id = 0
138
+
139
+ def name_to_id(x):
140
+ global id
141
+ if x in NAME2ID:
142
+ return NAME2ID[x]
143
+ else:
144
+ NAME2ID[x] = id
145
+ ID2NAME[id] = x
146
+ id += 1
147
+ return NAME2ID[x]
148
+
149
+
150
+ data = CityscapesData(label_text2id=name_to_id, shuffle=False)
151
+ # data.read_data("/data/mldata/qualitycontrol/rdatasv5_splited/rdatasv5")
152
+ # data.read_data("/home/vghost/ai/mldata2/qualitycontrol/rdatav10_preproc")
153
+ # data.read_data("/home/vghost/ai/mldata2/qualitycontrol/rdatasv10_neg_preproc")
154
+ data.read_data(wmlu.home_dir("ai/mldata/cityscapes"))
155
+ def filter(x):
156
+ return x in ['road','parking']
157
+ #return x in ['person', 'parking']
158
+ #return x in ['terrain']
159
+ #return x in ['car']
160
+ # data.read_data("/home/vghost/ai/mldata2/qualitycontrol/x")
161
+ for x in data.get_items():
162
+ full_path, img_info, category_ids, category_names, boxes, binary_mask, area, is_crowd, num_annotations_skipped = x
163
+ img = wmli.imread(full_path)
164
+
165
+ def text_fn(classes, scores):
166
+ return f"{ID2NAME[classes]}"
167
+
168
+ is_keep = [filter(x) for x in category_names]
169
+ category_ids = np.array(category_ids)[is_keep]
170
+ boxes = np.array(boxes)[is_keep]
171
+ binary_mask = np.array(binary_mask)[is_keep]
172
+ if len(category_ids)==0:
173
+ continue
174
+
175
+ wmlu.show_dict(NAME2ID)
176
+ odv.draw_bboxes_and_maskv2(
177
+ img=img, classes=category_ids, scores=None, bboxes=boxes, masks=binary_mask, color_fn=None,
178
+ text_fn=text_fn, thickness=4,
179
+ show_text=True,
180
+ fontScale=0.8)
181
+ plt.figure()
182
+ plt.imshow(img)
183
+ plt.show()
@@ -0,0 +1,25 @@
1
+ import wml.wml_utils as wmlu
2
+
3
+ def labels_statistics(labels,name="",classes_names=None):
4
+ counter = wmlu.Counter()
5
+ for l in labels:
6
+ if isinstance(l,(list,tuple)):
7
+ l = l[0]
8
+ counter.add(l)
9
+
10
+
11
+ counter = list(counter.items())
12
+ counter.sort(key=lambda x:x[1],reverse=True)
13
+ classes = []
14
+ for l,v in counter:
15
+ classes.append(l)
16
+ print(f"Total {len(classes)} classes")
17
+ print(list(classes))
18
+ if len(name)>0:
19
+ print(name)
20
+ for l,v in counter:
21
+ if classes_names is not None:
22
+ l = classes_names[l]
23
+ print(f"{l:>32}: {v:<8}, {v*100.0/len(labels):>3.2f}%")
24
+
25
+ print(f"Total {len(labels)} samples.")
@@ -0,0 +1,225 @@
1
+ import numpy as np
2
+
3
+ COCO_KP_NR = 17
4
+ ID_TO_COMPRESSED_ID = {} #第一个类别的编号为1
5
+ ZERO_ID_TO_COMPRESSED_ID = {} #第一个类别的编号为0
6
+ COMPRESSED_ID_TO_ID = {} #第一个类别的编号为1
7
+ ZERO_COMPRESSED_ID_TO_ID = {} #第一个类别的编号为0
8
+
9
+ ID_TO_TEXT={1: {u'supercategory': u'person', u'id': 1, u'name': u'person'},
10
+ 2: {u'supercategory': u'vehicle', u'id': 2, u'name': u'bicycle'},
11
+ 3: {u'supercategory': u'vehicle', u'id': 3, u'name': u'car'},
12
+ 4: {u'supercategory': u'vehicle', u'id': 4, u'name': u'motorcycle'},
13
+ 5: {u'supercategory': u'vehicle', u'id': 5, u'name': u'airplane'},
14
+ 6: {u'supercategory': u'vehicle', u'id': 6, u'name': u'bus'},
15
+ 7: {u'supercategory': u'vehicle', u'id': 7, u'name': u'train'},
16
+ 8: {u'supercategory': u'vehicle', u'id': 8, u'name': u'truck'},
17
+ 9: {u'supercategory': u'vehicle', u'id': 9, u'name': u'boat'},
18
+ 10: {u'supercategory': u'outdoor', u'id': 10, u'name': u'traffic light'},
19
+ 11: {u'supercategory': u'outdoor', u'id': 11, u'name': u'fire hydrant'},
20
+ 13: {u'supercategory': u'outdoor', u'id': 13, u'name': u'stop sign'},
21
+ 14: {u'supercategory': u'outdoor', u'id': 14, u'name': u'parking meter'},
22
+ 15: {u'supercategory': u'outdoor', u'id': 15, u'name': u'bench'},
23
+ 16: {u'supercategory': u'animal', u'id': 16, u'name': u'bird'},
24
+ 17: {u'supercategory': u'animal', u'id': 17, u'name': u'cat'},
25
+ 18: {u'supercategory': u'animal', u'id': 18, u'name': u'dog'},
26
+ 19: {u'supercategory': u'animal', u'id': 19, u'name': u'horse'},
27
+ 20: {u'supercategory': u'animal', u'id': 20, u'name': u'sheep'},
28
+ 21: {u'supercategory': u'animal', u'id': 21, u'name': u'cow'},
29
+ 22: {u'supercategory': u'animal', u'id': 22, u'name': u'elephant'},
30
+ 23: {u'supercategory': u'animal', u'id': 23, u'name': u'bear'},
31
+ 24: {u'supercategory': u'animal', u'id': 24, u'name': u'zebra'},
32
+ 25: {u'supercategory': u'animal', u'id': 25, u'name': u'giraffe'},
33
+ 27: {u'supercategory': u'accessory', u'id': 27, u'name': u'backpack'},
34
+ 28: {u'supercategory': u'accessory', u'id': 28, u'name': u'umbrella'},
35
+ 31: {u'supercategory': u'accessory', u'id': 31, u'name': u'handbag'},
36
+ 32: {u'supercategory': u'accessory', u'id': 32, u'name': u'tie'},
37
+ 33: {u'supercategory': u'accessory', u'id': 33, u'name': u'suitcase'},
38
+ 34: {u'supercategory': u'sports', u'id': 34, u'name': u'frisbee'},
39
+ 35: {u'supercategory': u'sports', u'id': 35, u'name': u'skis'},
40
+ 36: {u'supercategory': u'sports', u'id': 36, u'name': u'snowboard'},
41
+ 37: {u'supercategory': u'sports', u'id': 37, u'name': u'sports ball'},
42
+ 38: {u'supercategory': u'sports', u'id': 38, u'name': u'kite'},
43
+ 39: {u'supercategory': u'sports', u'id': 39, u'name': u'baseball bat'},
44
+ 40: {u'supercategory': u'sports', u'id': 40, u'name': u'baseball glove'},
45
+ 41: {u'supercategory': u'sports', u'id': 41, u'name': u'skateboard'},
46
+ 42: {u'supercategory': u'sports', u'id': 42, u'name': u'surfboard'},
47
+ 43: {u'supercategory': u'sports', u'id': 43, u'name': u'tennis racket'},
48
+ 44: {u'supercategory': u'kitchen', u'id': 44, u'name': u'bottle'},
49
+ 46: {u'supercategory': u'kitchen', u'id': 46, u'name': u'wine glass'},
50
+ 47: {u'supercategory': u'kitchen', u'id': 47, u'name': u'cup'},
51
+ 48: {u'supercategory': u'kitchen', u'id': 48, u'name': u'fork'},
52
+ 49: {u'supercategory': u'kitchen', u'id': 49, u'name': u'knife'},
53
+ 50: {u'supercategory': u'kitchen', u'id': 50, u'name': u'spoon'},
54
+ 51: {u'supercategory': u'kitchen', u'id': 51, u'name': u'bowl'},
55
+ 52: {u'supercategory': u'food', u'id': 52, u'name': u'banana'},
56
+ 53: {u'supercategory': u'food', u'id': 53, u'name': u'apple'},
57
+ 54: {u'supercategory': u'food', u'id': 54, u'name': u'sandwich'},
58
+ 55: {u'supercategory': u'food', u'id': 55, u'name': u'orange'},
59
+ 56: {u'supercategory': u'food', u'id': 56, u'name': u'broccoli'},
60
+ 57: {u'supercategory': u'food', u'id': 57, u'name': u'carrot'},
61
+ 58: {u'supercategory': u'food', u'id': 58, u'name': u'hot dog'},
62
+ 59: {u'supercategory': u'food', u'id': 59, u'name': u'pizza'},
63
+ 60: {u'supercategory': u'food', u'id': 60, u'name': u'donut'},
64
+ 61: {u'supercategory': u'food', u'id': 61, u'name': u'cake'},
65
+ 62: {u'supercategory': u'furniture', u'id': 62, u'name': u'chair'},
66
+ 63: {u'supercategory': u'furniture', u'id': 63, u'name': u'couch'},
67
+ 64: {u'supercategory': u'furniture', u'id': 64, u'name': u'potted plant'},
68
+ 65: {u'supercategory': u'furniture', u'id': 65, u'name': u'bed'},
69
+ 67: {u'supercategory': u'furniture', u'id': 67, u'name': u'dining table'},
70
+ 70: {u'supercategory': u'furniture', u'id': 70, u'name': u'toilet'},
71
+ 72: {u'supercategory': u'electronic', u'id': 72, u'name': u'tv'},
72
+ 73: {u'supercategory': u'electronic', u'id': 73, u'name': u'laptop'},
73
+ 74: {u'supercategory': u'electronic', u'id': 74, u'name': u'mouse'},
74
+ 75: {u'supercategory': u'electronic', u'id': 75, u'name': u'remote'},
75
+ 76: {u'supercategory': u'electronic', u'id': 76, u'name': u'keyboard'},
76
+ 77: {u'supercategory': u'electronic', u'id': 77, u'name': u'cell phone'},
77
+ 78: {u'supercategory': u'appliance', u'id': 78, u'name': u'microwave'},
78
+ 79: {u'supercategory': u'appliance', u'id': 79, u'name': u'oven'},
79
+ 80: {u'supercategory': u'appliance', u'id': 80, u'name': u'toaster'},
80
+ 81: {u'supercategory': u'appliance', u'id': 81, u'name': u'sink'},
81
+ 82: {u'supercategory': u'appliance', u'id': 82, u'name': u'refrigerator'},
82
+ 84: {u'supercategory': u'indoor', u'id': 84, u'name': u'book'},
83
+ 85: {u'supercategory': u'indoor', u'id': 85, u'name': u'clock'},
84
+ 86: {u'supercategory': u'indoor', u'id': 86, u'name': u'vase'},
85
+ 87: {u'supercategory': u'indoor', u'id': 87, u'name': u'scissors'},
86
+ 88: {u'supercategory': u'indoor', u'id': 88, u'name': u'teddy bear'},
87
+ 89: {u'supercategory': u'indoor', u'id': 89, u'name': u'hair drier'},
88
+ 90: {u'supercategory': u'indoor', u'id': 90, u'name': u'toothbrush'}}
89
+ COMPRESSED_ID_TO_TEXT = {}
90
+
91
+
92
+
93
+ KEYPOINTS_NAME = ["nose", #0
94
+ "left_eye", #1
95
+ "right_eye",#2
96
+ "left_ear",#3
97
+ "right_ear",#4
98
+ "left_shoulder",#5
99
+ "right_shoulder",#6
100
+ "left_elbow",#7
101
+ "right_elbow",#8
102
+ "left_wrist",#9
103
+ "right_wrist",#10
104
+ "left_hip",#11
105
+ "right_hip",#12
106
+ "left_knee",#13
107
+ "right_knee",#14
108
+ "left_ankle",#15
109
+ "right_ankle"]#16
110
+ JOINTS_PAIR = [[0 , 1], [1 , 2], [2 , 0], [1 , 3], [2 , 4], [3 , 5], [4 , 6], [5 , 6], [5 , 11],
111
+ [6 , 12], [11 , 12], [5 , 7], [7 , 9], [6 , 8], [8 , 10], [11 , 13], [13 , 15], [12 , 14], [14 , 16]]
112
+ j = 1
113
+ for i in range(1,81):
114
+ while j not in ID_TO_TEXT:
115
+ j += 1
116
+ ID_TO_COMPRESSED_ID[j] = i
117
+ ZERO_ID_TO_COMPRESSED_ID[j] = i-1
118
+ COMPRESSED_ID_TO_ID[i] = j
119
+ ZERO_COMPRESSED_ID_TO_ID[i-1] = j
120
+ j += 1
121
+
122
+ for k,v in COMPRESSED_ID_TO_ID.items():
123
+ COMPRESSED_ID_TO_TEXT[k] = ID_TO_TEXT[v]['name']
124
+
125
+ COCO_CLASSES_FREQ = {
126
+ "person": 30.52,
127
+ "car": 5.10,
128
+ "chair": 4.48,
129
+ "book": 2.87,
130
+ "bottle": 2.83,
131
+ "cup": 2.40,
132
+ "dining table": 1.83,
133
+ "bowl": 1.67,
134
+ "traffic light": 1.50,
135
+ "handbag": 1.44,
136
+ "umbrella": 1.33,
137
+ "bird": 1.26,
138
+ "boat": 1.25,
139
+ "truck": 1.16,
140
+ "bench": 1.14,
141
+ "sheep": 1.11,
142
+ "banana": 1.10,
143
+ "kite": 1.06,
144
+ "motorcycle": 1.01,
145
+ "backpack": 1.01,
146
+ "potted plant": 1.01,
147
+ "cow": 0.95,
148
+ "wine glass": 0.92,
149
+ "carrot": 0.91,
150
+ "knife": 0.90,
151
+ "broccoli": 0.85,
152
+ "donut": 0.83,
153
+ "bicycle": 0.83,
154
+ "skis": 0.77,
155
+ "vase": 0.77,
156
+ "horse": 0.77,
157
+ "tie": 0.76,
158
+ "cell phone": 0.75,
159
+ "orange": 0.74,
160
+ "cake": 0.74,
161
+ "sports ball": 0.74,
162
+ "clock": 0.74,
163
+ "suitcase": 0.72,
164
+ "spoon": 0.72,
165
+ "surfboard": 0.71,
166
+ "bus": 0.71,
167
+ "apple": 0.68,
168
+ "pizza": 0.68,
169
+ "tv": 0.68,
170
+ "couch": 0.67,
171
+ "remote": 0.66,
172
+ "sink": 0.65,
173
+ "skateboard": 0.64,
174
+ "elephant": 0.64,
175
+ "dog": 0.64,
176
+ "fork": 0.64,
177
+ "zebra": 0.62,
178
+ "airplane": 0.60,
179
+ "giraffe": 0.60,
180
+ "laptop": 0.58,
181
+ "tennis racket": 0.56,
182
+ "teddy bear": 0.56,
183
+ "cat": 0.55,
184
+ "train": 0.53,
185
+ "sandwich": 0.51,
186
+ "bed": 0.49,
187
+ "toilet": 0.48,
188
+ "baseball glove": 0.44,
189
+ "oven": 0.39,
190
+ "baseball bat": 0.38,
191
+ "hot dog": 0.34,
192
+ "keyboard": 0.33,
193
+ "snowboard": 0.31,
194
+ "frisbee": 0.31,
195
+ "refrigerator": 0.31,
196
+ "mouse": 0.26,
197
+ "stop sign": 0.23,
198
+ "toothbrush": 0.23,
199
+ "fire hydrant": 0.22,
200
+ "microwave": 0.19,
201
+ "scissors": 0.17,
202
+ "bear": 0.15,
203
+ "parking meter": 0.15,
204
+ "toaster": 0.03,
205
+ "hair drier": 0.02
206
+ }
207
+ ID_TO_FREQ = np.ones(shape=[91],dtype=np.float32)
208
+ for i in range(1,91):
209
+ if i in ID_TO_TEXT:
210
+ name = ID_TO_TEXT[i]['name']
211
+ if name not in COCO_CLASSES_FREQ:
212
+ print(f"Error {i}/{name}")
213
+ raise ValueError(name)
214
+ else:
215
+ ID_TO_FREQ[i] = COCO_CLASSES_FREQ[name]
216
+ COMPRESSED_ID_TO_FREQ = np.ones(shape=[81],dtype=np.float32)
217
+ for i in range(1,81):
218
+ id = COMPRESSED_ID_TO_ID[i]
219
+ COMPRESSED_ID_TO_FREQ[i] = ID_TO_FREQ[id]
220
+
221
+ '''
222
+ APsmall% AP for small objects: area < 32^2
223
+ APmedium% AP for medium objects: 32^2 < area < 96^2
224
+ APlarge% AP for large objects: area > 96^2
225
+ '''
@@ -0,0 +1,118 @@
1
+ from pycocotools.coco import COCO
2
+ import numpy as np
3
+ import copy
4
+
5
+ class COCOKeypoints(object):
6
+ def __init__(self):
7
+ self.pixel_std = 200
8
+ self.num_joints = 17
9
+ pass
10
+
11
+ def read_data(self,file_path):
12
+ self.coco = COCO(file_path)
13
+ self.image_set_index = self.coco.getImgIds()
14
+ self.gt_db = self._load_coco_keypoint_annotations()
15
+ return self.gt_db
16
+
17
+ def image_path_from_index(self, index):
18
+ file_name = '%012d.jpg' % index
19
+ return file_name
20
+
21
+ def _load_coco_keypoint_annotations(self):
22
+ """ ground truth bbox and keypoints """
23
+ gt_db = []
24
+ for index in self.image_set_index:
25
+ gt_db.extend(self._load_coco_keypoint_annotation_kernal(index))
26
+ return gt_db
27
+
28
+
29
+ def _load_coco_keypoint_annotation_kernal(self, index):
30
+ """
31
+ coco ann: [u'segmentation', u'area', u'iscrowd', u'image_id', u'bbox', u'category_id', u'id']
32
+ iscrowd:
33
+ crowd instances are handled by marking their overlaps with all categories to -1
34
+ and later excluded in training
35
+ bbox:
36
+ [x1, y1, w, h]
37
+ :param index: coco image id
38
+ :return: db entry
39
+ """
40
+ im_ann = self.coco.loadImgs(index)[0]
41
+ width = im_ann['width']
42
+ height = im_ann['height']
43
+
44
+ annIds = self.coco.getAnnIds(imgIds=index, iscrowd=False)
45
+ objs = self.coco.loadAnns(annIds)
46
+
47
+ # sanitize bboxes
48
+ valid_objs = []
49
+ for obj in objs:
50
+ x, y, w, h = obj['bbox']
51
+ x1 = np.max((0, x))
52
+ y1 = np.max((0, y))
53
+ x2 = np.min((width - 1, x1 + np.max((0, w - 1))))
54
+ y2 = np.min((height - 1, y1 + np.max((0, h - 1))))
55
+ if obj['area'] > 0 and x2 >= x1 and y2 >= y1:
56
+ obj['clean_bbox'] = [x1, y1, x2 - x1, y2 - y1]
57
+ valid_objs.append(obj)
58
+ objs = valid_objs
59
+
60
+ rec = []
61
+ for obj in objs:
62
+ '''cls = self._coco_ind_to_class_ind[obj['category_id']]
63
+ if cls != 1:
64
+ continue'''
65
+ # ignore objs without keypoints annotation
66
+ if max(obj['keypoints']) == 0:
67
+ continue
68
+
69
+ joints_3d = np.zeros((self.num_joints, 3), dtype=np.float32)
70
+ joints_3d_vis = np.zeros((self.num_joints, 3), dtype=np.float32)
71
+ for ipt in range(self.num_joints):
72
+ joints_3d[ipt, 0] = obj['keypoints'][ipt * 3 + 0]
73
+ joints_3d[ipt, 1] = obj['keypoints'][ipt * 3 + 1]
74
+ t_vis = obj['keypoints'][ipt * 3 + 2]
75
+ if t_vis > 1:
76
+ t_vis = 1
77
+ joints_3d[ipt, 2] = t_vis
78
+ joints_3d_vis[ipt, 0] = t_vis
79
+ joints_3d_vis[ipt, 1] = t_vis
80
+ joints_3d_vis[ipt, 2] = 0
81
+
82
+ clean_bbox = copy.deepcopy(obj['clean_bbox'])
83
+ center, scale = self._box2cs(clean_bbox[:4])
84
+ rec.append({
85
+ 'image_id':index,
86
+ 'image': self.image_path_from_index(index),
87
+ 'center': center,
88
+ 'scale': scale,
89
+ 'clean_bbox':clean_bbox,
90
+ 'keypoints': joints_3d,
91
+ 'joints_3d_vis': joints_3d_vis,
92
+ 'filename': '',
93
+ 'imgnum': 0,
94
+ })
95
+
96
+ return rec
97
+
98
+
99
+ def _box2cs(self, box):
100
+ x, y, w, h = box[:4]
101
+ return self._xywh2cs(x, y, w, h)
102
+
103
+ def _xywh2cs(self, x, y, w, h):
104
+ center = np.zeros((2), dtype=np.float32)
105
+ center[0] = x + w * 0.5
106
+ center[1] = y + h * 0.5
107
+
108
+ '''if w > self.aspect_ratio * h:
109
+ h = w * 1.0 / self.aspect_ratio
110
+ elif w < self.aspect_ratio * h:
111
+ w = h * self.aspect_ratio'''
112
+ scale = np.array(
113
+ [w * 1.0 / self.pixel_std, h * 1.0 / self.pixel_std],
114
+ dtype=np.float32)
115
+ if center[0] != -1:
116
+ scale = scale * 1.25
117
+
118
+ return center, scale
@@ -0,0 +1,103 @@
1
+ from pycocotools.coco import COCO
2
+ import numpy as np
3
+ import copy
4
+
5
+ '''
6
+ 返回image层面的结果
7
+ '''
8
+ class COCOKeypointsFmt2(object):
9
+ def __init__(self):
10
+ self.pixel_std = 200
11
+ self.num_joints = 17
12
+ pass
13
+
14
+ def read_data(self,file_path):
15
+ self.coco = COCO(file_path)
16
+ self.image_set_index = self.coco.getImgIds()
17
+ self.gt_db = self._load_coco_keypoint_annotations()
18
+ return self.gt_db
19
+
20
+ def image_path_from_index(self, index):
21
+ file_name = '%012d.jpg' % index
22
+ return file_name
23
+
24
+ def _load_coco_keypoint_annotations(self):
25
+ """ ground truth bbox and keypoints """
26
+ gt_db = []
27
+ for index in self.image_set_index:
28
+ res = self._load_coco_keypoint_annotation_kernal(index)
29
+ if res is not None:
30
+ gt_db.append(res)
31
+ return gt_db
32
+
33
+
34
+ def _load_coco_keypoint_annotation_kernal(self, index):
35
+ """
36
+ coco ann: [u'segmentation', u'area', u'iscrowd', u'image_id', u'bbox', u'category_id', u'id']
37
+ iscrowd:
38
+ crowd instances are handled by marking their overlaps with all categories to -1
39
+ and later excluded in training
40
+ bbox:
41
+ [x1, y1, w, h]
42
+ :param index: coco image id
43
+ :return: db entry
44
+ """
45
+ im_ann = self.coco.loadImgs(index)[0]
46
+ width = im_ann['width']
47
+ height = im_ann['height']
48
+
49
+ annIds = self.coco.getAnnIds(imgIds=index, iscrowd=False)
50
+ objs = self.coco.loadAnns(annIds)
51
+
52
+ # sanitize bboxes
53
+ valid_objs = []
54
+ for obj in objs:
55
+ x, y, w, h = obj['bbox']
56
+ x1 = np.max((0, x))
57
+ y1 = np.max((0, y))
58
+ x2 = np.min((width - 1, x1 + np.max((0, w - 1))))
59
+ y2 = np.min((height - 1, y1 + np.max((0, h - 1))))
60
+ if obj['area'] > 0 and x2 >= x1 and y2 >= y1:
61
+ obj['clean_bbox'] = [x1, y1, x2 - x1, y2 - y1]
62
+ valid_objs.append(obj)
63
+ objs = valid_objs
64
+
65
+ if len(objs) == 0:
66
+ return None
67
+
68
+ res = {}
69
+ res['image'] = self.image_path_from_index(index)
70
+ all_kps = []
71
+ all_bboxes = []
72
+ all_areas = []
73
+ all_iscrowd = []
74
+ for obj in objs:
75
+ '''cls = self._coco_ind_to_class_ind[obj['category_id']]
76
+ if cls != 1:
77
+ continue'''
78
+ # ignore objs without keypoints annotation
79
+ if max(obj['keypoints']) == 0:
80
+ continue
81
+
82
+ joints_3d = np.zeros((self.num_joints, 3), dtype=np.float32)
83
+ for ipt in range(self.num_joints):
84
+ joints_3d[ipt, 0] = obj['keypoints'][ipt * 3 + 0]
85
+ joints_3d[ipt, 1] = obj['keypoints'][ipt * 3 + 1]
86
+ t_vis = obj['keypoints'][ipt * 3 + 2]
87
+ if t_vis > 1:
88
+ t_vis = 1
89
+ joints_3d[ipt, 2] = t_vis
90
+
91
+ clean_bbox = np.array(obj['clean_bbox'])
92
+ bbox = clean_bbox
93
+ bbox[2:] = bbox[:2]+bbox[2:]
94
+ all_kps.append(joints_3d)
95
+ all_bboxes.append(bbox)
96
+ all_areas.append(obj['area'])
97
+ all_iscrowd.append(obj['iscrowd'])
98
+
99
+ res["keypoints"] = np.array(all_kps,dtype=np.float32)
100
+ res['bboxes'] = np.array(all_bboxes,dtype=np.float32)
101
+ res['area'] = np.array(all_areas,dtype=np.float32)
102
+ res['iscrowd'] = np.array(all_iscrowd,dtype=np.float32)
103
+ return res