-
Notifications
You must be signed in to change notification settings - Fork 2
/
FFN.py
61 lines (45 loc) · 1.68 KB
/
FFN.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import sys
import time
import signal
from src.FFNEvaluation import sampleEval
printStatus= "Result: "
printTimeout= "\n\nTime taken : "
# Register an handler for the timeout
def handler(signum, frame):
raise Exception("")#kill running :: Timeout occurs")
def runSingleInstance(onnxFile,vnnlibFile):
#Variable Initialization
startTime = time.time()
onnxFileName = onnxFile.split('/')[-1]
vnnFileName = vnnlibFile.split('/')[-1]
print(f"\nNN model: {onnxFileName}")
print(f"Property file: {vnnFileName}")
'Calling sampleEval until any adversarial found or timout ocuurs'
while(1):
status = sampleEval(onnxFile,vnnlibFile)
endTime = time.time()
timeElapsed = endTime - startTime
#print("Time elapsed: ",timeElapsed)
if (status == "violated"):
resultStr = " "#\n" + printTimeout+str(round(timeElapsed,4))+" second"
return resultStr
resultStr = printStatus +"Timeout"#+printTimeout+str(round(timeElapsed,4)) + " second"
return resultStr
#Main function
if __name__ == '__main__':
onnxFile= sys.argv[1]
vnnlibFile=sys.argv[2]
timeout=sys.argv[3]
# Register the signal function handler
signal.signal(signal.SIGALRM, handler)
# Define a timeout for "runSingleInstance"
signal.alarm(int(timeout))
'"runSingleInstance" will continue until any adversarial found or timeout occurs'
'When timeout occurs codes written within exception will be executed'
try:
retStatus = runSingleInstance(onnxFile,vnnlibFile)
print(retStatus)
except Exception as exc:
printStr = printStatus+"timeout"#+printTimeout + str(timeout) + " second\n"
print(printStr)
print(exc)