Skip to content

Commit 530de1b

Browse files
authored
Update report (#94)
* update release report * update leaderboard * remove yolo
1 parent 5a16289 commit 530de1b

File tree

4 files changed

+35
-159
lines changed

4 files changed

+35
-159
lines changed

data_prep/package_datasets.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,25 @@ def convert_to_shapely(value):
9191
return datasets
9292

9393

94+
def filter_degenerate_polygons(datasets):
95+
"""Filter out polygons that would create invalid bounding boxes (zero width or height)."""
96+
def convert_to_shapely(value):
97+
if type(value) == str:
98+
return shapely.wkt.loads(value)
99+
elif isinstance(value, BaseGeometry):
100+
return value
101+
else:
102+
raise ValueError(f"Invalid geometry type: {type(value)}")
103+
104+
shapely_geometries = gpd.GeoSeries(datasets["polygon"].apply(convert_to_shapely))
105+
bounds = shapely_geometries.bounds
106+
107+
# Filter out polygons where xmin == xmax or ymin == ymax
108+
valid_mask = (bounds["minx"] != bounds["maxx"]) & (bounds["miny"] != bounds["maxy"])
109+
110+
return datasets.loc[valid_mask].copy()
111+
112+
94113
def create_directories(base_dir, dataset_type):
95114
"""Create directories for the dataset."""
96115
os.makedirs(f"{base_dir}{dataset_type}_{version}/images", exist_ok=True)
@@ -493,6 +512,9 @@ def run(version, base_dir, debug=False):
493512
TreePoints_datasets = process_geometry_columns(TreePoints_datasets, "point")
494513
TreePolygons_datasets = process_geometry_columns(TreePolygons_datasets, "polygon")
495514

515+
# Remove degenerate polygons (those that would create invalid bounding boxes)
516+
TreePolygons_datasets = filter_degenerate_polygons(TreePolygons_datasets)
517+
496518
# Copy images
497519
copy_images(TreeBoxes_datasets, base_dir, "TreeBoxes")
498520
copy_images(TreePoints_datasets, base_dir, "TreePoints")

docs/examples/baseline_polygons.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import torch
99

1010
from deepforest import main as df_main
11-
from deepforest.utilities import read_file
11+
from deepforest.utilities import read_file, format_geometry
1212
from deepforest.visualize import plot_results
1313

1414
from milliontrees import get_dataset
@@ -61,20 +61,20 @@ def format_deepforest_predictions(
6161
"images")
6262
formatted_pred["image_path"] = basename
6363
else:
64-
pred.root_dir = os.path.join(dataset._data_dir._str, "images")
65-
pred["image_path"] = basename
64+
formatted_pred = format_geometry(pred)
65+
formatted_pred.root_dir = os.path.join(dataset._data_dir._str,
66+
"images")
67+
formatted_pred["image_path"] = basename
6668

6769
y_pred = {
6870
"y": torch.tensor(
69-
pred[["xmin", "ymin", "xmax", "ymax"]].values.astype(
71+
formatted_pred[["xmin", "ymin", "xmax", "ymax"]].values.astype(
7072
"float32")),
71-
"labels": torch.tensor(pred.label.values.astype(np.int64)),
73+
"labels": torch.tensor(formatted_pred.label.values.astype(np.int64)),
7274
"scores": torch.tensor(
73-
pred.score.values.astype("float32")),
75+
formatted_pred.score.values.astype("float32")),
7476
}
7577

76-
formatted_pred = pred
77-
7878
batch_y_pred.append(y_pred)
7979
formatted_predictions.append(formatted_pred)
8080

@@ -94,8 +94,8 @@ def plot_eval_result(
9494

9595
# Ground truth
9696
gt_df = read_file(
97-
pd.DataFrame(image_targets["y"].numpy(),
98-
columns=["xmin", "ymin", "xmax", "ymax"]))
97+
pd.DataFrame(image_targets["bboxes"],
98+
columns=["xmin", "ymin", "xmax", "ymax"]), label="Tree")
9999
gt_df["label"] = "Tree"
100100

101101
# Predictions
@@ -107,8 +107,8 @@ def plot_eval_result(
107107
image = image_tensor.permute(1, 2, 0).numpy() * 255
108108

109109
# Simple recall example for logging
110-
recall = dataset.metrics["recall"]._recall(image_targets["y"],
111-
y_pred.get("y",
110+
recall = dataset.metrics["recall"]._recall(image_targets["bboxes"],
111+
y_pred.get("bboxes",
112112
torch.zeros(
113113
(0, 4))),
114114
iou_threshold=0.3)
@@ -159,6 +159,7 @@ def main():
159159
# Load model
160160
model = df_main.deepforest()
161161
model.load_model("weecology/deepforest-tree")
162+
model.eval()
162163

163164
# Load dataset
164165
polygon_dataset = get_dataset("TreePolygons",

docs/examples/torchvision_fasterrcnn_treeboxes.py

Lines changed: 0 additions & 141 deletions
This file was deleted.

docs/leaderboard.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,20 @@ All point sources are used to train and predict all box sources.
5959
|---|---|---|---|---|
6060
| DeepForest baseline (`baseline_boxes.py`) | TreeBoxes | TreeBoxes | 0.397 | <small>`uv run python docs/examples/baseline_boxes.py --split-scheme random`</small> |
6161
| SAM3 (`sam3_boxes.py`) | TreeBoxes | TreeBoxes | 0.165 | <small>`uv run python docs/examples/sam3_boxes.py --device cuda --split-scheme random --hf-token $HF_TOKEN`</small> |
62-
| Torchvision Faster R-CNN (`torchvision_fasterrcnn_treeboxes.py`) | TreeBoxes | TreeBoxes | | <small>`uv run python docs/examples/torchvision_fasterrcnn_treeboxes.py --split_scheme random`</small> |
63-
| Ultralytics YOLO (`yolo_treeboxes.py`) | TreeBoxes | TreeBoxes | | <small>`uv run python docs/examples/yolo_treeboxes.py --split_scheme random --weights yolov8n.pt`</small> |
6462

6563
### Zero-shot
6664

6765
| Model | Task | Dataset | Avg Recall | Script |
6866
|---|---|---|---|---|
6967
| DeepForest baseline (`baseline_boxes.py`) | TreeBoxes | TreeBoxes | 0.534 | <small>`uv run python docs/examples/baseline_boxes.py --split-scheme zeroshot`</small> |
7068
| SAM3 (`sam3_boxes.py`) | TreeBoxes | TreeBoxes | 0.208 | <small>`uv run python docs/examples/sam3_boxes.py --device cuda --split-scheme zeroshot --hf-token $HF_TOKEN`</small> |
71-
| Torchvision Faster R-CNN (`torchvision_fasterrcnn_treeboxes.py`) | TreeBoxes | TreeBoxes | | <small>`uv run python docs/examples/torchvision_fasterrcnn_treeboxes.py --split_scheme zeroshot`</small> |
72-
| Ultralytics YOLO (`yolo_treeboxes.py`) | TreeBoxes | TreeBoxes | 0.004 | <small>`uv run python docs/examples/yolo_treeboxes.py --split_scheme zeroshot --weights yolov8n.pt`</small> |
7369

7470
### Cross-geometry
7571

7672
| Model | Task | Dataset | Avg Recall | Script |
7773
|---|---|---|---|---|
7874
| DeepForest baseline (`baseline_boxes.py`) | TreeBoxes | TreeBoxes | 0.000 | <small>`uv run python docs/examples/baseline_boxes.py --split-scheme crossgeometry`</small> |
7975
| SAM3 (`sam3_boxes.py`) | TreeBoxes | TreeBoxes | 0.000 | <small>`uv run python docs/examples/sam3_boxes.py --device cuda --split-scheme crossgeometry --hf-token $HF_TOKEN`</small> |
80-
| Torchvision Faster R-CNN (`torchvision_fasterrcnn_treeboxes.py`) | TreeBoxes | TreeBoxes | | <small>`uv run python docs/examples/torchvision_fasterrcnn_treeboxes.py --split_scheme crossgeometry`</small> |
81-
| Ultralytics YOLO (`yolo_treeboxes.py`) | TreeBoxes | TreeBoxes | 0.000 | <small>`uv run python docs/examples/yolo_treeboxes.py --split_scheme crossgeometry --weights yolov8n.pt`</small> |
8276

8377
## TreePolygons
8478

0 commit comments

Comments
 (0)