Beispiel #1
0
    def __init__(self,filename_weights,path_root,obj_threshold=0.5):
        config = InferenceConfig()
        self.model = detector_Mask_RCNN_core.MaskRCNN(mode="inference", model_dir=path_root, config=config)
        self.model.load_weights(filename_weights, by_name=True)
        self.class_names = ['BG']+tools_YOLO.get_COCO_class_names()
        self.colors = tools_YOLO.generate_colors(len(self.class_names) - 1)
        self.colors.insert(0, self.colors[-1])
        self.obj_threshold = obj_threshold

        return
Beispiel #2
0
def plot_mAP_overlap(folder_annotation,
                     file_markup_true,
                     file_markup_pred,
                     filename_meta,
                     folder_out,
                     out_prefix='',
                     delim=' '):

    input_image_size, class_names, anchors, anchor_mask, obj_threshold, nms_threshold = tools_YOLO.load_metadata(
        filename_meta)
    colors = tools_YOLO.generate_colors(len(class_names))

    ovp_ths = [0.9, 0.8, 0.7, 0.6, 0.5, 0.1]
    ovd_ths = [0.1, 0.2, 0.5, 0.99]
    results = []
    for ovp_th in ovp_ths:
        out_dir = folder_out + 'ovp_%02d/' % int(ovp_th * 100)
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
        for ovd_th in ovd_ths:

            precisions, recalls, confidences, class_IDs = get_precsion_recall_data_from_markups(
                folder_annotation,
                file_markup_true,
                file_markup_pred,
                None,
                ovp_th,
                ovd_th,
                delim=delim)
            mAP = 0

            for i, class_ID in enumerate(class_IDs):
                if len(precisions[i]) > 1:
                    xxx = numpy.array(
                        [precisions[i], recalls[i], confidences[i]]).T
                    filename_out = out_dir + out_prefix + 'OVD_%02d_AP_%02d_%s.txt' % (
                        int(ovd_th * 100), class_ID, class_names[class_ID])
                    tools_IO.save_mat(xxx, filename_out)
                    filename_out = out_dir + out_prefix + 'OVD_%02d_AP_%02d_%s.png' % (
                        int(ovd_th * 100), class_ID, class_names[class_ID])
                    AP = write_precision_recall(
                        filename_out,
                        precisions[i],
                        recalls[i],
                        caption='ovp %1.2f ovd %1.2f ' % (ovp_th, ovd_th) +
                        class_names[class_ID],
                        color=(colors[class_ID][2] / 255.0,
                               colors[class_ID][1] / 255.0,
                               colors[class_ID][0] / 255.0))
                    mAP += AP

            results.append(mAP / len(class_IDs))

    return results[0]
Beispiel #3
0
    def __init__(self, filename_topology, obj_threshold=0.5):
        self.obj_threshold = obj_threshold

        self.class_names = ['BG'] + tools_YOLO.get_COCO_class_names()
        self.colors = tools_YOLO.generate_colors(len(self.class_names) - 1)
        self.colors.insert(0, self.colors[-1])

        with tf.gfile.FastGFile(filename_topology, 'rb') as f:
            self.graph_def = tf.GraphDef()
            self.graph_def.ParseFromString(f.read())
        return
Beispiel #4
0
def plot_mAP_iou(folder_annotation,
                 file_markup_true,
                 file_markup_pred,
                 filename_meta,
                 folder_out,
                 out_prefix='',
                 delim=' '):

    input_image_size, class_names, anchors, anchor_mask, obj_threshold, nms_threshold = tools_YOLO.load_metadata(
        filename_meta)
    colors = tools_YOLO.generate_colors(len(class_names))

    iuo_ths = [0.5, 0.3, 0.1, 0.01]
    results = []
    for iuo_th in iuo_ths:
        ovp_th, ovd_th = None, None
        out_dir = folder_out + 'iou_%02d/' % int(iuo_th * 100)
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)

        precisions, recalls, confidences, class_IDs = get_precsion_recall_data_from_markups(
            folder_annotation,
            file_markup_true,
            file_markup_pred,
            iuo_th,
            ovp_th,
            ovd_th,
            delim=delim)
        mAP = 0

        for i, class_ID in enumerate(class_IDs):
            if len(precisions[i]) > 1:
                filename_out = out_dir + out_prefix + 'AP_%02d_%s.png' % (
                    class_ID, class_names[class_ID])
                AP = write_precision_recall(
                    filename_out,
                    precisions[i],
                    recalls[i],
                    caption='iou %1.2f ' % iuo_th + class_names[class_ID],
                    color=(colors[class_ID][2] / 255.0,
                           colors[class_ID][1] / 255.0,
                           colors[class_ID][0] / 255.0))
                mAP += AP

        results.append(mAP / len(class_IDs))
        print(out_prefix, iuo_th, mAP / len(class_IDs))

    print()

    return results[0]
Beispiel #5
0
    def init_tiny(self, default_weights_h5, num_classes):

        self.input_image_size, self.class_names, self.anchors, self.anchor_mask, self.obj_threshold, self.nms_threshold = tools_YOLO.init_default_metadata_tiny(
            num_classes)
        self.colors = tools_YOLO.generate_colors(len(self.class_names))
        self.input_tensor_shape = K.placeholder(shape=(2, ))
        self.sess = K.get_session()
        self.model = detector_YOLO3_core.yolo_body_tiny(
            Input(shape=(None, None, 3)), 3, num_classes)
        default_model = load_model(default_weights_h5, compile=False)
        detector_YOLO3_core.assign_weights(default_model, self.model)

        self.boxes, self.scores, self.classes = detector_YOLO3_core.get_tensors_box_score_class(
            self.model.output,
            self.anchors,
            self.anchor_mask,
            len(self.class_names),
            self.input_tensor_shape,
            score_threshold=self.obj_threshold,
            iou_threshold=self.nms_threshold)

        return
Beispiel #6
0
    def __load_model(self,
                     model_weights_h5,
                     filename_metadata,
                     obj_threshold=None):

        self.input_image_size, self.class_names, self.anchors, self.anchor_mask, self.obj_threshold, self.nms_threshold = tools_YOLO.load_metadata(
            filename_metadata)
        if obj_threshold is not None: self.obj_threshold = obj_threshold
        self.colors = tools_YOLO.generate_colors(len(self.class_names))
        self.input_tensor_shape = K.placeholder(shape=(2, ))
        self.sess = K.get_session()

        self.model = load_model(model_weights_h5, compile=False)

        self.boxes, self.scores, self.classes = detector_YOLO3_core.get_tensors_box_score_class(
            self.model.output,
            self.anchors,
            self.anchor_mask,
            len(self.class_names),
            self.input_tensor_shape,
            score_threshold=self.obj_threshold,
            iou_threshold=self.nms_threshold)

        return
Beispiel #7
0
def generate_colors(N):
    return tools_YOLO.generate_colors(N)