How do I use a pretrained model to predict an image?#
from deepforest import main
from deepforest import get_data
from deepforest.visualize import plot_results
# Initialize the model class
model = main.deepforest()
# Load a pretrained tree detection model from Hugging Face
model.load_model(model_name="weecology/deepforest-tree", revision="main")
sample_image_path = get_data("OSBS_029.png")
img = model.predict_image(path=sample_image_path)
plot_results(img)
Note
Please note that this video was made before the deepforest-pytorch -> deepforest name change.
For single images, predict_image can read an image from memory or file and return predicted bounding boxes.