Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/user_guide/13_annotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Yes! Object detection models use non-annotated areas of an image as negative dat

1. **Select Important Images**: Duplicate backgrounds or objects contribute little to model generalization. Focus on gathering a wide variety of object appearances.
2. **Avoid Over-splitting Labels**: Often, using a superclass for detection followed by a separate model for classification is more effective. See the [`CropModel`](03_cropmodels.md) for an example.
3. **Balance Accuracy and Practicality**: Depending on the goal (e.g., object counting or detection), keypoints can sometimes be used instead of precise boxes to simplify the process.
3. **Balance Accuracy and Practicality**: Depending on the goal (e.g., object counting or detection), point/keypoint annotations can sometimes be used instead of precise boxes to simplify the process.

## Quick Video on Annotating Images

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dependencies = [
"pyyaml>=5.1.0",
"rasterio",
"safetensors<0.6.0",
"scikit-image>=0.25.2",
"setuptools",
"shapely>2.0.0",
"slidingwindow",
Expand Down
5 changes: 5 additions & 0 deletions src/deepforest/conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,8 @@ cropmodel:
normalize:
# Number of pixels to expand bbox crop windows for better prediction context.
expand: 0

point:
score_integration_radius: 5
nms_distance_thresh: 5.0
distance_threshold: 10
22 changes: 22 additions & 0 deletions src/deepforest/conf/point.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
architecture: treeformer

model:
name: 'weecology/deepforest-tree-point'
revision: 'main'

# This model was trained on 10 cm/px data and has been tested
# at resolutions around 5-20 cm/px. If your data is significantly
# different, for example < 5 cm/px drone data, we suggest first
# downsampling your orthomosaics.
patch_size: 512
patch_overlap: 0.1

# Setting a threshold below 0.3 is likely to include a lot of
# noisy/low-confidence predictions.
score_thresh: 0.3

point:
backbone: 'pvt_v2_b3'
score_integration_radius: 5
nms_distance_thresh: 5.0
distance_threshold: 10.0
32 changes: 24 additions & 8 deletions src/deepforest/conf/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SchedulerConfig:
"""Set the type of scheduler, by default DeepForest uses a stepped learning
function reducing at "milestones" during training."""

type: str | None = "StepLR"
type: str | None = "stepLR"
params: SchedulerParamsConfig = field(default_factory=SchedulerParamsConfig)


Expand All @@ -57,8 +57,10 @@ class OptimizerConfig:

@dataclass
class TrainConfig:
"""Main training configuration. The CSV file and root directory are
required to specify the location of the training dataset.
"""Main training configuration.

The CSV file and root directory are required to specify the location
of the training dataset.

The default learning rate may need to be changed for certain
architectures, such as transformers-based models which sometimes
Expand All @@ -84,8 +86,10 @@ class TrainConfig:

@dataclass
class ValidationConfig:
"""Main validation configuration. As with training data, it's required that
you set a CSV file and root directory.
"""Main validation configuration.

As with training data, it's required that you set a CSV file and
root directory.

Validation during training is important to identify if the model has
converged or is overfitting.
Expand Down Expand Up @@ -125,11 +129,22 @@ class CropModelConfig:
expand: int = 0


@dataclass
class PointConfig:
"""Configuration for point models."""

backbone: str = "pvt_v2_b3"
score_integration_radius: int = 5
nms_distance_thresh: float = 5.0
distance_threshold: float = 10.0


@dataclass
class Config:
"""General DeepForest configuration. Some parameters here are shared
between dataloaders, for example the batch size, accelerator and number of
workers.
"""General DeepForest configuration.

Some parameters here are shared between dataloaders, for example the
batch size, accelerator and number of workers.

Here we also set the architecture, which can be one of "retinanet"
or "DeformableDetr" currently. If you modify the number of classes
Expand Down Expand Up @@ -173,3 +188,4 @@ class Config:
validation: ValidationConfig = field(default_factory=ValidationConfig)
predict: PredictConfig = field(default_factory=PredictConfig)
cropmodel: CropModelConfig = field(default_factory=CropModelConfig)
point: PointConfig = field(default_factory=PointConfig)
11 changes: 6 additions & 5 deletions src/deepforest/datasets/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ def _validate_labels(self) -> None:

@abstractmethod
def _validate_coordinates(self) -> None:
"""Validate geometries in the annotation data. Must be overidden by
child classes to implement task-specific checks (e.g., boxes vs
points).
"""Validate geometries in the annotation data.

Must be overidden by child classes to implement task-specific
checks (e.g., boxes vs points).

Should raise ValueError with details if any invalid geometries
are found.
Expand Down Expand Up @@ -285,8 +286,8 @@ def __getitem__(self, idx) -> tuple:
return image, targets, self.image_names[idx]


class KeypointDataset(TrainingDataset):
"""Dataset for keypoint detection tasks."""
class PointDataset(TrainingDataset):
"""Dataset for point detection tasks."""

_data_keys = [DataKey.IMAGE, DataKey.KEYPOINTS]

Expand Down
Loading
Loading