Пример #1
0
    def monitor(self):
        html_path = os.path.join(os.getcwd(), "web_pages", "monitor.html")
        
        if self.best_fit != -1:
            # If there is a segmentor then display the images segmentation
            img = imageio.imread(self.rgb_filename)
            gmask = imageio.imread(self.label_filename)

            print(self.best_ind["params"])
            self.best_ind["params"]
            seg = Segmentors.algoFromParams(self.best_ind["params"])
            mask = seg.evaluate(img)

            static_dir = os.path.join(os.getcwd(), "public")
            imageio.imwrite(os.path.join(static_dir, "mask.jpg"), mask)

            code = GeneticSearch.print_best_algorithm_code(self.best_ind["params"])

            # Calculate progress bar precentage
            percentage = (1 - self.best_ind["fitness"]) * 100
            
            rounded_fitness = float("{0:.2f}".format(self.best_ind["fitness"]))

            data = ["", code, self.best_ind["params"], rounded_fitness, percentage]
        else:
            data = ['style="display:none;"', "", "", "",""]

        return fill_html_template(html_path, data)
def test_print_best_algorithm_code():
    """Unit test for print_best_algorithm_code function.
     Checks function output matches method contents it's printing."""
    individual = ['FB', 0, 0, 984, 0.09, 92, 0, 0, 0, 0, 0, 0, 0, 0, 0,\
     (1, 2), 0, "checkerboard", "checkerboard", 0, 0, 0, 0, 0, 0]
    print_statement = "multichannel = False\n\
if len(img.shape) > 2:\n\
    multichannel = True\n\
output = skimage.segmentation.felzenszwalb(\n\
    img,\n\
    984,\n\
    0.09,\n\
    92,\n\
    multichannel=multichannel,\n\
)\n"
    assert GeneticSearch.print_best_algorithm_code(individual) == print_statement
Пример #3
0
def update_code_display(n_intevals, currently_displayed_code):
    if has_results():
        return GeneticSearch.print_best_algorithm_code(best_ind["params"])
    else:
        return currently_displayed_code