import os from matplotlib import pyplot as plt if __name__ == '__main__': full_path = utils.get_path(in_or_out=utils.IN, data_fold=utils.TRAINING, full_dataset=True) xml_files = [f for f in os.listdir(full_path) if f.endswith('.xml')] roof_types = set() roof_polygons = dict() total_metal = 0 total_thatch = 0 total_tiled = 0 for xml_file in xml_files[:10]: img_name = xml_file[:-4] roof_polygons[img_name] = DataLoader.get_all_roofs_full_dataset( merge_tiled=True, xml_name=xml_file, xml_path=full_path) roof_types.update(roof_polygons[img_name].keys()) try: print full_path + img_name + '.jpg' image = cv2.imread(full_path + img_name + '.jpg') except IOError as e: print e sys.exit() for r, roof_type in enumerate(roof_polygons[img_name].keys()): if roof_type == 'thatch': color = (255, 0, 0) total_thatch += len(roof_polygons[img_name][roof_type]) elif roof_type == 'metal': color = (0, 255, 0)
def __init__(self, report_name=None, method=None, full_dataset=True, folder_name=None, save_imgs=True, out_path=None, detections=None, in_path=None, detector_names=None, mergeFalsePos=False, separateDetections=True, vocGood=0.1, negThres = 0.3, auc_threshold=0.5, correct_roofs=None, img_names=None): ''' Will score the detections class it contains. Parameters: -------------------- separateDetections: bool Whether the metal detections can count as true positives for the thatch detections and viceversa mergeFalsePos: bool Whether we need to keep track of the good and bad detections of metal and thatch separately or not. We cannot separate them if we want to train a single neural network to distinguish between both types of roofs since the bad detections of either roof must not contain a positive detection of the other type of roof (it should be background) ''' self.TOTAL = 0 self.save_imgs = save_imgs #these two are related to saving the FP and TP for neural training self.mergeFalsePos=mergeFalsePos self.auc_threshold = auc_threshold self.keep_detections_separate = separateDetections #threholds to classify detections as False/True positives and Good/Bad detections(these are to train the neural network on it) self.VOC_threshold = utils.VOC_threshold #threshold to assign a detection as a true positive self.VOC_good_detection_threshold = dict() self.VOC_good_detection_threshold['metal'] = utils.VOC_threshold self.VOC_good_detection_threshold['thatch'] = utils.VOC_threshold self.detection_portion_threshold = 0.50 self.negThres = negThres self.detections = detections self.in_path = in_path #the path from which the images are taken if img_names is None: self.img_names = [f for f in listdir(self.in_path) if f.endswith('.jpg')] else: self.img_names = img_names #the ground truth roofs for every image and roof type if correct_roofs is None: self.correct_roofs = dict() for roof_type in utils.ROOF_TYPES: self.correct_roofs[roof_type] = dict() self.full_dataset = full_dataset if full_dataset == False: for img_name in self.img_names: for roof_type in utils.ROOF_TYPES: #we receive polygons, so we convert them into boxes so we can use the fast scoring temp_roofs = DataLoader.get_polygons(roof_type=roof_type, xml_name=img_name[:-3]+'xml' , xml_path=self.in_path) if len(temp_roofs)>0: self.correct_roofs[roof_type][img_name] = utils.polygons2boxes(temp_roofs) else: self.correct_roofs[roof_type][img_name] = [] self.detections.update_roof_num(self.correct_roofs[roof_type][img_name], roof_type) else: for img_name in self.img_names: current_roofs = DataLoader.get_all_roofs_full_dataset(xml_name=img_name[:-3]+'xml' , xml_path=self.in_path) for roof_type in utils.ROOF_TYPES: if roof_type not in current_roofs: self.correct_roofs[roof_type][img_name] = [] else: self.correct_roofs[roof_type][img_name] = current_roofs[roof_type] self.detections.update_roof_num(self.correct_roofs[roof_type][img_name], roof_type) else: self.correct_roofs = correct_roofs #init the report file self.out_path = out_path if report_name is not None: if detector_names is not None: self.init_report(detector_names, report_name=report_name) #variables needed to pickle the FP and TP to a file that makes sense assert method is not None self.method = method self.folder_name = folder_name
def __init__(self, report_name=None, method=None, full_dataset=True, folder_name=None, save_imgs=True, out_path=None, detections=None, in_path=None, detector_names=None, mergeFalsePos=False, separateDetections=True, vocGood=0.1, negThres=0.3, auc_threshold=0.5, correct_roofs=None, img_names=None): ''' Will score the detections class it contains. Parameters: -------------------- separateDetections: bool Whether the metal detections can count as true positives for the thatch detections and viceversa mergeFalsePos: bool Whether we need to keep track of the good and bad detections of metal and thatch separately or not. We cannot separate them if we want to train a single neural network to distinguish between both types of roofs since the bad detections of either roof must not contain a positive detection of the other type of roof (it should be background) ''' self.TOTAL = 0 self.save_imgs = save_imgs #these two are related to saving the FP and TP for neural training self.mergeFalsePos = mergeFalsePos self.auc_threshold = auc_threshold self.keep_detections_separate = separateDetections #threholds to classify detections as False/True positives and Good/Bad detections(these are to train the neural network on it) self.VOC_threshold = utils.VOC_threshold #threshold to assign a detection as a true positive self.VOC_good_detection_threshold = dict() self.VOC_good_detection_threshold['metal'] = utils.VOC_threshold self.VOC_good_detection_threshold['thatch'] = utils.VOC_threshold self.detection_portion_threshold = 0.50 self.negThres = negThres self.detections = detections self.in_path = in_path #the path from which the images are taken if img_names is None: self.img_names = [ f for f in listdir(self.in_path) if f.endswith('.jpg') ] else: self.img_names = img_names #the ground truth roofs for every image and roof type if correct_roofs is None: self.correct_roofs = dict() for roof_type in utils.ROOF_TYPES: self.correct_roofs[roof_type] = dict() self.full_dataset = full_dataset if full_dataset == False: for img_name in self.img_names: for roof_type in utils.ROOF_TYPES: #we receive polygons, so we convert them into boxes so we can use the fast scoring temp_roofs = DataLoader.get_polygons( roof_type=roof_type, xml_name=img_name[:-3] + 'xml', xml_path=self.in_path) if len(temp_roofs) > 0: self.correct_roofs[roof_type][ img_name] = utils.polygons2boxes(temp_roofs) else: self.correct_roofs[roof_type][img_name] = [] self.detections.update_roof_num( self.correct_roofs[roof_type][img_name], roof_type) else: for img_name in self.img_names: current_roofs = DataLoader.get_all_roofs_full_dataset( xml_name=img_name[:-3] + 'xml', xml_path=self.in_path) for roof_type in utils.ROOF_TYPES: if roof_type not in current_roofs: self.correct_roofs[roof_type][img_name] = [] else: self.correct_roofs[roof_type][ img_name] = current_roofs[roof_type] self.detections.update_roof_num( self.correct_roofs[roof_type][img_name], roof_type) else: self.correct_roofs = correct_roofs #init the report file self.out_path = out_path if report_name is not None: if detector_names is not None: self.init_report(detector_names, report_name=report_name) #variables needed to pickle the FP and TP to a file that makes sense assert method is not None self.method = method self.folder_name = folder_name