How to use the deepforest.predict function in deepforest

To help you get started, we’ve selected a few deepforest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github weecology / DeepForest / deepforest / deepforest.py View on Github external
#Check the formatting
        if isinstance(image_path,np.ndarray):
            raise ValueError("image_path should be a string, but is a numpy array. If predicting a loaded image (channel order BGR), use raw_image argument.")
        
        #Check for correct formatting
        #Warning if image is very large and using the release model
        if raw_image is None:
            raw_image = cv2.imread(image_path)    
        
        if self.__release_version__ :
            if any([x > 400 for x in raw_image.shape[:2]]):
                warnings.warn("Input image has a size of {}, but the release model was trained on crops of 400px x 400px, results may be poor."
                              "Use predict_tile for dividing large images into overlapping windows.".format(raw_image.shape[:2]))
        
        #Predict
        prediction = predict.predict_image(self.prediction_model, image_path=image_path, raw_image=raw_image, return_plot=return_plot, score_threshold=score_threshold, color=color)            
            
        #cv2 channel order to matplotlib order
        if return_plot & show:
            plt.imshow(prediction[:,:,::-1])
            plt.show()             

        return prediction
github weecology / DeepForest / deepforest / deepforest.py View on Github external
#transform coordinates to original system
            xmin, ymin, xmax, ymax = windows[index].getRect()
            boxes.xmin = boxes.xmin + xmin
            boxes.xmax = boxes.xmax + xmin
            boxes.ymin = boxes.ymin + ymin
            boxes.ymax = boxes.ymax + ymin
    
            predicted_boxes.append(boxes)
    
        predicted_boxes = pd.concat(predicted_boxes)
    
        #Non-max supression for overlapping boxes among window 
        with tf.Session() as sess:
            print("{} predictions in overlapping windows, applying non-max supression".format(predicted_boxes.shape[0]))
            new_boxes, new_scores, new_labels = predict.non_max_suppression(sess,
                                                                                predicted_boxes[["xmin","ymin","xmax","ymax"]].values,
                                                                                predicted_boxes.score.values, predicted_boxes.label.values,
                                                                                max_output_size=predicted_boxes.shape[0],
                                                                                iou_threshold=iou_threshold)
    
            image_detections = np.concatenate([new_boxes, np.expand_dims(new_scores, axis=1), np.expand_dims(new_labels, axis=1)], axis=1)
            mosaic_df = pd.DataFrame(image_detections,columns=["xmin","ymin","xmax","ymax","score","label"])
            mosaic_df.label = mosaic_df.label.str.decode("utf-8")
            print("{} predictions kept after non-max suppression".format(mosaic_df.shape[0]))
    
        if return_plot:
            #Draw predictions
            for box in mosaic_df[["xmin","ymin","xmax","ymax"]].values:
                draw_box(numpy_image, box, [0,0,255])
    
            return numpy_image