-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmodify_label.py
More file actions
60 lines (53 loc) · 1.87 KB
/
modify_label.py
File metadata and controls
60 lines (53 loc) · 1.87 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
52
53
54
55
56
57
58
59
60
import os
import argparse
def increaseandthreshold(xys, threshold):
xs = []
ys = []
biggest = 0
for xy in xys:
[x, y] = xy.split(" ")
y = float(y)
xs.append(x)
if y<=biggest:
ys.append(biggest)
else:
ys.append(y)
biggest = y
for k in range(len(ys)):
if ys[k]<=threshold:
ys[k]=0
else:
ys[k]=1
assert len(xs)==len(ys)
return [f"{xs[i]} {ys[i]}\n" for i in range(len(xs))]
root = "./pic"
labelfile = "labels_ma.txt"
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="modify labels")
parser.add_argument("-c", type=str, default=["ctrl"], nargs="+", help="circuits/chips")
parser.add_argument("--type", type=str, default=["and", "or", "fe", "dom", "ssl", "msl"], nargs="+", help="fault types")
parser.add_argument("-t", type=float, default=0.899999, help="ma threshold")
args = parser.parse_args()
print(args)
chips = args.c
faults = args.type
threshold = args.t
for chip in chips:
for fault in faults:
if not os.path.exists(os.path.join(root, chip, fault)):
continue
resps = os.listdir(os.path.join(root, chip, fault))
for resp in resps:
item = os.path.join(root, chip, fault, resp, labelfile)
if not os.path.exists(item):
print(item)
raise Exception
with open(item, "r") as f:
xys = f.readlines()
f.close()
xys = increaseandthreshold(xys=xys, threshold=threshold)
with open(os.path.join(root, chip, fault, resp, "labels_modified.txt"), "w") as f:
for i in xys:
f.write(i)
f.close()
print(f"{chip} done")