Skip to content

Commit

Permalink
[build] NumPy 2.0 support (#1709)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixdittrich92 authored Sep 30, 2024
1 parent 420ab32 commit 7b7f7f3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ requirements:
- setuptools

run:
- numpy >=1.16.0, <2.0.0
- numpy >=1.16.0, <3.0.0
- scipy >=1.4.0, <2.0.0
- pillow >=9.2.0
- h5py >=3.1.0, <4.0.0
Expand Down
2 changes: 1 addition & 1 deletion doctr/transforms/functional/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def rotate_sample(
rotated_geoms[..., 0] = rotated_geoms[..., 0] / rotated_img.shape[2]
rotated_geoms[..., 1] = rotated_geoms[..., 1] / rotated_img.shape[1]

return rotated_img, np.clip(rotated_geoms, 0, 1)
return rotated_img, np.clip(np.around(rotated_geoms, decimals=15), 0, 1)


def crop_detection(
Expand Down
2 changes: 1 addition & 1 deletion doctr/utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def box_iou(boxes_1: np.ndarray, boxes_2: np.ndarray) -> np.ndarray:
right = np.minimum(r1, r2.T)
bot = np.minimum(b1, b2.T)

intersection = np.clip(right - left, 0, np.Inf) * np.clip(bot - top, 0, np.Inf)
intersection = np.clip(right - left, 0, np.inf) * np.clip(bot - top, 0, np.inf)
union = (r1 - l1) * (b1 - t1) + ((r2 - l2) * (b2 - t2)).T - intersection
iou_mat = intersection / union

Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dynamic = ["version"]
dependencies = [
# For proper typing, mypy needs numpy>=1.20.0 (cf. https://github.com/numpy/numpy/pull/16515)
# Additional typing support is brought by numpy>=1.22.4, but core build sticks to >=1.16.0
"numpy>=1.16.0,<2.0.0",
"numpy>=1.16.0,<3.0.0",
"scipy>=1.4.0,<2.0.0",
"h5py>=3.1.0,<4.0.0",
"opencv-python>=4.5.0,<5.0.0",
Expand Down Expand Up @@ -75,7 +75,6 @@ contrib = [
testing = [
"pytest>=5.3.2",
"coverage[toml]>=4.5.4",
"hdf5storage>=0.1.18",
"onnxruntime>=1.11.0",
"requests>=2.20.0",
"psutil>=5.9.5"
Expand Down Expand Up @@ -112,7 +111,6 @@ dev = [
# Testing
"pytest>=5.3.2",
"coverage[toml]>=4.5.4",
"hdf5storage>=0.1.18",
"onnxruntime>=1.11.0",
"requests>=2.20.0",
"psutil>=5.9.5",
Expand Down
39 changes: 24 additions & 15 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from io import BytesIO

import cv2
import hdf5storage
import numpy as np
import pytest
import requests
Expand Down Expand Up @@ -257,24 +256,34 @@ def mock_imgur5k(tmpdir_factory, mock_image_stream):
def mock_svhn_dataset(tmpdir_factory, mock_image_stream):
root = tmpdir_factory.mktemp("datasets")
svhn_root = root.mkdir("svhn")
train_root = svhn_root.mkdir("train")
file = BytesIO(mock_image_stream)

# NOTE: hdf5storage seems not to be maintained anymore, ref.: https://github.com/frejanordsiek/hdf5storage/pull/134
# Instead we download the mocked data which was generated using the following code:
# ascii image names
first = np.array([[49], [46], [112], [110], [103]], dtype=np.int16) # 1.png
second = np.array([[50], [46], [112], [110], [103]], dtype=np.int16) # 2.png
third = np.array([[51], [46], [112], [110], [103]], dtype=np.int16) # 3.png
# first = np.array([[49], [46], [112], [110], [103]], dtype=np.int16) # 1.png
# second = np.array([[50], [46], [112], [110], [103]], dtype=np.int16) # 2.png
# third = np.array([[51], [46], [112], [110], [103]], dtype=np.int16) # 3.png
# labels: label is also ascii
label = {
"height": [35, 35, 35, 35],
"label": [1, 1, 3, 7],
"left": [116, 128, 137, 151],
"top": [27, 29, 29, 26],
"width": [15, 10, 17, 17],
}

matcontent = {"digitStruct": {"name": [first, second, third], "bbox": [label, label, label]}}
# label = {
# "height": [35, 35, 35, 35],
# "label": [1, 1, 3, 7],
# "left": [116, 128, 137, 151],
# "top": [27, 29, 29, 26],
# "width": [15, 10, 17, 17],
# }

# matcontent = {"digitStruct": {"name": [first, second, third], "bbox": [label, label, label]}}
# Mock train data
train_root = svhn_root.mkdir("train")
hdf5storage.write(matcontent, filename=train_root.join("digitStruct.mat"))
# hdf5storage.write(matcontent, filename=train_root.join("digitStruct.mat"))

# Downloading the mocked data
url = "https://github.com/mindee/doctr/releases/download/v0.9.0/digitStruct.mat"
response = requests.get(url)
with open(train_root.join("digitStruct.mat"), "wb") as f:
f.write(response.content)

for i in range(3):
fn = train_root.join(f"{i + 1}.png")
with open(fn, "wb") as f:
Expand Down

0 comments on commit 7b7f7f3

Please sign in to comment.