Skip to content

Commit

Permalink
evaluate boxes doc
Browse files Browse the repository at this point in the history
  • Loading branch information
bw4sz committed Jan 10, 2025
1 parent c8e4d0f commit 361ad97
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 153 deletions.
204 changes: 61 additions & 143 deletions docs/examples/baseline_boxes.ipynb

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions docs/examples/baseline_points.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,12 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"import warnings\n",
"from deepforest.utilities import read_file\n",
"\n",
"def format_deepforest_prediction(images, metadata, targets, m, batch_index, point_dataset):\n",
" # Suppress user warnings to make more readable\n",
Expand All @@ -293,7 +294,8 @@
" predictions = m.predict_step(images, batch_index)\n",
" for image_metadata, pred, image_targets, image in zip(metadata,predictions, targets, images):\n",
" basename = point_dataset._filename_id_to_code[int(image_metadata[0])]\n",
" pred[\"geometry\"] = pred.centroid\n",
" pred = read_file(pred)\n",
" pred[\"geometry\"] = pred[\"geometry\"].centroid\n",
" pred[[\"x\",\"y\"]] = pred[\"geometry\"].apply(lambda x: pd.Series([x.x, x.y]))\n",
" if pred is None:\n",
" y_pred = {}\n",
Expand Down Expand Up @@ -327,14 +329,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"There are 66 batches in the test loader\n"
"ename": "NameError",
"evalue": "name 'get_eval_loader' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Get the test loader\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m test_loader \u001b[38;5;241m=\u001b[39m \u001b[43mget_eval_loader\u001b[49m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstandard\u001b[39m\u001b[38;5;124m\"\u001b[39m, point_test_data, batch_size\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m12\u001b[39m)\n\u001b[1;32m 4\u001b[0m \u001b[38;5;66;03m# Print the length of the test loader\u001b[39;00m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThere are \u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m batches in the test loader\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39mformat(\u001b[38;5;28mlen\u001b[39m(test_loader)))\n",
"\u001b[0;31mNameError\u001b[0m: name 'get_eval_loader' is not defined"
]
}
],
Expand Down
5 changes: 2 additions & 3 deletions milliontrees/common/metrics/all_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def _accuracy(self, src_boxes, pred_boxes, iou_threshold):
)
false_negative = total_gt - true_positive
acc = true_positive / ( true_positive + false_positive + false_negative )
return true_positive / ( true_positive + false_positive + false_negative )
return acc
elif total_gt == 0:
if total_pred > 0:
return torch.tensor(0.)
Expand Down Expand Up @@ -510,8 +510,7 @@ def _accuracy(self, src_keypoints, pred_keypoints, distance_threshold):
false_negative = total_gt - true_positive
acc = true_positive / (true_positive + false_positive +
false_negative)
return true_positive / (true_positive + false_positive +
false_negative)
return acc
elif total_gt == 0:
if total_pred > 0:
return torch.tensor(0.)
Expand Down

0 comments on commit 361ad97

Please sign in to comment.