def __load_data(self, cache_all_annotations):
        # Load image list from dir ...
        self.img_list = ImageInfo.ListChartDirectory(self.img_dir, "")
        self.auto_check_stats = {
            "total_no_annotation": 0,
            "total_multi_panel": 0,
            "total_no_test": 0,
            "total_passed": 0,
            "total_failed": 0,
        }

        for idx, chart_path in enumerate(self.img_list):
            current_img = None

            # find annotation path ...
            relative_dir, img_filename = os.path.split(chart_path)

            img_base, ext = os.path.splitext(img_filename)
            # output dir
            output_dir = self.annotation_dir + relative_dir
            annotation_filename = output_dir + "/" + img_base + ".xml"

            if os.path.exists(annotation_filename):
                self.img_annotations.append(annotation_filename)
                self.total_annotation_files += 1

                image_info = ImageInfo.FromXML(annotation_filename,
                                               current_img)
                if len(image_info.panels) == 1:
                    # add to single panel index
                    self.all_single_panel.append(idx)

                    type_desc, orientation = image_info.panels[
                        0].get_description()
                    if orientation == "":
                        current_type = type_desc
                    else:
                        current_type = "{0:s} ({1:s})".format(
                            type_desc, orientation)
                    # if type_desc in ["non-chart"]:
                    #     print(annotation_filename)

                    status_ints = ImageInfo.GetAllStatuses(image_info)
                    self.img_statuses.append(status_ints)

                    if current_type in self.single_per_type:
                        self.single_per_type[current_type].append(
                            (idx, status_ints))
                    else:
                        self.single_per_type[current_type] = [(idx,
                                                               status_ints)]

                    if not "auto_check_passed" in image_info.panels[
                            0].properties:
                        self.auto_check_stats["total_no_test"] += 1
                    else:
                        if int(image_info.panels[0].
                               properties["auto_check_passed"]) > 0:
                            self.auto_check_stats["total_passed"] += 1
                        else:
                            self.auto_check_stats["total_failed"] += 1
                else:
                    # add to multi-panel index
                    self.all_multi_panel.append(idx)
                    # TODO: multi-panel case is not handled yet ...

                    self.img_statuses.append(None)
                    self.auto_check_stats["total_multi_panel"] += 1

                # keep or discard the current annotation ...
                if cache_all_annotations:
                    self.cache_annotations.append(image_info)
                else:
                    self.cache_annotations.append(None)
            else:
                self.img_annotations.append(None)
                self.cache_annotations.append(None)
                self.img_statuses.append(ImageInfo.GetNullStatuses())
                self.auto_check_stats["total_no_annotation"] += 1
예제 #2
0
    def __init__(self, img_dir, annotation_dir, cache_all_annotations=False):

        self.img_dir = img_dir
        self.annotation_dir = annotation_dir

        # Load image list from dir ...
        self.img_list = ImageInfo.ListChartDirectory(img_dir, "")

        self.total_annotation_files = 0

        self.img_annotations = []
        self.cache_annotations = []
        self.img_statuses = []

        self.all_single_panel = []
        self.all_multi_panel = []
        self.single_per_type = {}

        for idx, chart_path in enumerate(self.img_list):
            current_img = None

            # find annotation path ...
            relative_dir, img_filename = os.path.split(chart_path)

            img_base, ext = os.path.splitext(img_filename)
            # output dir
            output_dir = self.annotation_dir + relative_dir
            annotation_filename = output_dir + "/" + img_base + ".xml"

            if os.path.exists(annotation_filename):
                self.img_annotations.append(annotation_filename)
                self.total_annotation_files += 1

                image_info = ImageInfo.FromXML(annotation_filename,
                                               current_img)
                if len(image_info.panels) == 1:
                    # add to single panel index
                    self.all_single_panel.append(idx)

                    type_desc, orientation = image_info.panels[
                        0].get_description()
                    if orientation == "":
                        current_type = type_desc
                    else:
                        current_type = "{0:s} ({1:s})".format(
                            type_desc, orientation)

                    status_ints = ImageInfo.GetAllStatuses(image_info)
                    self.img_statuses.append(status_ints)

                    if current_type in self.single_per_type:
                        self.single_per_type[current_type].append(
                            (idx, status_ints))
                    else:
                        self.single_per_type[current_type] = [(idx,
                                                               status_ints)]

                else:
                    # add to multi-panel index
                    self.all_multi_panel.append(idx)
                    # TODO: multi-panel case is not handled yet ...

                    self.img_statuses.append(None)
                # keep or discard the current annotation ...
                if cache_all_annotations:
                    self.cache_annotations.append(image_info)
                else:
                    self.cache_annotations.append(None)
            else:
                self.img_annotations.append(None)
                self.cache_annotations.append(None)
                self.img_statuses.append(ImageInfo.GetNullStatuses())