def run_analysis(): population_size = np.arange(start=25, stop=35, step=5) pixels_percentage_to_change = np.arange(start=0.4, stop=0.5, step=0.1) max_generation_count = [100] population_percentage_to_keep = np.arange(start=0.1,stop=0.3, step=0.1) mutation_prob = np.arange(start=0.4, stop=0.6, step=0.2) crossover_prob = np.arange(start=0.7, stop=0.8, step=0.1) all_params_combination = itertools.product(population_size, pixels_percentage_to_change, max_generation_count, population_percentage_to_keep, mutation_prob, crossover_prob) fake_img_generator = FakeImgGenerator(Utils.get_test_image_path(IMG_NAME), P_MAX, P_MIN, FAKE_CLASS_PROB_TO_GET) results = [] output_dir = Utils.get_new_output_dir() for i, c in enumerate(all_params_combination): print("Test generation set number: {}".format(i)) generation_result = fake_img_generator.run(population_size=c[0], pixels_percentage_to_change=c[1], max_generations_count=c[2], population_percentage_to_keep=c[3], mutation_prob=c[4], crossover_prob=c[5]) results.append(generation_result) result_path = Utils.create_child_dir(basepath=output_dir, child_dir="result_{}".format(str(i))) print("Result probability: {}".format(generation_result.get_last_probability())) generation_result.save(output_dir=result_path) _save_results_comparison(results, output_dir)
from src.FakeImgGenerator import FakeImgGenerator from src.Utils import Utils from Config import * if __name__ == '__main__': img_name = IMG_NAME img_path = Utils.get_test_image_path(img_name) p_max = P_MAX p_min = P_MIN fake_class_prob_to_get = FAKE_CLASS_PROB_TO_GET fake_img_generator = FakeImgGenerator(img_path, p_max, p_min, fake_class_prob_to_get) population_size = 30 pixels_percentage_to_change = 0.4 max_generations_count = 100 population_percentage_to_keep = 0.1 mutation_prob = 0.6 crossover_prob = 0.7 result = fake_img_generator.run(population_size, pixels_percentage_to_change, max_generations_count, population_percentage_to_keep, mutation_prob, crossover_prob) output_dir = Utils.get_new_output_dir() result.save(output_dir)