Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check for empty frame, closes #839 #840

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/deepforest/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ def _predict_crop_model_(crop_model,
Returns:
The updated results dataframe with predicted labels and scores.
"""
if results.empty:
print("No predictions to run crop model on, returning empty dataframe")
return results

bounding_box_dataset = dataset.BoundingBoxDataset(
results,
root_dir=os.path.dirname(raster_path),
Expand Down
29 changes: 27 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def test_predict_image_fromarray(m):
prediction = m.predict_image(image=image)

assert isinstance(prediction, pd.DataFrame)
assert set(prediction.columns) == {"xmin", "ymin", "xmax", "ymax", "label", "score", "geometry"}
assert set(prediction.columns) == {"xmin", "ymin", "xmax", "ymax", "label", "score", "geometry"}
assert not hasattr(prediction, 'root_dir')

def test_predict_big_file(m, tmpdir):
Expand Down Expand Up @@ -648,4 +648,29 @@ def test_predict_tile_with_crop_model(m, config):
assert set(result.columns) == {
"xmin", "ymin", "xmax", "ymax", "label", "score", "cropmodel_label", "geometry",
"cropmodel_score", "image_path"
}
}


def test_predict_tile_with_crop_model_empty():
"""If the model return is empty, the crop model should return an empty dataframe"""
raster_path = get_data("SOAP_061.png")
m = main.deepforest()
patch_size = 400
patch_overlap = 0.05
iou_threshold = 0.15
mosaic = True
# Set up the crop model
crop_model = model.CropModel()

# Call the predict_tile method with the crop_model
m.config["train"]["fast_dev_run"] = False
m.create_trainer()
result = m.predict_tile(raster_path=raster_path,
patch_size=patch_size,
patch_overlap=patch_overlap,
iou_threshold=iou_threshold,
mosaic=mosaic,
crop_model=crop_model)

# Assert the result
assert result is None