Skip to content

Commit

Permalink
feat: pre commit for the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume.bertrand@edhec.com authored and guillaume.bertrand@edhec.com committed Feb 24, 2024
1 parent 9e65b7b commit ba9b8e7
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 70 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: doc
name: doc
on:
push:
branches:
- master
- master
- main
permissions:
contents: write
Expand All @@ -18,12 +18,12 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: 3.12
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- run: pip install -r bindings/docs/requirements-doc.txt && pip install bindings/.
- run: cd bindings && mkdocs gh-deploy --force
- run: cd bindings && mkdocs gh-deploy --force
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
- id: detect-private-key
- id: debug-statements

- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.2.2'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ It shows a significant speedup over the equivalent numpy implementations in Pyth
**🦀 Rust [documentation](https://docs.rs/powerboxesrs)**


**🐍 Python [documentation]("https://smirkey.github.io/powerboxes/")**
**🐍 Python [documentation](https://smirkey.github.io/powerboxes/)**

## Installation

Expand Down
54 changes: 3 additions & 51 deletions bindings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
Powerboxes is a package containing utility functions for transforming bounding boxes and computing metrics. It is implemented in both Python and Rust.
It shows a significant speedup over the equivalent numpy implementations in Python, or other libraries such as [shapely](https://github.com/shapely/shapely) or [torchvision](https://pytorch.org/vision/main/ops.html).

# Checkout out the documentation !
**🐍 Python [documentation]("https://smirkey.github.io/powerboxes/")**

## Installation

```bash
Expand All @@ -28,54 +31,3 @@ area = pb.box_areas(box)
# Compute the intersection of the box with itself
intersection = pb.iou_distance(box, box)
```
### Functions available
#### Box Transformations and utilities
- `box_areas`: Compute the area of list of boxes
- `box_convert`: Convert a box from one format to another. Supported formats are `xyxy`, `xywh`, `cxcywh`.
- `remove_small_boxes`: Remove boxes with area smaller than a threshold
- `mask_to_boxes`: Convert a mask to a list of boxes

#### Box Metrics
- `iou_distance`: Compute the intersection over union matrix of two sets of boxes
- `parallel_iou_distance`: Compute the intersection over union matrix of two sets of boxes in parallel
- `giou_distance`: Compute the generalized intersection over union matrix of two sets of boxes
- `parallel_giou_distance`: Compute the generalized intersection over union matrix of two sets of boxes in parallel
- `tiou_distance`: Compute the tracking intersection over union matrix of two sets of boxes

#### Rotated Box Metrics
- `rotated_iou_distance`: Compute the intersection over union matrix of two sets of rotated boxes in cxcywha format
- `rotated_giou_distance`: Compute the generalized intersection over union matrix of two sets of rotated boxes in cxcywha format

#### Box NMS
- `nms`: Non-maximum suppression, returns the indices of the boxes to keep
- `rtree_nms`: Non-maximum suppression, returns the indices of the boxes to keep, uses a r-tree internally to avoid quadratic complexity, useful when having many boxes.

## Benchmarks

Some benchmarks of powerboxes against various open source alternatives, not all functions are benchmarked. Notice that we use log scales, **all differences are major** !

### Box area
Here it's torchvision vs powerboxes vs numpy

![Box area](../images/box_area.png)

### Box convert
Here it's torchvision vs powerboxes

![Box convert](../images/box_convert.png)

### Box IoU matrix
Torchvision vs numpy vs powerboxes

![Box IoU](../images/box_iou.png)

### NMS
Torchvision vs powerboxes vs lsnms vs numpy

#### Large image (10000x10000 pixels)

![Box NMS](../images/box_nms_large_image.png)

#### Normal image (1000x1000 pixels)

![Box NMS](../images/box_nms_normal_image.png)
2 changes: 1 addition & 1 deletion bindings/docs/box_filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

::: powerboxes.nms

::: powerboxes.rtree_nms
::: powerboxes.rtree_nms
2 changes: 1 addition & 1 deletion bindings/docs/box_ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

::: powerboxes.box_convert

::: powerboxes.masks_to_boxes
::: powerboxes.masks_to_boxes
2 changes: 1 addition & 1 deletion bindings/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ intersection = pb.iou_distance(box, box)

!!! note "supported dtypes by most functions"

::: powerboxes.supported_dtypes
::: powerboxes.supported_dtypes
2 changes: 1 addition & 1 deletion bindings/docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

::: powerboxes.diou_distance

::: powerboxes.tiou_distance
::: powerboxes.tiou_distance
2 changes: 1 addition & 1 deletion bindings/docs/requirements-doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ mkdocs-autorefs==0.5.0
mkdocs-material==9.5.6
mkdocs-material-extensions==1.3.1
mkdocstrings==0.24.0
mkdocstrings-python==1.8.0
mkdocstrings-python==1.8.0
2 changes: 1 addition & 1 deletion bindings/docs/rotated_box.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

::: powerboxes.rotated_giou_distance

::: powerboxes.rotated_tiou_distance
::: powerboxes.rotated_tiou_distance
2 changes: 1 addition & 1 deletion bindings/python/powerboxes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,4 +500,4 @@ def rtree_nms(
"rotated_tiou_distance",
"rtree_nms",
"__version__",
]
]
2 changes: 1 addition & 1 deletion bindings/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pytest-codspeed>=2.0.0
numpy
pytest-cov
pillow
maturin
maturin
2 changes: 1 addition & 1 deletion bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,4 +1160,4 @@ fn rtree_nms_i16(
iou_threshold,
score_threshold,
)?);
}
}
5 changes: 4 additions & 1 deletion bindings/tests/test_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from PIL import Image


def test_masks_box():
expected = np.array(
[
Expand All @@ -15,7 +16,9 @@ def test_masks_box():
[108, 148, 152, 213],
],
)
assets_directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets")
assets_directory = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "assets"
)
mask_path = os.path.join(assets_directory, "masks.tiff")
image = Image.open(mask_path)
masks = np.zeros((image.n_frames, image.height, image.width))
Expand Down
2 changes: 1 addition & 1 deletion bindings/tests/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,4 @@ def test_diou_distance_dtype():
diou_distance(
boxes1.astype(unsuported_dtype_example),
boxes2.astype(unsuported_dtype_example),
)
)
2 changes: 1 addition & 1 deletion bindings/tests/test_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,4 @@ def test_nms_many_boxes(benchmark, generate_boxes):
def test_rtree_nms_many_boxes(benchmark, generate_boxes):
boxes = generate_boxes
scores = np.random.random(len(boxes))
benchmark(rtree_nms, boxes, scores, 0.5, 0.5)
benchmark(rtree_nms, boxes, scores, 0.5, 0.5)
1 change: 0 additions & 1 deletion powerboxesrs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ let boxes = array![[1., 2., 3., 4.], [0., 0., 10., 10.]];
let areas = box_areas(&boxes);
assert_eq!(areas, array![4., 100.]);
```

2 changes: 1 addition & 1 deletion powerboxesrs/src/diou.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ mod tests {
let diou_distance_result = diou_distance(&boxes1, &boxes2);
assert_eq!(diou_distance_result, arr2(&[[1.0]]));
}
}
}

0 comments on commit ba9b8e7

Please sign in to comment.