-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclassification.py
More file actions
51 lines (43 loc) · 1.55 KB
/
classification.py
File metadata and controls
51 lines (43 loc) · 1.55 KB
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
47
48
49
50
51
import sys
import os
from subprocess import check_output
import subprocess
path = str(sys.argv[1])
print ("path: " ,path)
model = str(sys.argv[2])
print ("model: ", model)
def extract_score(line):
return float(line.split()[3].replace(")", ""))
cmd = "ls " +path
proc = subprocess.Popen(cmd, shell=True ,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
files = proc.communicate()[0]
label = ""
a = 0
b = 0
for filename in files.splitlines():
abandoned = 0
background = 0
filename = filename.decode('ascii')
if filename is "":
continue
cmd_classify = "python classify.py " + path + filename + " " + model + " labels/bag_detection.txt"
proc_classify = subprocess.Popen(cmd_classify, shell=True ,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
lines = proc_classify.communicate()[0].splitlines()
#print (cmd_classify)
for line in lines:
line = line.decode('ascii')
if 'score' in line:
score = extract_score(line)
if 'abandoned' in line:
abandoned = score
else:
background = score
if abandoned > background:
a += 1
label = "abandoned"
else:
b += 1
label = "background"
print (filename + " classified as: ", label, " scores: " , abandoned, background, " counts so far: ", a, b )
print ("Abandoned: " , a )
print (" Background: ", b)