biases3 = np.genfromtxt('../mnist/para/biases3.csv', delimiter=',') B1 = [ RealVal(biases1[i]) for i in range(l1_n) ] B2 = [ RealVal(biases2[i]) for i in range(l2_n) ] B3 = [ RealVal(biases3[i]) for i in range(l3_n) ] print "Creating Assertions" if verify_mode == "specific": # The MNIST data set has 10,000 images for testing inputs = np.genfromtxt('../mnist/para/mnist_test_images_100.csv', delimiter=',') InX = [ RealVal(inputs[0][i]) for i in range(l0_n) ] else: InX = [ Real('inX-%s' % i) for i in range(l0_n) ] InY= [ Real('inY-%s' % i) for i in range(l0_n) ] L1X = core.vmmul(InX, W1, B1, l0_n, l1_n, act_func) L2X = core.vmmul(L1X, W2, B2, l1_n, l2_n, act_func) OutX = core.vmmul(L2X, W3, B3, l2_n, l3_n, act_func) L1Y = core.vmmul(InY, W1, B1, l0_n, l1_n, act_func) L2Y = core.vmmul(L1Y, W2, B2, l1_n, l2_n, act_func) OutY = core.vmmul(L2Y, W3, B3, l2_n, l3_n, act_func) #TODO: The input pertubation constriants have to be more general input_cond = [ And(InX[i] - InY[i] < input_bound, InY[i] - InX[i] < input_bound, 0 <= InY[i], InY[i] <= 1, 0 <= InX[i], InX[i] <= 1) for i in range(l0_n) ] output_cond = [ Not( core.full_robust(OutX, OutY, l3_n, robust_cons, bound=output_bound) ) ] s = Solver() s.add(input_cond + output_cond)
else: InX = [ Real('inX-%s' % i) for i in range(l0_n) ] InY= [ Real('inY-%s' % i) for i in range(l0_n) ] else: #unscaled scale = RealVal(255) if verify_mode == "specific": inputs = np.genfromtxt('../mnist/para/mnist_test_images_unscaled_100.csv', delimiter=',') X = [ IntVal(inputs[input_id][i]) for i in range(l0_n) ] InX = core.scaleInput(X, scale, l0_n) else: X = [ Int('x%s' % i) for i in range(l0_n) ] InX = core.scaleInput(X, scale, l0_n) Y = [ Int('y%s' % i) for i in range(l0_n) ] InY = core.scaleInput(Y, scale, l0_n) OutX = core.vmmul(InX, W, B, l0_n, l1_n, "none") OutY = core.vmmul(InY, W, B, l0_n, l1_n, "none") if input_scaled == "scaled": input_cond = [ And(InX[i] - InY[i] < input_var, InY[i] - InX[i] < input_var, 0 <= InY[i], InY[i] <= 1, 0 <= InX[i], InX[i] <= 1) for i in range(l0_n) ] else: input_cond = [ And(X[i] - Y[i] < input_var, Y[i] - X[i] < input_var, 0 <= Y[i], Y[i] <= 255, 0 <= X[i], X[i] <= 255) for i in range(l0_n) ] output_cond = [ Not( core.full_robust(OutX, OutY, l1_n, robust_cons, bound=output_bound) ) ] s = Solver() s.add(input_cond + output_cond) result = core.solveIt(s) if (result == sat): m = s.model() outx = [m.evaluate(OutX[i]) for i in range(l1_n)] outy = [m.evaluate(OutY[i]) for i in range(l1_n)]