-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (58 loc) · 1.93 KB
/
Copy pathmain.py
File metadata and controls
69 lines (58 loc) · 1.93 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
61
62
63
64
65
66
67
68
69
import os
from src.Injection import Injection
from utils.utils import (
get_evaluator,
get_inference,
get_loader,
get_network,
get_network_parameters,
get_sp_type,
get_name_file,
output_to_csv,
parse_args,
)
def main(args):
data_t = args.type
network_name = args.network_name
data_set = args.data_set
inference_class = get_inference(data_set)
# initialize inference class
inference = inference_class(
data_t,
network_name,
get_network(network_name),
get_evaluator(network_name),
args.batch_size,
args.size,
data_set,
get_loader(args.data_set),
args.seed,
)
num_weight_net, num_layer, tensor_shape = get_network_parameters(data_set, network_name, data_t)
# create injection list
injection = Injection()
injection.create_injection_list(
num_weight_net,
num_layer , # num_layer limited to convolutional layers only for now
tensor_shape,
num_bit_representation=args.bit_len,
type=get_sp_type(data_t),
number_of_faults=args.force_n,
net_level = args.net_level,
bit_index_low = args.low_index,
bit_index_high = args.high_index
)
# setup path for results file
PATH = os.path.abspath(os.path.dirname(__file__))
results_path = PATH + "/res/" + data_set + "/" + network_name + "/" + get_name_file(data_t, args.name_output)
# perform inference without injection
golden_acc, _ = inference.compute_inference()
# perform inference for every fault in fault list
for fault in injection.fault_list:
print(f"\nFault: {fault.fault_id}")
# perform inference with injection
acc, top_5 = inference.compute_inference(fault)
# output results to csv in results_path
output_to_csv(results_path, fault, acc, golden_acc, top_5)
if __name__ == "__main__":
main(args=parse_args())