예제 #1
0
 def load_kernel(self) -> None:
     """ Load the metadate before training. """
     self.classes = set()
     for sample_id in tqdm(self.sample_ids):
         try:
             image_path = get_image_local_path(sample_id, self.DIR_PATH)
             image = read_image(image_path)
             # print(f"image shape {image.shape}")
             annotation_path = get_xml_local_path(sample_id, self.DIR_PATH)
             annotations, image_shape = load_xml(annotation_path)
             _, class_labels = convert_annotations(annotations, image_shape)
             if (len(class_labels) == 0):
                 print(f'Skip sample {sample_id}, no gt_objects')
                 continue
             for class_label in class_labels:
                 self.classes.update({class_label})
             self.add_image(
                 source=self.source,
                 image_id=sample_id,
                 sub_class_label="BloodCell",
                 path=image_path,
                 image_size=image.shape,
             )
         except Exception as e:
             print(f'EXCP: {e} during handling {sample_id}')
             continue
     for i, c in enumerate(list(self.class_names_preset[1:])):
         self.add_class(self.source, i + 1, c)
     self.prepare()
     return
예제 #2
0
 def load_image(self, image_id, zero_image=False):
     """ Load the images during training. """
     info = self.image_info[image_id]
     image_id = info['id']
     image_path = get_image_local_path(image_id, self.DIR_PATH)
     image = read_image(image_path)
     return image
 def load_kernel(self) -> None:
     """ Load the metadate before training. """
     self.classes = set()
     for sample_id in tqdm(self.sample_ids):
         try:
             image_path = get_image_local_path(sample_id, self.DIR_PATH)
             image = read_image(image_path)
             annotation_path = get_json_local_path(sample_id, self.DIR_PATH)
             with open(annotation_path) as f:
                 annotations = json.load(f)
             if (len(annotations["objects"]) == 0):
                 print(f'Skip sample {sample_id}, no gt_objects')
                 continue
             for obj in annotations["objects"]:
                 self.classes.update({obj["classTitle"]})
             self.add_image(
                 source=self.source,
                 image_id=sample_id,
                 sub_class_label="ConstructionSite",
                 path=image_path,
                 image_size=image.shape,
             )
         except Exception as e:
             print(f'EXCP: {e} during handling {sample_id}')
             continue
     for i, c in enumerate(list(self.class_names_preset[1:])):
         self.add_class(self.source, i + 1, c)
     self.prepare()
     return
예제 #4
0
 def load_image(self, image_id, zero_image=False):
     """ Load the images during training. """
     info = self.image_info[image_id]
     image_id = info['id']
     origin = info['origin']
     if origin == "A":
         image_path = get_image_local_path(image_id, self.DIR_PATH_A)
     elif origin == "B":
         image_path = get_image_local_path_B(image_id, self.DIR_PATH_B)
     image = read_image(image_path)
     return image
예제 #5
0
 def load_kernel(self) -> None:
     """ Load the metadate before training. """
     self.classes = set()
     for i, row in self.df.iterrows():
         try:
             sample_id = row["sample_id"]
             WBC_type = row["WBC_types"]
             origin = row["origin"]
             if origin == "A":
                 image_path = get_image_local_path(sample_id,
                                                   self.DIR_PATH_A)
                 image = read_image(image_path)
                 annotation_path = get_xml_local_path(
                     sample_id, self.DIR_PATH_A)
                 annotations, image_shape = load_xml(annotation_path)
                 masks, class_labels = convert_annotations(
                     annotations, image_shape)
                 class_labels = [
                     correct_class_label(l, WBC_type) for l in class_labels
                 ]
             elif origin == "B":
                 image_path = get_image_local_path_B(
                     sample_id, self.DIR_PATH_B)
                 image = read_image(image_path)
                 mask = read_image(
                     get_mask_local_path_B(sample_id, self.DIR_PATH_B))
                 masks = mask[..., 0:1]
                 class_labels = WBC_type
             # print(class_labels)
             if (len(class_labels) == 0):
                 print(f'Skip sample {sample_id}, no gt_objects')
                 continue
             for class_label in class_labels:
                 self.classes.update({class_label})
             self.add_image(
                 source=self.source,
                 origin=origin,
                 image_id=sample_id,
                 sub_class_label=WBC_type,
                 path=image_path,
                 image_size=image.shape,
             )
         except Exception as e:
             print(f'EXCP: {e} during handling {sample_id}')
             continue
     for i, c in enumerate(list(self.class_names_preset[1:])):
         self.add_class(self.source, i + 1, c)
     self.prepare()
     return
    def load_kernel(self) -> None:
        """ Load the dataset before inference. """
        self.classes = set()
        for sample_id in tqdm(self.sample_ids):
            try:
                image_path = get_image_local_path(sample_id, self.DIR_PATH)
                image = read_image(image_path)

                self.add_image(
                    source=self.source,
                    image_id=sample_id,
                    sub_class_label="ConstructionSite",
                    path=image_path,
                    image_size=image.shape,
                )
            except Exception as e:
                print(f'EXCP: {e} during handling {sample_id}')
                continue
        for i, c in enumerate(list(self.class_names_preset[1:])):
            self.add_class(self.source, i + 1, c)
        self.prepare()
        return