How to use the deepforest.preprocess 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 / tests / test_preprocess.py View on Github external
def test_compute_windows(config, numpy_image):
    windows = preprocess.compute_windows(numpy_image, config["patch_size"], config["patch_overlap"])
    assert len(windows) == 9
github weecology / DeepForest / tests / test_tfrecords.py View on Github external
print("Configuring tfrecord tests")
    config = {}
    config["patch_size"] = 200
    config["patch_overlap"] = 0.05
    config["annotations_xml"] = get_data("OSBS_029.xml")
    config["rgb_dir"] = "tests/data"
    config["annotations_file"] = "tests/data/OSBS_029.csv"
    config["path_to_raster"] =get_data("OSBS_029.tif")
    config["image-min-side"] = 800
    config["backbone"] = "resnet50"
    
    #Create a clean config test data
    annotations = utilities.xml_to_annotations(xml_path=config["annotations_xml"])
    annotations.to_csv("tests/data/testtfrecords_OSBS_029.csv",index=False)
    
    annotations_file = preprocess.split_raster(path_to_raster=config["path_to_raster"],
                                                        annotations_file="tests/data/testtfrecords_OSBS_029.csv",
                                                        base_dir= "tests/data/",
                                                        patch_size=config["patch_size"],
                                                        patch_overlap=config["patch_overlap"])
    
    annotations_file.to_csv("tests/data/testfile_tfrecords.csv", index=False,header=False)
    return config
github weecology / DeepForest / tests / test_preprocess.py View on Github external
def test_split_raster_empty(config):
    #Blank annotations file
    blank_annotations = pd.DataFrame({"image_path":"OSBS_029.tif","xmin":[""],"ymin":[""],"xmax":[""],"ymax":[""],"label":[""]})
    blank_annotations.to_csv("tests/data/blank_annotations.csv",index=False)
    
    #Ignore blanks
    annotations_file = preprocess.split_raster(config["path_to_raster"], "tests/data/blank_annotations.csv", "tests/data/",config["patch_size"], config["patch_overlap"], allow_empty=False)
    assert annotations_file.shape[0] == 0
    
    #Include blanks
    annotations_file = preprocess.split_raster(config["path_to_raster"], "tests/data/blank_annotations.csv", "tests/data/",config["patch_size"], config["patch_overlap"], allow_empty=True)
    assert annotations_file.shape[0] > 0
github weecology / DeepForest / deepforest / deepforest.py View on Github external
Args:
            raster_path: Path to image on disk
            iou_threshold: Minimum iou overlap among predictions between windows to be supressed. Defaults to 0.5. Lower values suppress more boxes at edges.
            return_plot: Should the image be returned with the predictions drawn?
    
        Returns:
            boxes (array): if return_plot, an image. Otherwise a numpy array of predicted bounding boxes, scores and labels
        """   
    
        #Load raster as image
        raster = Image.open(path_to_raster)
        numpy_image = np.array(raster)        
        image_name = os.path.basename(path_to_raster)
    
        #Compute sliding window index
        windows = preprocess.compute_windows(numpy_image, patch_size,patch_overlap)
    
        #Save images to tmpdir
        predicted_boxes = []
    
        for index, window in enumerate(windows):
            #Crop window and predict
            crop = numpy_image[windows[index].indices()] 
    
            #Crop is RGB channel order, change to BGR
            crop = crop[...,::-1]
            boxes = self.predict_image(raw_image=crop, return_plot=False, score_threshold=self.config["score_threshold"])            
    
            #transform coordinates to original system
            xmin, ymin, xmax, ymax = windows[index].getRect()
            boxes.xmin = boxes.xmin + xmin
            boxes.xmax = boxes.xmax + xmin