コード例 #1
0
def apply_rast_tshd(image, seed, tshd_val):
    seed_image = x_test[int(seed)]
    xml_desc = vectorization_tools.vectorize(seed_image)
    seed = rasterization_tools.rasterize_in_memory(xml_desc)
    distance_seed = get_distance(seed, image)

    print("RAST %s" % distance_seed)

    if distance_seed < tshd_val:
        return True
    else:
        return False
コード例 #2
0
    def mutate(self):
        condition = True
        counter_mutations = 0
        while condition:
            # Select mutation operator.
            rand_mutation_probability = random.uniform(0, 1)
            rand_mutation_prob = random.uniform(0, 1)
            if rand_mutation_probability >= MUTOPPROB:            
                if rand_mutation_prob >= MUTOFPROB:
                    mutation = 1
                else:
                    mutation = 2
            else:
                if rand_mutation_prob >= MUTOFPROB:
                    mutation = 3
                else:
                    mutation = 4

            counter_mutations += 1
            mutant_vector = mutation_manager.mutate(self.digit.xml_desc, mutation, counter_mutations/20)
            mutant_xml_desc = vectorization_tools.create_svg_xml(mutant_vector)
            rasterized_digit = rasterization_tools.rasterize_in_memory(mutant_xml_desc)

            distance_inputs = get_distance(self.digit.purified, rasterized_digit)

            if (TSHD_TYPE == '0'):
                if distance_inputs != 0:
                    condition = False
            elif (TSHD_TYPE == '1'):
                seed_image = DigitMutator.x_test[int(self.digit.seed)]
                xml_desc = vectorization_tools.vectorize(seed_image)
                seed = rasterization_tools.rasterize_in_memory(xml_desc)
                distance_seed = get_distance(seed, rasterized_digit)
                if distance_inputs != 0 and distance_seed <= DISTANCE and distance_seed != 0:
                    condition = False
            elif (TSHD_TYPE == '2'):
                seed = reshape(DigitMutator.x_test[int(self.digit.seed)])
                distance_seed = get_distance(seed, rasterized_digit)
                if distance_inputs != 0 and distance_seed <= DISTANCE_SEED and distance_seed != 0:
                    condition = False

        self.digit.xml_desc = mutant_xml_desc
        self.digit.purified = rasterized_digit
        self.digit.predicted_label = None
        self.digit.confidence = None
コード例 #3
0
    def __init__(self, basepath):
        super(DeepHyperionSample, self).__init__(basepath)

        # Load the metadata (json) file and the files to compute the features (xml, svg)
        npy_path = basepath + ".npy"
        json_path = basepath + ".json"
        svg_path = basepath + ".svg"

        with open(json_path) as jf:
            json_data = json.load(jf)

        self.image = np.load(npy_path)

        if os.path.exists(svg_path):
            self.approximated_model = False

            with open(svg_path, 'r') as input_file:
                self.xml_desc = input_file.read()
        else:
            self.approximated_model = True
            self.xml_desc = vectorize(self.image)

        # Set Sample attributes
        self.id = json_data["id"]
        self.tool = json_data["tool"]
        self.misbehaviour = json_data["misbehaviour"]
        self.run = json_data["run"]
        self.timestamp = json_data["timestamp"]
        self.elapsed = json_data["elapsed"]

        # Compute the metrics, those are not available in the metadata json
        self.features["moves"] = metrics.move_distance(self.xml_desc)
        self.features["bitmaps"] = metrics.dark_bitmaps(self.image)
        self.features["orientation"] = metrics.orientation_calc(self.image)

        # Set MNistSample attributes
        self.performance = json_data["performance"]
        self.predicted_label = json_data["predicted_label"]
        self.expected_label = json_data["expected_label"]
        self.seed = json_data["seed"]

        # Store to file besides the input json
        self.dump()
コード例 #4
0
    def __init__(self, basepath):
        super(DLFuzzSample, self).__init__(basepath)

        # Load the metadata (json) file and the files to compute the features (xml, npy)
        npy_path = basepath + ".npy"
        # TODO Does this have to be an instance attribute? Maybe we can remove it after we compute the features?
        self.image = np.load(npy_path)
        json_path = basepath + ".json"
        with open(json_path) as jf:
            json_data = json.load(jf)
        try:
            # TODO Does this have to be an instance attribute? Maybe we can remove it after we compute the features?
            self.xml_desc = json_data["xml_desc"]
            # TODO Does this have to be an instance attribute? Maybe we can remove it after we compute the features?
            self.approximated_model = False
        except KeyError:
            # TODO Does this have to be an instance attribute? Maybe we can remove it after we compute the features?
            self.xml_desc = vectorize(self.image)
            # TODO Does this have to be an instance attribute? Maybe we can remove it after we compute the features?
            self.approximated_model = True

        # Set Sample attributes
        self.id = json_data["id"]
        self.tool = json_data["tool"]
        self.misbehaviour = json_data["misbehaviour"]
        self.run = json_data["run"]
        self.timestamp = json_data["timestamp"]
        self.elapsed = json_data["elapsed"]
        # Compute the metrics, those are not available in the metadata json
        self.features["moves"] = metrics.move_distance(self.xml_desc)
        self.features["bitmaps"] = metrics.dark_bitmaps(self.image)
        self.features["orientation"] = metrics.orientation_calc(self.image)

        # Set MNistSample attributes
        self.performance = json_data["performance"]
        self.predicted_label = json_data["predicted_label"]
        self.expected_label = json_data["expected_label"]
        self.seed = json_data["seed"]

        # Store to file besides the input json
        self.dump()
コード例 #5
0
def generate_digit(seed):
    seed_image = x_test[int(seed)]
    xml_desc = vectorization_tools.vectorize(seed_image)
    return Digit(xml_desc, EXPECTED_LABEL, seed)