Esempio n. 1
0
def net_update(network: networks.NeuralNetwork) -> networks.NeuralNetwork:

    if not network.up_to_date:

        for alt_rep in network.alt_rep_cache:

            if alt_rep.up_to_date:
                if isinstance(alt_rep, cv.ONNXNetwork):
                    return cv.ONNXConverter().to_neural_network(alt_rep)
                elif isinstance(alt_rep, cv.PyTorchNetwork):
                    return cv.PyTorchConverter().to_neural_network(alt_rep)
                else:
                    raise NotImplementedError

    else:
        return network
Esempio n. 2
0
                    in_pred_bias.append([-norm_input_lb[m]])
                    in_pred_bias.append([norm_input_ub[m]])

                in_pred_bias = np.array(in_pred_bias)
                in_pred_mat = np.array(in_pred_mat)
                out_pred_mat = np.array(unsafe_mats[k])
                out_pred_bias = np.array(unsafe_vecs[k])

                prop = ver.NeVerProperty(in_pred_mat, in_pred_bias,
                                         [out_pred_mat], [out_pred_bias])
                # prop = ver.NeVerProperty(in_pred_mat, in_pred_bias, unsafe_mats, unsafe_vecs)

                input_prefix = network.input_id
                output_prefix = network.get_last_node().identifier
                ver.temp_never2smt(prop, input_prefix, output_prefix,
                                   f"smt_property/SMT_{p_id[k]}.smt2")

                p2 = reading.SmtPropertyParser(
                    ver.SMTLIBProperty(f"smt_property/SMT_{p_id[k]}.smt2"),
                    input_prefix, output_prefix).parse_property()
                print(p2)

            prop_set = True

        onnx_net = conv.ONNXConverter().from_neural_network(network)
        pytorch_net = conv.PyTorchConverter().from_neural_network(network)
        torch.save(pytorch_net.pytorch_network,
                   f"acas_pytorch/{network.identifier}.pt")
        onnx.save(onnx_net.onnx_network,
                  f"acas_onnx/{network.identifier}.onnx")
Esempio n. 3
0
lr_property = ver.NeVerProperty(in_pred_mat, in_pred_bias, out_pred_mat,
                                out_pred_bias)

master_log_file = "logs/MNISTExperimentLog.txt"

ver_param_sets = [[False, 0, False, 0]]
param_set_id = ["Over-Approx"]

with open(master_log_file, "a") as master_log:
    master_log.write(f"Dataset,NetworkID,Methodology,Safety,Time\n")

for net_id in net_ids:

    net_path = "mnist_nets/" + net_id + ".onnx"
    net = conv.ONNXConverter().to_neural_network(
        conv.ONNXNetwork(net_id, onnx.load(net_path)))
    assert isinstance(net, networks.SequentialNetwork)
    current_node = net.get_first_node()
    while current_node is not None:
        if isinstance(current_node, nodes.FullyConnectedNode):
            current_node.weight = np.where(
                np.abs(current_node.weight) < 0.000001, 0, current_node.weight)
        current_node = net.get_next_node(current_node)

    for p_set in ver_param_sets:

        log_filepath = f"logs/MNIST_NET={net_id}_{param_set_id[0]}.txt"

        print(f"MNIST_NET={net_id}_{param_set_id[0]}")
        verifier = ver.NeverVerification(log_filepath,
                                         neuron_relevance=p_set[0],
Esempio n. 4
0
    print("DROPOUT NODE TEST")
    start_network = network.SequentialNetwork("NET_TEST", "X")
    start_network.add_node(nodes.DropoutNode("Dropout_1", (3, 4, 5, 6)))
    alt_network = converter.from_neural_network(start_network)
    end_network = converter.to_neural_network(alt_network)
    assert isinstance(end_network, network.SequentialNetwork)
    start_node = start_network.get_first_node()
    end_node = end_network.get_first_node()

    assert isinstance(start_node, nodes.DropoutNode)
    assert isinstance(end_node, nodes.DropoutNode)
    assert start_node.p == end_node.p
    assert start_node.identifier == end_node.identifier


converters = [conversion.ONNXConverter(), conversion.PyTorchConverter()]
for conv in converters:
    print(f"Test for {conv.__class__.__name__}")
    relu_node_test(conv)
    sigmoid_node_test(conv)
    fully_connected_node_test(conv, True)
    fully_connected_node_test(conv, False)
    batchnorm_node_test(conv)
    conv_node_test(conv, True)
    conv_node_test(conv, False)
    averagepool_node_test(conv)
    maxpool_node_test(conv)
    lrn_node_test(conv)
    softmax_node_test(conv)
    unsqueeze_node_test(conv)
    reshape_node_test(conv)