Skip to main content

Prediction through DeepForest

Prediction

DeepForest allows the prediction of the new data with the prebuilt model or we can also use our custom trained models. 


Predict a single image

DeepForest allows to predict single images with predict_image function which can read an image from memory or file provided by user, which returns the bounding boxes of the predicted trees in image.

 
image_path = get_data("OSBS_029.png")
boxes = model.predict_image(path=image_path, return_plot = False)


 

 
boxes.head()
xmin ymin xmax ymax label scores
0 334.708405 342.333954 375.941376 392.187531 0 0.736650
1 295.990601 371.456604 331.521240 400.000000 0 0.714327
2 216.828201 207.996216 245.123276 240.167023 0 0.691064
3 276.206848 330.758636 303.309631 363.038422 0 0.690987
4 328.604736 45.947182 361.095276 80.635254 0 0.638212
 

The current DeepForest has release model there is a category named "Tree", which has the label as numeric 0 and there is also a bird release model which has the label as numeric 1.

Predict a tile

Large tiles covering large geographic areas will not fit in memory during prediction, and results will be poor due to the density of bounding boxes. Remote sensing data is typically provided as a geospatial .tif file and is best suited for the predict_tile function, which divides the tile into overlapping windows, performs predictions on each window, and reassembles the resulting annotations.

 
raster_path = get_data("OSBS_029.tif")
# Window size of 300px with an overlap of 25% among windows for this small tile.
predicted_raster = model.predict_tile(raster_path, return_plot = True, 
                                              patch_size=300,patch_overlap=0.25)
 

 

Predict a set of annotations

When evaluating ground truth data, it is helpful to predict a sequence of images and combine them into a data frame. The predict_generator method allows the user to point to an annotated file and return predictions for all images. The image path is a relative path to the root dir. What we generally do is save the .csv file alongside the images.

 
csv_file = get_data("testfile_deepforest.csv")
boxes = model.predict_file(csv_file=csv_file, 
                                root_dir = os.path.dirname(csv_file),savedir=".")
 


We can also customize the appeaance of bounding box created like color and thickness by providing these arguments a value while calling predict_image function.

 
image_path = get_data("OSBS_029.png")
boxes = model.predict_image(path=image_path, return_plot = True, 
                                               color=(0, 165, 255), thickness=3)
 

 

Comments

Popular posts from this blog

GSoC Final Report

GSoC Final Report My journey on the Google Summer of Code project passed by so fast, A lot of stuff happened during those three months, and as I’m writing this blog post, I feel quite nostalgic about these three months. GSoC was indeed a fantastic experience. It gave me an opportunity to grow as a developer in an open source community and I believe that I ended up GSoC with a better understanding of what open source is. I learned more about the community, how to communicate with them, and who are the actors in this workflow. So, this is a summary report of all my journey at GSoC 2022. Name : Ansh Dassani Organization:   NumFOCUS- Data Retriever Project title : Training and Evaluation of model on various resolutions Project link:  DeepForest Mentors :  Ben Weinstein ,  Henry Senyondo , Ethan White Introduction                                        DeepForest is a pytho...

Creating flutter packages

  How to create Dart packages for Flutter In Flutter, we use the Dart programming language to build cross-platform applications. Dart packages are like the libraries you might be used to installing for, say, Node.js projects using either npm or yarn. These packages are built by Flutter devs for Flutter devs. In this tutorial, we’ll show you how to build Dart packages and share them with other Flutter developers around the world. We’ll cover the following with practical examples: What is a Dart package? Flutter project requirements Dart package types Creating a Flutter/Dart package Initializing a Git repo Writing a Flutter widget Testing your Flutter package Publishing and sharing your Flutter package What is a Dart package? Dart packages help us solve issues and create workarounds for problems without having to write the code ourselves from scratch. For example, let’s say we’re building a Flutter app and we discover that we need to upload a picture from our local filesystem and dis...

Evaluation of predicted data

Evaluation of predicted data To convert the overlap between predicted bounding boxes and ground truth bounding boxes into a measure of accuracy and precision, the most common approach is to compare the overlap using the Intersection over Union (IoU) metric. IoU is the ratio of the overlap area of ​​the predicted polygon box with the ground truth polygon box divided by the area of ​​the combined bounding box. The IoU metric ranges from 0 which is not overlapping at all to 1 which is totally overlapping. In the wider computer vision literature, the common overlap threshold is 0.5, but this value is arbitrary and ultimately irrelevant to any particular ecological problem. We treat boxes with an IoU score greater than 0.4 as true positives, and boxes with scores less than 0.4 as false negatives. A value of 0.4 was chosen for threshold-based visual assessment, which indicates good visual agreement between predicted and observed crowns. We tested a range of overlap thresholds from 0.3 (less ...