def __init__(self, parent): super(SplitDialog, self).__init__(parent) self.images_directory = '' self.annotations_file = '' self.last_directory = os.path.expanduser("~") self.current_directory = '' self.train_validation_split = 0.5 self.splitter = DatasetSplitter()
class testDatasetSplitter(unittest.TestCase): def setUp(self): self.target = DatasetSplitter() def testSplitUnionIsEqualToTotal(self): items = range(15) result = self.target.split(items, [.6,.2,.2]) aggregated_result = numpy.concatenate(result).tolist() self.assertEqual(sorted(aggregated_result), sorted(items)) def testSplitIntersectionIsEmpty(self): items = range(15) result = self.target.split(items, [.6,.2,.2]) self.assertEqual(0, len(numpy.intersect1d(result[0], result[1]))) self.assertEqual(0, len(numpy.intersect1d(result[1], result[2]))) self.assertEqual(0, len(numpy.intersect1d(result[0], result[2])))
class testDatasetSplitter(unittest.TestCase): def setUp(self): self.target = DatasetSplitter() def testSplitUnionIsEqualToTotal(self): items = range(15) result = self.target.split(items, [.6, .2, .2]) aggregated_result = numpy.concatenate(result).tolist() self.assertEqual(sorted(aggregated_result), sorted(items)) def testSplitIntersectionIsEmpty(self): items = range(15) result = self.target.split(items, [.6, .2, .2]) self.assertEqual(0, len(numpy.intersect1d(result[0], result[1]))) self.assertEqual(0, len(numpy.intersect1d(result[1], result[2]))) self.assertEqual(0, len(numpy.intersect1d(result[0], result[2])))
class SplitDialog(QDialog): def __init__(self, parent): super(SplitDialog, self).__init__(parent) self.images_directory = '' self.annotations_file = '' self.last_directory = os.path.expanduser("~") self.current_directory = '' self.train_validation_split = 0.5 self.splitter = DatasetSplitter() def accept(self): if len(self.images_directory) == 0 or len(self.annotations_file) == 0: if len(self.images_directory) == 0: QMessageBox.information(self, "Images", "Set Images Folder!") elif len(self.annotations_file) == 0: QMessageBox.information(self, "Annotations", "Set Annotations File!") else: self.splitter.reset() if os.path.isdir(self.images_directory) and os.path.isfile( self.annotations_file): split = -2 split, self.current_directory = self.splitter.split_dataset( self.images_directory, self.annotations_file, self.train_validation_split) if split == 0: generated = False generated = self.splitter.generate_annotations( self.annotations_file) if not generated: QMessageBox.information( self, "Annotations", "Annotation files were not generated for train and validation folders. Original annotaion file does not contain the section '_via_img_metadata'." % image_path) elif split == -1: QMessageBox.information( self, "Mask", "Image files corresponding to annotations were not found in %s." % self.images_directory) elif split == 1: QMessageBox.information( self, "Annotations", "The section '_via_img_metadata' was not found in the annotations file %s." % self.annotations_file) os.system("xdg-open '%s'" % self.current_directory) else: if not os.path.isdir(self.images_directory): QMessageBox.information( self, "Images", "Images Folder %s was not found." % self.images_directory) elif not os.path.isfile(self.annotations_file): QMessageBox.information( self, "Annotations", "Annotations file %s was not found." % self.annotations_file) super(SplitDialog, self).accept()
def setUp(self): self.target = DatasetSplitter()