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

Edge case. When cropmodel is used, and the detection model returns no result, the assertion is raised. #839

Open
bw4sz opened this issue Nov 22, 2024 · 0 comments · May be fixed by #840
Open
Assignees
Labels
bug Something isn't working

Comments

@bw4sz
Copy link
Collaborator

bw4sz commented Nov 22, 2024

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 isinstance(result, pd.DataFrame)
    assert set(result.columns) == {
        "xmin", "ymin", "xmax", "ymax", "label", "score", "cropmodel_label", "geometry",
        "cropmodel_score", "image_path"
    }
self = <deepforest.dataset.BoundingBoxDataset object at 0x1849afdd0>
df = Empty DataFrame
Columns: [xmin, ymin, xmax, ymax, label, score, image_path]
Index: []
root_dir = '/Users/benweinstein/Documents/DeepForest/src/deepforest/data'
transform = None, augment = False

    def __init__(self, df, root_dir, transform=None, augment=False):
        self.df = df
    
        if transform is None:
            self.transform = bounding_box_transform(augment=augment)
        else:
            self.transform = transform
    
        unique_image = self.df['image_path'].unique()
>       assert len(unique_image
                  ) == 1, "There should be only one unique image for this class object"
E       AssertionError: There should be only one unique image for this class object

I am assigning to myself and will fix shortly. I found it while working with the CropModel workflow. Just need to check for results.empty.

@bw4sz bw4sz added the bug Something isn't working label Nov 22, 2024
@bw4sz bw4sz self-assigned this Nov 22, 2024
bw4sz added a commit that referenced this issue Nov 22, 2024
@bw4sz bw4sz linked a pull request Nov 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant