コード例 #1
0
ファイル: custom_train.py プロジェクト: syleo22/Xtreme-Vision
    def evaluate_model(self, model_path, iou_threshold = 0.5):
        self.model = MaskRCNN(mode = "inference", model_dir = os.getcwd(), config = self.config)  
        if os.path.isfile(model_path):
            model_files = [model_path]
             
        if os.path.isdir(model_path):
            model_files = sorted([os.path.join(model_path, file_name) for file_name in os.listdir(model_path)])
        for modelfile in model_files:
            if str(modelfile).endswith(".h5"):
                self.model.load_weights(modelfile, by_name=True)
            APs = []
            #outputs = list()
            for image_id in self.dataset_test.image_ids:                                                                                                                                                                                                                                                                                                                                                                             
                # load image, bounding boxes and masks for the image id
                image, image_meta, gt_class_id, gt_bbox, gt_mask = load_image_gt(self.dataset_test, self.config, image_id)
                # convert pixel values (e.g. center)
                scaled_image = mold_image(image, self.config)
                # convert image into one sample
                sample = np.expand_dims(scaled_image, 0)
		        # make prediction
                yhat = self.model.detect(sample, verbose=0)
		        # extract results for first sample
                r = yhat[0]
		        # calculate statistics, including AP
                AP, _, _, _ = compute_ap(gt_bbox, gt_class_id, gt_mask, r["rois"], r["class_ids"], r["scores"], r['masks'])
		        # store
                APs.append(AP)
	        # calculate the mean AP across all images
            mAP = np.mean(APs)
            print(modelfile, "evaluation using iou_threshold", iou_threshold, "is", f"{mAP:01f}", '\n')
コード例 #2
0
 def load_model(self, model_path):
     self.model = MaskRCNN(mode="inference",
                           model_dir=self.model_dir,
                           config=coco_config)
     self.model.load_weights(model_path, by_name=True)
コード例 #3
0
 def load_model(self, model_path):
     #load the weights for COCO
     self.model = MaskRCNN(mode="inference",
                           model_dir=self.model_dir,
                           config=self.config)
     self.model.load_weights(model_path, by_name=True)