weecology / DeepForest-pytorch

Pytorch implementation of the deepforest model for tree crown RGB detection.
MIT License
17 stars 9 forks source link

Profile IOU eval #66

Closed bw4sz closed 3 years ago

bw4sz commented 3 years ago
def _overlap_(test_poly, truth_polys, rtree_index):
    """Calculate overlap between one polygon and all ground truth by area"""
    results = []
    matched_list = list(rtree_index.intersection(test_poly.geometry.bounds))
    for index in truth_polys.index:
        if index in matched_list:
            # get the original index just to be sure
            intersection_result = test_poly.geometry.intersection(
                truth_polys.loc[index].geometry)
            intersection_area = intersection_result.area
        else:
            intersection_area = 0
        results.append(
            pd.DataFrame({
                "prediction_id": [test_poly.prediction_id],
                "truth_id": [truth_polys.loc[index].truth_id],
                "area": intersection_area
            }))
    results = pd.concat(results)

    return results

Creating a pandas frame each round seems to be expensive.

Screen Shot 2021-05-16 at 8 03 37 PM
bw4sz commented 3 years ago

Removed the pandas construction on each loop, this should speed things up considerably.