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.
- python_wml-3.0.0.dist-info/LICENSE +23 -0
- python_wml-3.0.0.dist-info/METADATA +51 -0
- python_wml-3.0.0.dist-info/RECORD +164 -0
- python_wml-3.0.0.dist-info/WHEEL +5 -0
- python_wml-3.0.0.dist-info/top_level.txt +1 -0
- wml/__init__.py +0 -0
- wml/basic_data_def/__init__.py +2 -0
- wml/basic_data_def/detection_data_def.py +279 -0
- wml/basic_data_def/io_data_def.py +2 -0
- wml/basic_img_utils.py +816 -0
- wml/img_patch.py +92 -0
- wml/img_utils.py +571 -0
- wml/iotoolkit/__init__.py +17 -0
- wml/iotoolkit/aic_keypoint.py +115 -0
- wml/iotoolkit/baidu_mask_toolkit.py +244 -0
- wml/iotoolkit/base_dataset.py +210 -0
- wml/iotoolkit/bboxes_statistics.py +515 -0
- wml/iotoolkit/build.py +0 -0
- wml/iotoolkit/cityscapes_toolkit.py +183 -0
- wml/iotoolkit/classification_data_statistics.py +25 -0
- wml/iotoolkit/coco_data_fwd.py +225 -0
- wml/iotoolkit/coco_keypoints.py +118 -0
- wml/iotoolkit/coco_keypoints_fmt2.py +103 -0
- wml/iotoolkit/coco_toolkit.py +397 -0
- wml/iotoolkit/coco_wholebody.py +269 -0
- wml/iotoolkit/common.py +108 -0
- wml/iotoolkit/crowd_pose.py +146 -0
- wml/iotoolkit/fast_labelme.py +110 -0
- wml/iotoolkit/image_folder.py +95 -0
- wml/iotoolkit/imgs_cache.py +58 -0
- wml/iotoolkit/imgs_reader_mt.py +73 -0
- wml/iotoolkit/labelme_base.py +102 -0
- wml/iotoolkit/labelme_json_to_img.py +49 -0
- wml/iotoolkit/labelme_toolkit.py +117 -0
- wml/iotoolkit/labelme_toolkit_fwd.py +733 -0
- wml/iotoolkit/labelmemckeypoints_dataset.py +169 -0
- wml/iotoolkit/lspet.py +48 -0
- wml/iotoolkit/mapillary_vistas_toolkit.py +269 -0
- wml/iotoolkit/mat_data.py +90 -0
- wml/iotoolkit/mckeypoints_statistics.py +28 -0
- wml/iotoolkit/mot_datasets.py +62 -0
- wml/iotoolkit/mpii.py +108 -0
- wml/iotoolkit/npmckeypoints_dataset.py +164 -0
- wml/iotoolkit/o365_to_coco.py +136 -0
- wml/iotoolkit/object365_toolkit.py +156 -0
- wml/iotoolkit/object365v2_toolkit.py +71 -0
- wml/iotoolkit/pascal_voc_data.py +51 -0
- wml/iotoolkit/pascal_voc_toolkit.py +194 -0
- wml/iotoolkit/pascal_voc_toolkit_fwd.py +473 -0
- wml/iotoolkit/penn_action.py +57 -0
- wml/iotoolkit/rawframe_dataset.py +129 -0
- wml/iotoolkit/rewrite_pascal_voc.py +28 -0
- wml/iotoolkit/semantic_data.py +49 -0
- wml/iotoolkit/split_file_by_type.py +29 -0
- wml/iotoolkit/sports_mot_datasets.py +78 -0
- wml/iotoolkit/vis_objectdetection_dataset.py +70 -0
- wml/iotoolkit/vis_torch_data.py +39 -0
- wml/iotoolkit/yolo_toolkit.py +38 -0
- wml/object_detection2/__init__.py +4 -0
- wml/object_detection2/basic_visualization.py +37 -0
- wml/object_detection2/bboxes.py +812 -0
- wml/object_detection2/data_process_toolkit.py +146 -0
- wml/object_detection2/keypoints.py +292 -0
- wml/object_detection2/mask.py +120 -0
- wml/object_detection2/metrics/__init__.py +3 -0
- wml/object_detection2/metrics/build.py +15 -0
- wml/object_detection2/metrics/classifier_toolkit.py +440 -0
- wml/object_detection2/metrics/common.py +71 -0
- wml/object_detection2/metrics/mckps_toolkit.py +338 -0
- wml/object_detection2/metrics/toolkit.py +1953 -0
- wml/object_detection2/npod_toolkit.py +361 -0
- wml/object_detection2/odtools.py +243 -0
- wml/object_detection2/standard_names.py +75 -0
- wml/object_detection2/visualization.py +956 -0
- wml/object_detection2/wmath.py +34 -0
- wml/semantic/__init__.py +0 -0
- wml/semantic/basic_toolkit.py +65 -0
- wml/semantic/mask_utils.py +156 -0
- wml/semantic/semantic_test.py +21 -0
- wml/semantic/structures.py +1 -0
- wml/semantic/toolkit.py +105 -0
- wml/semantic/visualization_utils.py +658 -0
- wml/threadtoolkit.py +50 -0
- wml/walgorithm.py +228 -0
- wml/wcollections.py +212 -0
- wml/wfilesystem.py +487 -0
- wml/wml_utils.py +657 -0
- wml/wstructures/__init__.py +4 -0
- wml/wstructures/common.py +9 -0
- wml/wstructures/keypoints_train_toolkit.py +149 -0
- wml/wstructures/kps_structures.py +579 -0
- wml/wstructures/mask_structures.py +1161 -0
- wml/wtorch/__init__.py +8 -0
- wml/wtorch/bboxes.py +104 -0
- wml/wtorch/classes_suppression.py +24 -0
- wml/wtorch/conv_module.py +181 -0
- wml/wtorch/conv_ws.py +144 -0
- wml/wtorch/data/__init__.py +16 -0
- wml/wtorch/data/_utils/__init__.py +45 -0
- wml/wtorch/data/_utils/collate.py +183 -0
- wml/wtorch/data/_utils/fetch.py +47 -0
- wml/wtorch/data/_utils/pin_memory.py +121 -0
- wml/wtorch/data/_utils/signal_handling.py +72 -0
- wml/wtorch/data/_utils/worker.py +227 -0
- wml/wtorch/data/base_data_loader_iter.py +93 -0
- wml/wtorch/data/dataloader.py +501 -0
- wml/wtorch/data/datapipes/__init__.py +1 -0
- wml/wtorch/data/datapipes/iter/__init__.py +12 -0
- wml/wtorch/data/datapipes/iter/batch.py +126 -0
- wml/wtorch/data/datapipes/iter/callable.py +92 -0
- wml/wtorch/data/datapipes/iter/listdirfiles.py +37 -0
- wml/wtorch/data/datapipes/iter/loadfilesfromdisk.py +30 -0
- wml/wtorch/data/datapipes/iter/readfilesfromtar.py +60 -0
- wml/wtorch/data/datapipes/iter/readfilesfromzip.py +63 -0
- wml/wtorch/data/datapipes/iter/sampler.py +94 -0
- wml/wtorch/data/datapipes/utils/__init__.py +0 -0
- wml/wtorch/data/datapipes/utils/common.py +65 -0
- wml/wtorch/data/dataset.py +354 -0
- wml/wtorch/data/datasets/__init__.py +4 -0
- wml/wtorch/data/datasets/common.py +53 -0
- wml/wtorch/data/datasets/listdirfilesdataset.py +36 -0
- wml/wtorch/data/datasets/loadfilesfromdiskdataset.py +30 -0
- wml/wtorch/data/distributed.py +135 -0
- wml/wtorch/data/multi_processing_data_loader_iter.py +866 -0
- wml/wtorch/data/sampler.py +267 -0
- wml/wtorch/data/single_process_data_loader_iter.py +24 -0
- wml/wtorch/data/test_data_loader.py +26 -0
- wml/wtorch/dataset_toolkit.py +67 -0
- wml/wtorch/depthwise_separable_conv_module.py +98 -0
- wml/wtorch/dist.py +591 -0
- wml/wtorch/dropblock/__init__.py +6 -0
- wml/wtorch/dropblock/dropblock.py +228 -0
- wml/wtorch/dropblock/dropout.py +40 -0
- wml/wtorch/dropblock/scheduler.py +48 -0
- wml/wtorch/ema.py +61 -0
- wml/wtorch/fc_module.py +73 -0
- wml/wtorch/functional.py +34 -0
- wml/wtorch/iter_dataset.py +26 -0
- wml/wtorch/loss.py +69 -0
- wml/wtorch/nets/__init__.py +0 -0
- wml/wtorch/nets/ckpt_toolkit.py +219 -0
- wml/wtorch/nets/fpn.py +276 -0
- wml/wtorch/nets/hrnet/__init__.py +0 -0
- wml/wtorch/nets/hrnet/config.py +2 -0
- wml/wtorch/nets/hrnet/hrnet.py +494 -0
- wml/wtorch/nets/misc.py +249 -0
- wml/wtorch/nets/resnet/__init__.py +0 -0
- wml/wtorch/nets/resnet/layers/__init__.py +17 -0
- wml/wtorch/nets/resnet/layers/aspp.py +144 -0
- wml/wtorch/nets/resnet/layers/batch_norm.py +231 -0
- wml/wtorch/nets/resnet/layers/blocks.py +111 -0
- wml/wtorch/nets/resnet/layers/wrappers.py +110 -0
- wml/wtorch/nets/resnet/r50_config.py +38 -0
- wml/wtorch/nets/resnet/resnet.py +691 -0
- wml/wtorch/nets/shape_spec.py +20 -0
- wml/wtorch/nets/simple_fpn.py +101 -0
- wml/wtorch/nms.py +109 -0
- wml/wtorch/nn.py +896 -0
- wml/wtorch/ocr_block.py +193 -0
- wml/wtorch/summary.py +331 -0
- wml/wtorch/train_toolkit.py +603 -0
- wml/wtorch/transformer_blocks.py +266 -0
- wml/wtorch/utils.py +719 -0
- wml/wtorch/wlr_scheduler.py +100 -0
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
import wml.object_detection2.npod_toolkit as npod
|
|
4
|
+
import wml.wml_utils
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
|
+
import numpy as np
|
|
7
|
+
import math
|
|
8
|
+
import wml.object_detection2.visualization as odv
|
|
9
|
+
import wml.img_utils as wmli
|
|
10
|
+
from wml.iotoolkit.pascal_voc_toolkit import PascalVOCData,read_voc_xml
|
|
11
|
+
from wml.iotoolkit.coco_toolkit import COCOData
|
|
12
|
+
from wml.iotoolkit.labelme_toolkit import LabelMeData
|
|
13
|
+
from wml.iotoolkit.fast_labelme import FastLabelMeData
|
|
14
|
+
import wml.object_detection2.bboxes as odb
|
|
15
|
+
import pandas as pd
|
|
16
|
+
import wml.wml_utils as wmlu
|
|
17
|
+
from wml.iotoolkit.mapillary_vistas_toolkit import MapillaryVistasData
|
|
18
|
+
from sklearn.cluster import KMeans
|
|
19
|
+
from functools import partial
|
|
20
|
+
from argparse import ArgumentParser
|
|
21
|
+
from itertools import count
|
|
22
|
+
from wml.iotoolkit.object365v2_toolkit import Object365V2
|
|
23
|
+
from wml.object_detection2.data_process_toolkit import remove_class
|
|
24
|
+
from collections import OrderedDict
|
|
25
|
+
from wml.walgorithm import lower_bound
|
|
26
|
+
|
|
27
|
+
class DictDatasetReader:
|
|
28
|
+
|
|
29
|
+
def __init__(self,dataset) -> None:
|
|
30
|
+
self.dataset = dataset
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
def __len__(self):
|
|
34
|
+
return len(self.dataset)
|
|
35
|
+
|
|
36
|
+
def __getitem__(self,idx):
|
|
37
|
+
if hasattr(self.dataset,"get_ann_info"):
|
|
38
|
+
data = self.dataset.get_ann_info(idx)
|
|
39
|
+
else:
|
|
40
|
+
data = self.dataset[idx]
|
|
41
|
+
|
|
42
|
+
labels_text = [str(x) for x in data['labels']]
|
|
43
|
+
return data['filename'],[0,0],data['labels'],labels_text,data['bboxes'],None,None,None,None
|
|
44
|
+
|
|
45
|
+
'''
|
|
46
|
+
ratio: h/w
|
|
47
|
+
'''
|
|
48
|
+
def statistics_boxes(boxes,nr=100,name=""):
|
|
49
|
+
sizes = [math.sqrt((x[2]-x[0])*(x[3]-x[1])) for x in boxes]
|
|
50
|
+
ratios = [(x[2]-x[0])/(x[3]-x[1]+1e-8) for x in boxes]
|
|
51
|
+
try:
|
|
52
|
+
print(f"Min area size (sqrt(w*h)) {min(sizes):.2f}, max area size {max(sizes):.2f} (pixel), mean {np.mean(sizes):.2f}, std {np.std(sizes):.2f}.")
|
|
53
|
+
print(f"Min ratio {min(ratios):.2f}, max ratios {max(ratios):.2f}, mean: {np.mean(ratios):.2f}.")
|
|
54
|
+
rratios = [x if x>=1 else 1.0/max(x,1e-3) for x in ratios]
|
|
55
|
+
print(f"Real Ratio:Min {min(rratios):.2f}, max {max(rratios):.2f}, mean: {np.mean(rratios):.2f}, std: {np.std(rratios):.2f}.")
|
|
56
|
+
except:
|
|
57
|
+
pass
|
|
58
|
+
'''plt.figure(2,figsize=(10,10))
|
|
59
|
+
n, bins, patches = plt.hist(sizes, nr, normed=None, facecolor='blue', alpha=0.5)
|
|
60
|
+
plt.grid(axis='y', alpha=0.75)
|
|
61
|
+
plt.grid(axis='x', alpha=0.75)
|
|
62
|
+
plt.title(name+" area")
|
|
63
|
+
plt.figure(3,figsize=(10,10))
|
|
64
|
+
n, bins, patches = plt.hist(ratios, nr, normed=None, facecolor='red', alpha=0.5)
|
|
65
|
+
plt.grid(axis='y', alpha=0.75)
|
|
66
|
+
plt.grid(axis='x', alpha=0.75)
|
|
67
|
+
plt.title(name+" ratio")
|
|
68
|
+
plt.show()
|
|
69
|
+
print(max(ratios))
|
|
70
|
+
return _statistics_value(sizes,nr),_statistics_value(ratios,nr)'''
|
|
71
|
+
pd_sizes = pd.Series(sizes)
|
|
72
|
+
pd_ratios = pd.Series(ratios)
|
|
73
|
+
plt.figure(0,figsize=(15,10))
|
|
74
|
+
#pd_sizes.plot(kind = 'hist', bins = nr, color = 'steelblue', edgecolor = 'black', normed = True, label = "hist")
|
|
75
|
+
#pd_sizes.plot(kind = 'hist', bins = nr, color = 'steelblue', edgecolor = 'black', density=True, label = "hist")
|
|
76
|
+
pd_sizes.plot(kind = 'hist', bins = nr, color = 'steelblue', edgecolor = 'black', label = "hist")
|
|
77
|
+
#pd_sizes.plot(kind = 'kde', color = 'red', label ="kde")
|
|
78
|
+
plt.grid(axis='y', alpha=0.75)
|
|
79
|
+
plt.grid(axis='x', alpha=0.75)
|
|
80
|
+
plt.title(name)
|
|
81
|
+
|
|
82
|
+
plt.figure(1,figsize=(15,10))
|
|
83
|
+
#pd_ratios.plot(kind = 'hist', bins = nr, color = 'steelblue', edgecolor = 'black', normed = True, label = "hist")
|
|
84
|
+
#pd_ratios.plot(kind = 'hist', bins = nr, color = 'steelblue', edgecolor = 'black', desnsity= True, label = "hist")
|
|
85
|
+
pd_ratios.plot(kind = 'hist', bins = nr, color = 'steelblue', edgecolor = 'black', label = "hist")
|
|
86
|
+
#pd_ratios.plot(kind = 'kde', color = 'red', label ="kde")
|
|
87
|
+
plt.grid(axis='y', alpha=0.75)
|
|
88
|
+
plt.grid(axis='x', alpha=0.75)
|
|
89
|
+
plt.title(name+" ratio")
|
|
90
|
+
plt.show()
|
|
91
|
+
try:
|
|
92
|
+
print(max(ratios))
|
|
93
|
+
except:
|
|
94
|
+
pass
|
|
95
|
+
return _statistics_value(sizes,nr),_statistics_value(ratios,nr)
|
|
96
|
+
|
|
97
|
+
def statistics_classes_per_img(data,nr=100):
|
|
98
|
+
pd_sizes = pd.Series(data)
|
|
99
|
+
plt.figure(0,figsize=(15,10))
|
|
100
|
+
#pd_sizes.plot(kind = 'hist', bins = nr, color = 'steelblue', edgecolor = 'black', normed = True, label = "hist")
|
|
101
|
+
#pd_sizes.plot(kind = 'hist', bins = nr, color = 'steelblue', edgecolor = 'black', density=True, label = "hist")
|
|
102
|
+
pd_sizes.plot(kind = 'hist', bins = nr, color = 'steelblue', edgecolor = 'black', label = "hist")
|
|
103
|
+
#pd_sizes.plot(kind = 'kde', color = 'red', label ="kde")
|
|
104
|
+
plt.grid(axis='y', alpha=0.75)
|
|
105
|
+
plt.grid(axis='x', alpha=0.75)
|
|
106
|
+
plt.title("classes nr per img")
|
|
107
|
+
plt.show()
|
|
108
|
+
|
|
109
|
+
def statistics_boxes_by_different_area(boxes,nr=100,bin_size=5,level=0,size_array=[]):
|
|
110
|
+
sizes = [math.sqrt((x[2]-x[0])*(x[3]-x[1])) for x in boxes]
|
|
111
|
+
min_size = min(sizes)
|
|
112
|
+
max_size = max(sizes)
|
|
113
|
+
delta = (max_size-min_size)/bin_size
|
|
114
|
+
l_bboxes = {}
|
|
115
|
+
if size_array is None or len(size_array)==0:
|
|
116
|
+
size_array = []
|
|
117
|
+
for i in range(bin_size-1):
|
|
118
|
+
size_array.append(min_size+delta+i*delta)
|
|
119
|
+
else:
|
|
120
|
+
bin_size = len(size_array)+1
|
|
121
|
+
|
|
122
|
+
for i,s in enumerate(sizes):
|
|
123
|
+
if s>size_array[-1]:
|
|
124
|
+
index = len(size_array)
|
|
125
|
+
else:
|
|
126
|
+
index = lower_bound(size_array,s)
|
|
127
|
+
if index in l_bboxes:
|
|
128
|
+
l_bboxes[index].append(boxes[i])
|
|
129
|
+
else:
|
|
130
|
+
l_bboxes[index] = [boxes[i]]
|
|
131
|
+
|
|
132
|
+
print(f"bboxes nr of each range")
|
|
133
|
+
for k in range(bin_size):
|
|
134
|
+
if k not in l_bboxes:
|
|
135
|
+
continue
|
|
136
|
+
v = l_bboxes[k]
|
|
137
|
+
print(k,len(v),f"{len(v)*100.0/len(boxes):.2f}%")
|
|
138
|
+
|
|
139
|
+
size_array = [min_size]+size_array+[max_size]
|
|
140
|
+
for i in range(bin_size):
|
|
141
|
+
if i not in l_bboxes:
|
|
142
|
+
continue
|
|
143
|
+
l_size = min_size + i* delta
|
|
144
|
+
h_size = l_size + delta
|
|
145
|
+
statistics_boxes(l_bboxes[i],nr,name=f"area_{size_array[i]:.3f}->{size_array[i+1]:.3f}: {len(l_bboxes[i])*100/len(sizes):.1f}%")
|
|
146
|
+
|
|
147
|
+
if False and level<1:
|
|
148
|
+
branch_thr = 0.8
|
|
149
|
+
for k,v in l_bboxes.items():
|
|
150
|
+
if len(v)/len(boxes)>branch_thr:
|
|
151
|
+
print(f"Show branch {k} statistics")
|
|
152
|
+
statistics_boxes_by_different_area(v,nr=nr,bin_size=bin_size,level=level+1)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def statistics_boxes_by_different_ratio(boxes,nr=100,bin_size=5):
|
|
157
|
+
ratios = [(x[2]-x[0])/(x[3]-x[1]+1e-8) for x in boxes]
|
|
158
|
+
min_ratio = min(ratios)
|
|
159
|
+
max_ratio = max(ratios)
|
|
160
|
+
delta = (max_ratio-min_ratio)/bin_size
|
|
161
|
+
l_bboxes = {}
|
|
162
|
+
for i, r in enumerate(ratios):
|
|
163
|
+
index = int((r - min_ratio) / delta)
|
|
164
|
+
if index in l_bboxes:
|
|
165
|
+
l_bboxes[index].append(boxes[i])
|
|
166
|
+
else:
|
|
167
|
+
l_bboxes[index] = [boxes[i]]
|
|
168
|
+
|
|
169
|
+
for k, v in l_bboxes.items():
|
|
170
|
+
print(k, len(v))
|
|
171
|
+
for i in range(bin_size):
|
|
172
|
+
if i not in l_bboxes:
|
|
173
|
+
continue
|
|
174
|
+
l_ratio= min_ratio+ i * delta
|
|
175
|
+
h_ratio= l_ratio+ delta
|
|
176
|
+
statistics_boxes(l_bboxes[i], nr, name=f"ratio_{l_ratio:.3f}->{h_ratio:.3f}")
|
|
177
|
+
pass
|
|
178
|
+
|
|
179
|
+
def _statistics_value(values,nr=100):
|
|
180
|
+
value_max = max(values)
|
|
181
|
+
value_min = min(values)
|
|
182
|
+
values_y = [0.]*nr
|
|
183
|
+
|
|
184
|
+
for v in values:
|
|
185
|
+
if v<=value_min:
|
|
186
|
+
values_y[0] += 1.0
|
|
187
|
+
elif v>=value_max:
|
|
188
|
+
values_y[nr-1] += 1.0
|
|
189
|
+
else:
|
|
190
|
+
index = int((v-value_min)*(nr-1)/(value_max-value_min))
|
|
191
|
+
values_y[index] += 1.0
|
|
192
|
+
|
|
193
|
+
return values_y,value_min,value_max
|
|
194
|
+
|
|
195
|
+
def default_encode_label(l):
|
|
196
|
+
return l
|
|
197
|
+
|
|
198
|
+
def statistics_boxes_in_dir(dir_path,label_encoder=default_encode_label,labels_to_remove=None,nr=100,aspect_range=None):
|
|
199
|
+
def get_datas():
|
|
200
|
+
if not os.path.exists(dir_path):
|
|
201
|
+
print("path {} not exists.".format(dir_path))
|
|
202
|
+
files = wml_utils.recurse_get_filepath_in_dir(dir_path,suffix=".xml")
|
|
203
|
+
print("\ntotal file size {}.".format(len(files)))
|
|
204
|
+
for file in files:
|
|
205
|
+
shape, bboxes, labels_text, difficult, truncated = read_voc_xml(file,aspect_range=aspect_range)
|
|
206
|
+
yield bboxes,labels_text,os.path.basename(file)
|
|
207
|
+
|
|
208
|
+
return statistics_boxes_with_datas(get_datas(),label_encoder,labels_to_remove,nr)
|
|
209
|
+
|
|
210
|
+
def trans_img_short_size_to(img_size,short_size=640):
|
|
211
|
+
img_short_size = min(img_size[0],img_size[1])
|
|
212
|
+
scale = short_size/img_short_size
|
|
213
|
+
return [x*scale for x in img_size]
|
|
214
|
+
|
|
215
|
+
def trans_img_long_size_to(img_size,long_size=512):
|
|
216
|
+
img_long_size = max(img_size[0],img_size[1])
|
|
217
|
+
scale = long_size/img_long_size
|
|
218
|
+
return [x*scale for x in img_size]
|
|
219
|
+
|
|
220
|
+
def statistics_boxes_with_datas(datas,label_encoder=default_encode_label,labels_to_remove=None,max_aspect=None,absolute_size=False,
|
|
221
|
+
trans_img_size=None,silent=False):
|
|
222
|
+
all_boxes = []
|
|
223
|
+
all_labels = []
|
|
224
|
+
max_examples = 0
|
|
225
|
+
label_file_count={}
|
|
226
|
+
labels_to_file={}
|
|
227
|
+
example_nrs = []
|
|
228
|
+
classeswise_boxes = {}
|
|
229
|
+
total_file_nr = 0
|
|
230
|
+
classes_nr_per_img = []
|
|
231
|
+
no_annotation_nr = 0
|
|
232
|
+
total_crowd_files = 0
|
|
233
|
+
total_crowd_bboxes = 0
|
|
234
|
+
|
|
235
|
+
for data in datas:
|
|
236
|
+
file, img_size,category_ids, labels_text, bboxes, binary_mask, area, is_crowd, _ = data
|
|
237
|
+
total_file_nr += 1
|
|
238
|
+
if is_crowd is not None:
|
|
239
|
+
is_crowd = np.array(is_crowd).astype(np.int32)
|
|
240
|
+
|
|
241
|
+
if np.any(is_crowd):
|
|
242
|
+
total_crowd_files += 1
|
|
243
|
+
total_crowd_bboxes += np.sum(is_crowd)
|
|
244
|
+
if bboxes.shape[0]<1:
|
|
245
|
+
if not silent:
|
|
246
|
+
print(f"{file} no annotation, skip")
|
|
247
|
+
no_annotation_nr += 1
|
|
248
|
+
continue
|
|
249
|
+
if absolute_size:
|
|
250
|
+
if trans_img_size is not None:
|
|
251
|
+
img_size = trans_img_size(img_size)
|
|
252
|
+
#bboxes = odb.relative_boxes_to_absolutely_boxes(bboxes,width=img_size[1],height=img_size[0])
|
|
253
|
+
pass
|
|
254
|
+
classes_nr_per_img.append(len(set(labels_text)))
|
|
255
|
+
file = os.path.basename(file)
|
|
256
|
+
if len(labels_text)==0:
|
|
257
|
+
continue
|
|
258
|
+
aspect = npod.box_aspect(bboxes)
|
|
259
|
+
if max_aspect is not None and np.max(aspect)>max_aspect:
|
|
260
|
+
print(f"asepct is too large, expect max aspect is {max_aspect}, actual get {np.max(aspect)}")
|
|
261
|
+
e_nr = len(labels_text)
|
|
262
|
+
example_nrs.append(e_nr)
|
|
263
|
+
max_examples = max(e_nr,max_examples)
|
|
264
|
+
all_boxes.extend(bboxes)
|
|
265
|
+
all_labels.extend(labels_text)
|
|
266
|
+
for l,box in zip(labels_text,bboxes):
|
|
267
|
+
if l in classeswise_boxes:
|
|
268
|
+
classeswise_boxes[l].append(box)
|
|
269
|
+
else:
|
|
270
|
+
classeswise_boxes[l] = [box]
|
|
271
|
+
|
|
272
|
+
tmp_dict = {}
|
|
273
|
+
for l in labels_text:
|
|
274
|
+
tmp_dict[l] = 1
|
|
275
|
+
if l in labels_to_file:
|
|
276
|
+
labels_to_file[l].append(file)
|
|
277
|
+
else:
|
|
278
|
+
labels_to_file[l] = [file]
|
|
279
|
+
|
|
280
|
+
for k in tmp_dict.keys():
|
|
281
|
+
if k in label_file_count:
|
|
282
|
+
label_file_count[k] += 1
|
|
283
|
+
else:
|
|
284
|
+
label_file_count[k] = 1
|
|
285
|
+
|
|
286
|
+
labels_counter = {}
|
|
287
|
+
org_labels_counter = {}
|
|
288
|
+
encoded_labels = []
|
|
289
|
+
for _l in all_labels:
|
|
290
|
+
l = label_encoder(_l)
|
|
291
|
+
encoded_labels.append(l)
|
|
292
|
+
if l in labels_counter:
|
|
293
|
+
labels_counter[l] = labels_counter[l]+1
|
|
294
|
+
else:
|
|
295
|
+
labels_counter[l] = 1
|
|
296
|
+
if _l in org_labels_counter:
|
|
297
|
+
org_labels_counter[_l] = org_labels_counter[_l]+1
|
|
298
|
+
else:
|
|
299
|
+
org_labels_counter[_l] = 1
|
|
300
|
+
example_nrs = np.array(example_nrs)
|
|
301
|
+
try:
|
|
302
|
+
print(f"Max element size {np.max(example_nrs)}, element min {np.min(example_nrs)}, element mean {np.mean(example_nrs)}, element var {np.var(example_nrs)}.")
|
|
303
|
+
except:
|
|
304
|
+
pass
|
|
305
|
+
labels_counter = list(labels_counter.items())
|
|
306
|
+
labels_counter.sort(key=lambda x:x[1],reverse=True)
|
|
307
|
+
|
|
308
|
+
classes = [x[0] for x in labels_counter]
|
|
309
|
+
print(f"num classes={len(classes)}")
|
|
310
|
+
print(tuple(classes))
|
|
311
|
+
|
|
312
|
+
total_nr = 0
|
|
313
|
+
for k,v in labels_counter:
|
|
314
|
+
total_nr += v
|
|
315
|
+
|
|
316
|
+
print(f"Total files contain crowd bboxes: {total_crowd_files}/{total_crowd_files*100/total_file_nr:.2f}%")
|
|
317
|
+
print(f"Total crowd bboxes: {total_crowd_bboxes}/{total_crowd_bboxes*100/max(total_nr,1):.2f}%")
|
|
318
|
+
|
|
319
|
+
print(f"Total bboxes count {total_nr}")
|
|
320
|
+
print("\n--->BBoxes count:")
|
|
321
|
+
for k,v in labels_counter:
|
|
322
|
+
print("{:>8}:{:<8}, {:>4.2f}%".format(k,v,v*100./total_nr))
|
|
323
|
+
|
|
324
|
+
print(f"Total file count {total_file_nr}.")
|
|
325
|
+
print(f"Total no annotation file count {no_annotation_nr}, {no_annotation_nr*100/total_file_nr:.2f}%.")
|
|
326
|
+
print("\n--->File count:")
|
|
327
|
+
label_file_count= list(label_file_count.items())
|
|
328
|
+
label_file_count.sort(key=lambda x:x[1],reverse=True)
|
|
329
|
+
for k,v in label_file_count:
|
|
330
|
+
print("{:>8}:{:<8}, {:>4.2f}".format(k,v,v*100./total_file_nr))
|
|
331
|
+
print("\n--->org statistics:")
|
|
332
|
+
org_labels_counter= list(org_labels_counter.items())
|
|
333
|
+
org_labels_counter.sort(key=lambda x:x[1],reverse=True)
|
|
334
|
+
total_nr = 0
|
|
335
|
+
for k,v in org_labels_counter:
|
|
336
|
+
total_nr += v
|
|
337
|
+
for k,v in org_labels_counter:
|
|
338
|
+
print(f"{k:>8}:{v:<8}, {v*100./total_nr:>4.2f}%")
|
|
339
|
+
if labels_to_remove is not None:
|
|
340
|
+
all_boxes,encoded_labels = remove_class(all_boxes,encoded_labels,labels_to_remove)
|
|
341
|
+
|
|
342
|
+
#show classes per img info
|
|
343
|
+
classes_nr_per_img = np.array(classes_nr_per_img)
|
|
344
|
+
try:
|
|
345
|
+
print(f"Classes per img, min={np.min(classes_nr_per_img)}, max={np.max(classes_nr_per_img)}, mean={np.mean(classes_nr_per_img)}, std={np.std(classes_nr_per_img)}")
|
|
346
|
+
except:
|
|
347
|
+
pass
|
|
348
|
+
|
|
349
|
+
return [all_boxes,classeswise_boxes,labels_to_file,classes_nr_per_img]
|
|
350
|
+
|
|
351
|
+
def statistics_dict_dataset_boxes_with_datas(datas,*args,**kwargs):
|
|
352
|
+
ndatas = DictDatasetReader(datas)
|
|
353
|
+
return statistics_boxes_with_datas(ndatas,*args,**kwargs)
|
|
354
|
+
|
|
355
|
+
def show_boxes_statistics(statics):
|
|
356
|
+
plt.figure(0,figsize=(10,10))
|
|
357
|
+
sizes = statics[0]
|
|
358
|
+
nr = len(sizes[0])
|
|
359
|
+
sizes_x = sizes[1]+np.array(range(nr)).astype(np.float32)*(sizes[2]-sizes[1])/(nr-1)
|
|
360
|
+
sizes_x = sizes_x.tolist()
|
|
361
|
+
plt.title("Size")
|
|
362
|
+
plt.xticks(ticks(sizes[1],sizes[2],-3,20))
|
|
363
|
+
plt.plot(sizes_x,sizes[0])
|
|
364
|
+
plt.figure(1,figsize=(10,10))
|
|
365
|
+
ratios = statics[1]
|
|
366
|
+
nr = len(ratios[0])
|
|
367
|
+
ratios_x = ratios[1]+np.array(range(nr)).astype(np.float32)*(ratios[2]-ratios[1])/(nr-1)
|
|
368
|
+
ratios_x = ratios_x.tolist()
|
|
369
|
+
plt.title("Ratio")
|
|
370
|
+
plt.xticks(ticks(ratios[1],ratios[2],-1,20))
|
|
371
|
+
plt.plot(ratios_x,ratios[0])
|
|
372
|
+
plt.show()
|
|
373
|
+
|
|
374
|
+
def show_classwise_boxes_statistics(data,nr=20,labels=None):
|
|
375
|
+
for k,v in data.items():
|
|
376
|
+
if labels is not None and not k in labels:
|
|
377
|
+
continue
|
|
378
|
+
statistics_boxes(v,nr=nr,name=k)
|
|
379
|
+
|
|
380
|
+
def ticks(minv,maxv,order,nr):
|
|
381
|
+
delta = (maxv-minv)/(2.*nr)
|
|
382
|
+
scale = math.pow(10,order)
|
|
383
|
+
n_min = (minv-delta)//scale
|
|
384
|
+
n_max = (maxv+delta)//scale
|
|
385
|
+
minv = n_min*scale
|
|
386
|
+
maxv = n_max*scale
|
|
387
|
+
t_delta = (max(scale,((maxv-minv)/nr))//scale)*scale
|
|
388
|
+
return np.arange(minv,maxv,t_delta).tolist()
|
|
389
|
+
|
|
390
|
+
def show_anchor_box(img_file,boxes,size=None):
|
|
391
|
+
nr = boxes.shape[0]
|
|
392
|
+
classes = []
|
|
393
|
+
scores = []
|
|
394
|
+
for i in range(nr):
|
|
395
|
+
classes.append(0)
|
|
396
|
+
scores.append(1)
|
|
397
|
+
img = wmli.imread(img_file)
|
|
398
|
+
if size is not None:
|
|
399
|
+
img = wmli.resize_img(img,(size[1],size[0]))
|
|
400
|
+
|
|
401
|
+
odv.bboxes_draw_on_img(img, classes, scores, boxes)
|
|
402
|
+
plt.figure(figsize=(10,10))
|
|
403
|
+
plt.imshow(img)
|
|
404
|
+
plt.show()
|
|
405
|
+
return img
|
|
406
|
+
|
|
407
|
+
def test_dataset():
|
|
408
|
+
data = PascalVOCData(label_text2id=None)
|
|
409
|
+
data.read_data("/home/vghost/ai/mldata2/test_data_0day/test_s")
|
|
410
|
+
|
|
411
|
+
return data.get_items()
|
|
412
|
+
|
|
413
|
+
def pascal_voc_dataset(data_dir,labels=None):
|
|
414
|
+
#labels = ['MS7U', 'MP1U', 'MU2U', 'ML9U', 'MV1U', 'ML3U', 'MS1U', 'Other']
|
|
415
|
+
if labels is not None and len(labels)>0:
|
|
416
|
+
label_text2id = dict(zip(labels,count()))
|
|
417
|
+
else:
|
|
418
|
+
label_text2id = None
|
|
419
|
+
|
|
420
|
+
#data = PascalVOCData(label_text2id=label_text2id,resample_parameters={6:8,5:2,7:2})
|
|
421
|
+
data = PascalVOCData(label_text2id=label_text2id,absolute_coord=True,silent=True)
|
|
422
|
+
|
|
423
|
+
'''data_path = "/mnt/data1/wj/ai/smldata/boedcvehicle/train"
|
|
424
|
+
data_path = "/mnt/data1/wj/ai/smldata/boedcvehicle/wt_06"
|
|
425
|
+
data_path = "/home/wj/ai/mldata1/GDS1Crack/train"
|
|
426
|
+
data_path = "/home/wj/ai/mldata1/take_photo/train/coco"
|
|
427
|
+
data_path = "/mnt/data1/wj/ai/mldata/MOT/MOT17/train/MOT17-09-SDP/img1"
|
|
428
|
+
data_path = "/home/wj/ai/mldata1/B11ACT/datas/labeled"
|
|
429
|
+
data_path = "/home/wj/ai/mldata1/B7mura/datas/data/ML3U"
|
|
430
|
+
data_path = "/home/wj/ai/mldata1/B7mura/datas/data/MV1U"
|
|
431
|
+
data_path = "/home/wj/ai/mldata1/B7mura/datas/data/MU4U"
|
|
432
|
+
data_path = "/home/wj/ai/mldata1/B7mura/datas/data"
|
|
433
|
+
data_path = "/home/wj/下载/_数据集"'''
|
|
434
|
+
#data_path = "/home/wj/ai/mldata1/B7mura/datas/test_s0"
|
|
435
|
+
#data_path = "/home/wj/0day/wt_06"
|
|
436
|
+
#data_path = '/home/wj/0day/pyz'
|
|
437
|
+
xmls = wmlu.get_files(data_dir,suffix=".xml")
|
|
438
|
+
imgs = [wmlu.change_suffix(x,"jpg") for x in xmls]
|
|
439
|
+
files = list(zip(imgs,xmls))
|
|
440
|
+
data.read_data(files)
|
|
441
|
+
'''data.read_data(data_dir,
|
|
442
|
+
silent=True,
|
|
443
|
+
img_suffix=".bmp;;.jpg")'''
|
|
444
|
+
|
|
445
|
+
return data.get_items()
|
|
446
|
+
|
|
447
|
+
def coco2014_dataset():
|
|
448
|
+
data = COCOData()
|
|
449
|
+
data.read_data(wmlu.home_dir("ai/mldata/coco/annotations/instances_train2014.json"),
|
|
450
|
+
image_dir=wmlu.home_dir("ai/mldata/coco/train2014"))
|
|
451
|
+
|
|
452
|
+
return data.get_items()
|
|
453
|
+
|
|
454
|
+
def coco2017_dataset(annotations_path,labels=None):
|
|
455
|
+
data = COCOData(remove_crowd=False)
|
|
456
|
+
data.read_data(annotations_path)
|
|
457
|
+
|
|
458
|
+
return data.get_items()
|
|
459
|
+
|
|
460
|
+
def objects365_dataset(annotations_path,labels=None):
|
|
461
|
+
data = Object365V2(remove_crowd=False)
|
|
462
|
+
data.read_data(annotations_path)
|
|
463
|
+
|
|
464
|
+
return data.get_items()
|
|
465
|
+
|
|
466
|
+
def coco2014_val_dataset():
|
|
467
|
+
data = COCOData()
|
|
468
|
+
data.read_data(wmlu.home_dir("ai/mldata/coco/annotations/instances_val2014.json"),
|
|
469
|
+
image_dir=wmlu.home_dir("ai/mldata/coco/val2014"))
|
|
470
|
+
|
|
471
|
+
return data.get_items()
|
|
472
|
+
|
|
473
|
+
def labelme_dataset(data_dir,labels):
|
|
474
|
+
data = FastLabelMeData(label_text2id=None,absolute_coord=True)
|
|
475
|
+
#data.read_data("/home/vghost/ai/mldata2/qualitycontrol/rdatasv10")
|
|
476
|
+
data.read_data(data_dir,img_suffix="bmp;;jpg;;jpeg")
|
|
477
|
+
#data.read_data("/home/wj/ai/mldata1/B11ACT/datas/test_s0",img_suffix="bmp")
|
|
478
|
+
return data.get_items()
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
lid = 0
|
|
482
|
+
def _mapillary_vistas_dataset():
|
|
483
|
+
NAME2ID = {}
|
|
484
|
+
ID2NAME = {}
|
|
485
|
+
|
|
486
|
+
def name_to_id(x):
|
|
487
|
+
global lid
|
|
488
|
+
if x in NAME2ID:
|
|
489
|
+
return NAME2ID[x]
|
|
490
|
+
else:
|
|
491
|
+
NAME2ID[x] = lid
|
|
492
|
+
ID2NAME[lid] = x
|
|
493
|
+
lid += 1
|
|
494
|
+
return NAME2ID[x]
|
|
495
|
+
ignored_labels = [
|
|
496
|
+
'manhole', 'dashed', 'other-marking', 'static', 'front', 'back',
|
|
497
|
+
'solid', 'catch-basin','utility-pole', 'pole', 'street-light','direction-back', 'direction-front'
|
|
498
|
+
'ambiguous', 'other','text','diagonal','left','right','water-valve','general-single','temporary-front',
|
|
499
|
+
'wheeled-slow','parking-meter','split-left-or-straight','split-right-or-straight','zigzag',
|
|
500
|
+
'give-way-row','ground-animal','phone-booth','give-way-single','garage','temporary-back','caravan','other-barrier'
|
|
501
|
+
]
|
|
502
|
+
data = MapillaryVistasData(label_text2id=name_to_id, shuffle=False, ignored_labels=ignored_labels)
|
|
503
|
+
# data.read_data("/data/mldata/qualitycontrol/rdatasv5_splited/rdatasv5")
|
|
504
|
+
# data.read_data("/home/vghost/ai/mldata2/qualitycontrol/rdatav10_preproc")
|
|
505
|
+
# data.read_data("/home/vghost/ai/mldata2/qualitycontrol/rdatasv10_neg_preproc")
|
|
506
|
+
data.read_data(wmlu.home_dir("ai/mldata/mapillary_vistas/mapillary-vistas-dataset_public_v2.0"))
|
|
507
|
+
return data.get_boxes_items()
|
|
508
|
+
|
|
509
|
+
def mapillary_vistas_dataset(data_dir):
|
|
510
|
+
data = MapillaryVistasData(shuffle=False,use_semantic=False)
|
|
511
|
+
# data.read_data("/data/mldata/qualitycontrol/rdatasv5_splited/rdatasv5")
|
|
512
|
+
# data.read_data("/home/vghost/ai/mldata2/qualitycontrol/rdatav10_preproc")
|
|
513
|
+
# data.read_data("/home/vghost/ai/mldata2/qualitycontrol/rdatasv10_neg_preproc")
|
|
514
|
+
data.read_data(data_dir)
|
|
515
|
+
return data.get_boxes_items()
|
wml/iotoolkit/build.py
ADDED
|
File without changes
|