def test_get_img_name_and_img_path_from_text_filename(self): coco_reader = CocoDatasetReader() labels_folder_path = os.path.join(self.dataset_name, 'train_labels') images_folder_path = os.path.join(self.dataset_name, 'train_images') text_path = load_text_paths(labels_folder_path)[0] coco_reader._save_to_instance_folder_paths(self.dataset_name) image_filepath, image_filename = coco_reader._get_img_name_and_img_path_from_text_filename( text_path) self.assertEqual(image_filepath in load_images(images_folder_path), True)
def test_read_text(self): coco_reader = CocoDatasetReader() labels_folder_path = os.path.join(self.dataset_name, 'train_labels') images_folder_path = os.path.join(self.dataset_name, 'train_images') text_path = load_text_paths(labels_folder_path)[0] coco_reader._save_to_instance_folder_paths(self.dataset_name) data_in_output_format, _ = coco_reader._read_text( text_path, ["test", "test"]) self.assertEqual(len(data_in_output_format['boxes']) > 0, True) self.assertEqual(len(data_in_output_format['labels']) > 0, True) self.assertEqual(len(data_in_output_format['boxes']), len(data_in_output_format['labels']))
def test_txt_file_to_image(self): images = load_images_names(self.images_path) folder_txts = load_text_paths(self.annotations_path) folder_txts.sort() txts_form_images_names = [] for image in images: label_txt_filename = image + '.txt' label_txt_filepath = os.path.join(self.annotations_path, label_txt_filename) txts_form_images_names.append(label_txt_filepath) txts_form_images_names.sort() self.assertEqual(txts_form_images_names == folder_txts, True)
def _extract_data_from_annotations_folder( self, output_data_in_universa_od_format): """ Method that extract data form annotations folder. :param output_data_in_universa_od_format: dict in universal object detection format without annotations :type output_data_in_universa_od_format: dict :return: dict in universal object detection format with annotations :rtype: dict """ txts_paths = load_text_paths(self.annotations_folder_path) uniq_dataset_classes = [] uniq_dataset_classes = self._load_dataset_classes_names() objects = [] for text_path in txts_paths: text_object_dict, uniq_dataset_classes = self._read_text( text_path, uniq_dataset_classes) objects.append(text_object_dict) output_data_in_universa_od_format.update({'objects': objects}) uniq_dataset_classes = self._format_dataset_classes( uniq_dataset_classes) output_data_in_universa_od_format.update( {'dataset_classes': uniq_dataset_classes}) return output_data_in_universa_od_format
def test_text_paths_loading(self): coco_reader = CocoDatasetReader() coco_reader._test_structure_exist(self.dataset_name) texts = load_text_paths(coco_reader.annotations_folder_path) self.assertEqual(len(texts) > 0, True)