-
Notifications
You must be signed in to change notification settings - Fork 250
Description
Describe the bug
When using deepforest.utilities.read_file (DeepForest 2.0.0) to load a valid COCO detection JSON (bbox-only, no segmentation), the function raises a KeyError: 'segmentation'.
The JSON follows standard COCO detection format:
- Top-level keys: info, licenses, images, annotations, categories
- Each annotation has:
id,image_id,category_id,bbox,area,iscrowd - No
segmentationfield (which is optional in COCO when you only use bounding boxes)
However, internally utilities.read_file assumes that a segmentation key is always present in each annotation and fails with KeyError when it is not.
This makes it impossible to directly use standard COCO detection datasets with DeepForest via utilities.read_file without first modifying the COCO file.
To Reproduce
- Create a minimal COCO JSON file (e.g., annotations.json) with:
- One image:
"images": [
{
"id": 1,
"file_name": "2024_08_1.tif",
"height": 4325,
"width": 4325
}
]- One bbox-only annotation (no
segmentationkey):
"annotations": [
{
"id": 1,
"image_id": 1,
"category_id": 1,
"bbox": [1364.38, 1586.75, 115.60, 119.88],
"area": 13859.10,
"iscrowd": 0
}
]- One category:
"categories": [
{
"id": 1,
"name": "tree",
"supercategory": "object"
}
]- In a notebook or script
from deepforest import utilities
root_dir = r"some_directory"
annotations_file = "annotations.json"
annotations = utilities.read_file(annotations_file, root_dir=root_dir)- Observe that
utilities.read_fileraises:
Environment:
- OS: Windows 11 Home 64-bit (10.0, Build 26200)
- Python version and environment: 3.12
- DeepForest: Version 2.0.0
- Installation: Conda, version 24.11.1
Screenshots and Context
User Story
As a researcher working with aerial tree detection datasets using standard COCO bbox annotations, I want to load my existing COCO JSON files directly with deepforest.utilities.read_file (or an equivalent DeepForest loader) without having to modify them, so that I can quickly plug DeepForest into my existing COCO-labelled workflows and tools without adding custom pre-processing steps or deviating from the COCO standard.