-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat_by_path.py
executable file
·49 lines (39 loc) · 1.23 KB
/
stat_by_path.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
from argparse import ArgumentParser
import glob
from tqdm import tqdm
def calculate_stat(path, cnt):
info = dict()
info['NS'] = 0
total = 0
for i in range(cnt+1):
info[str(i)]=0
# annot_path = path+'/*/annotations/*.txt'
annot_path = path+'/*.txt'
annots_file = glob.glob(annot_path, recursive=True)
for i in tqdm(annots_file):
with open(i, 'r') as f:
total+=1
lines = f.readlines()
if len(lines)==0:
info['NS']+=1
for line in lines:
l = line.split(' ')
try:
info[str(l[0])]+=1
except KeyError:
pass
for key in info.keys():
if key == 'NS':
print("Negative Sample: ",info[key])
else:
print("Class-",int(key)," : ",info[key])
return total, info
def main():
parser = ArgumentParser()
parser.add_argument('--path', '-p', type=str, default='./annotation', help='annotation folder path')
parser.add_argument('--cnt', '-c', type=int, help='class count number', default=12)
args = parser.parse_args()
calculate_stat(args.path, args.cnt)
if __name__ == "__main__":
main()