From 545e2c825905213616f3c535871ff819b04e4737 Mon Sep 17 00:00:00 2001 From: felix Date: Wed, 6 Nov 2024 08:12:54 +0100 Subject: [PATCH] Upgrade py 3.10 --- .conda/meta.yaml | 2 +- .github/workflows/builds.yml | 6 +++--- .github/workflows/demo.yml | 4 ++-- .github/workflows/doc-status.yml | 2 +- .github/workflows/docker.yml | 6 +++--- .github/workflows/docs.yml | 2 +- .github/workflows/main.yml | 6 +++--- .github/workflows/public_docker_images.yml | 2 +- .github/workflows/publish.yml | 8 ++++---- .github/workflows/pull_requests.yml | 2 +- .github/workflows/references.yml | 16 ++++++++-------- .github/workflows/scripts.yml | 8 ++++---- .github/workflows/style.yml | 4 ++-- README.md | 2 +- api/Dockerfile | 2 +- api/pyproject.toml | 2 +- docs/source/getting_started/installing.rst | 2 +- doctr/models/_utils.py | 6 +++--- .../differentiable_binarization/base.py | 2 +- doctr/models/detection/fast/base.py | 2 +- doctr/models/detection/linknet/base.py | 2 +- doctr/models/kie_predictor/tensorflow.py | 2 +- doctr/models/predictor/tensorflow.py | 2 +- doctr/utils/geometry.py | 8 ++++---- pyproject.toml | 6 +++--- 25 files changed, 53 insertions(+), 53 deletions(-) diff --git a/.conda/meta.yaml b/.conda/meta.yaml index 3755e7f4eb..3d3b14545a 100644 --- a/.conda/meta.yaml +++ b/.conda/meta.yaml @@ -16,7 +16,7 @@ build: requirements: host: - - python>=3.9, <3.12 + - python>=3.10, <3.13 - setuptools run: diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 7ee17ebbbf..15b4a5d7fe 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - python: ["3.9", "3.10"] + python: ["3.10", "3.11"] framework: [tensorflow, pytorch] steps: - uses: actions/checkout@v4 @@ -24,7 +24,7 @@ jobs: uses: actions/setup-python@v5 with: # MacOS issue ref.: https://github.com/actions/setup-python/issues/855 & https://github.com/actions/setup-python/issues/865 - python-version: ${{ matrix.os == 'macos-latest' && '3.11' || matrix.python }} + python-version: ${{ matrix.os == 'macos-latest' && matrix.python == '3.10' && '3.11' || matrix.python }} architecture: x64 - if: matrix.framework == 'tensorflow' name: Cache python modules (TF) @@ -58,7 +58,7 @@ jobs: - uses: conda-incubator/setup-miniconda@v3 with: auto-update-conda: true - python-version: 3.9 + python-version: "3.10" channels: pypdfium2-team,bblanchon,defaults,conda-forge channel-priority: strict - name: Install dependencies diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index ad5a1045b3..875fff8b02 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -26,7 +26,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] framework: [tensorflow, pytorch] steps: - if: matrix.os == 'macos-latest' @@ -92,7 +92,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/doc-status.yml b/.github/workflows/doc-status.yml index 294f3dc55a..7d2bda22d2 100644 --- a/.github/workflows/doc-status.yml +++ b/.github/workflows/doc-status.yml @@ -9,7 +9,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "3.9" + python-version: "3.10" architecture: x64 - name: check status run: | diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 70302c957f..99fac9c033 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -12,16 +12,16 @@ jobs: steps: - uses: actions/checkout@v4 - name: Build docker image - run: docker build -t doctr-tf-py3.9-slim --build-arg SYSTEM=cpu . + run: docker build -t doctr-tf-py3.10-slim --build-arg SYSTEM=cpu . - name: Run docker container - run: docker run doctr-tf-py3.9-slim python3 -c 'import doctr' + run: docker run doctr-tf-py3.10-slim python3 -c 'import doctr' pytest-api: runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 79965b560c..2b2c056a99 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ac34c9cc76..f2c5e212ad 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] steps: - uses: actions/checkout@v4 - name: Set up Python @@ -45,7 +45,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] steps: - uses: actions/checkout@v4 - name: Set up Python @@ -78,7 +78,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] steps: - uses: actions/checkout@v4 - name: Set up Python diff --git a/.github/workflows/public_docker_images.yml b/.github/workflows/public_docker_images.yml index 2ccdb66018..8d4e929391 100644 --- a/.github/workflows/public_docker_images.yml +++ b/.github/workflows/public_docker_images.yml @@ -22,7 +22,7 @@ jobs: fail-fast: false matrix: # Must match version at https://www.python.org/ftp/python/ - python: ["3.9.18", "3.10.13", "3.11.8"] + python: ["3.10.13", "3.11.8", "3.12.7"] framework: ["tf", "torch", "tf,viz,html,contrib", "torch,viz,html,contrib"] system: ["cpu", "gpu"] diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b09d8a4299..2494fdaa14 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,7 +11,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -50,7 +50,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -73,7 +73,7 @@ jobs: - uses: conda-incubator/setup-miniconda@v3 with: auto-update-conda: true - python-version: 3.9 + python-version: "3.10" channels: pypdfium2-team,bblanchon,defaults,conda-forge channel-priority: strict - name: Install dependencies @@ -103,7 +103,7 @@ jobs: - uses: conda-incubator/setup-miniconda@v3 with: auto-update-conda: true - python-version: 3.9 + python-version: "3.10" - name: Install package shell: bash -el {0} run: | diff --git a/.github/workflows/pull_requests.yml b/.github/workflows/pull_requests.yml index 045c4676f6..8d972c8551 100644 --- a/.github/workflows/pull_requests.yml +++ b/.github/workflows/pull_requests.yml @@ -12,7 +12,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "3.9" + python-version: "3.10" architecture: x64 - name: Cache python modules uses: actions/cache@v4 diff --git a/.github/workflows/references.yml b/.github/workflows/references.yml index f79784244a..bd614727df 100644 --- a/.github/workflows/references.yml +++ b/.github/workflows/references.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] framework: [tensorflow, pytorch] steps: - uses: actions/checkout@v4 @@ -65,7 +65,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] framework: [tensorflow, pytorch] steps: - uses: actions/checkout@v4 @@ -131,7 +131,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] framework: [tensorflow, pytorch] steps: - uses: actions/checkout@v4 @@ -186,7 +186,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] framework: [tensorflow, pytorch] steps: - uses: actions/checkout@v4 @@ -230,7 +230,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] framework: [tensorflow, pytorch] steps: - uses: actions/checkout@v4 @@ -274,7 +274,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] framework: [tensorflow, pytorch] steps: - uses: actions/checkout@v4 @@ -329,7 +329,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] framework: [tensorflow, pytorch] steps: - uses: actions/checkout@v4 @@ -375,7 +375,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] framework: [tensorflow, pytorch] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/scripts.yml b/.github/workflows/scripts.yml index d5f45aff21..1857cb6a12 100644 --- a/.github/workflows/scripts.yml +++ b/.github/workflows/scripts.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9", "3.10"] + python: ["3.10", "3.11"] framework: [tensorflow, pytorch] steps: - if: matrix.os == 'macos-latest' @@ -59,7 +59,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9", "3.10"] + python: ["3.10", "3.11"] framework: [tensorflow, pytorch] steps: - if: matrix.os == 'macos-latest' @@ -105,7 +105,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python: ["3.9", "3.10"] + python: ["3.10", "3.11"] framework: [tensorflow, pytorch] steps: - if: matrix.os == 'macos-latest' @@ -150,7 +150,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python: ["3.9", "3.10"] + python: ["3.10", "3.11"] steps: - uses: actions/checkout@v4 - name: Set up Python diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index c755a06c15..47cc0d6e56 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] steps: - uses: actions/checkout@v4 - name: Set up Python @@ -31,7 +31,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python: ["3.9"] + python: ["3.10"] steps: - uses: actions/checkout@v4 - name: Set up Python diff --git a/README.md b/README.md index b0f3b9d5f9..7231a64c3a 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ The KIE predictor results per page are in a dictionary format with each key repr ### Prerequisites -Python 3.9 (or higher) and [pip](https://pip.pypa.io/en/stable/) are required to install docTR. +Python 3.10 (or higher) and [pip](https://pip.pypa.io/en/stable/) are required to install docTR. ### Latest release diff --git a/api/Dockerfile b/api/Dockerfile index 8038ed28c8..6fd83e4ebd 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,4 +1,4 @@ -FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9-slim +FROM tiangolo/uvicorn-gunicorn-fastapi:python3.10-slim WORKDIR /app diff --git a/api/pyproject.toml b/api/pyproject.toml index 9bafb67935..3f21402540 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -10,7 +10,7 @@ authors = ["Mindee "] license = "Apache-2.0" [tool.poetry.dependencies] -python = ">=3.9,<3.12" +python = ">=3.10,<3.13" python-doctr = {git = "https://github.com/mindee/doctr.git", extras = ['tf'], branch = "main" } # Fastapi: minimum version required to avoid pydantic error # cf. https://github.com/tiangolo/fastapi/issues/4168 diff --git a/docs/source/getting_started/installing.rst b/docs/source/getting_started/installing.rst index e764e734a7..39e79aa3dd 100644 --- a/docs/source/getting_started/installing.rst +++ b/docs/source/getting_started/installing.rst @@ -3,7 +3,7 @@ Installation ************ -This library requires `Python `_ 3.9 or higher. +This library requires `Python `_ 3.10 or higher. Prerequisites diff --git a/doctr/models/_utils.py b/doctr/models/_utils.py index c5dcd9ba81..348a7773c9 100644 --- a/doctr/models/_utils.py +++ b/doctr/models/_utils.py @@ -64,13 +64,13 @@ def estimate_orientation( gray_img = cv2.medianBlur(gray_img, 5) thresh = cv2.threshold(gray_img, thresh=0, maxval=255, type=cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1] else: - thresh = img.astype(np.uint8) # type: ignore[assignment] + thresh = img.astype(np.uint8) page_orientation, orientation_confidence = general_page_orientation or (None, 0.0) if page_orientation and orientation_confidence >= min_confidence: # We rotate the image to the general orientation which improves the detection # No expand needed bitmap is already padded - thresh = rotate_image(thresh, -page_orientation) # type: ignore + thresh = rotate_image(thresh, -page_orientation) else: # That's only required if we do not work on the detection models bin map # try to merge words in lines (h, w) = img.shape[:2] @@ -91,7 +91,7 @@ def estimate_orientation( angles = [] for contour in contours[:n_ct]: - _, (w, h), angle = cv2.minAreaRect(contour) # type: ignore[assignment] + _, (w, h), angle = cv2.minAreaRect(contour) if w / h > ratio_threshold_for_lines: # select only contours with ratio like lines angles.append(angle) elif w / h < 1 / ratio_threshold_for_lines: # if lines are vertical, substract 90 degree diff --git a/doctr/models/detection/differentiable_binarization/base.py b/doctr/models/detection/differentiable_binarization/base.py index 21eceb7940..414471146c 100644 --- a/doctr/models/detection/differentiable_binarization/base.py +++ b/doctr/models/detection/differentiable_binarization/base.py @@ -114,7 +114,7 @@ def bitmap_to_boxes( contours, _ = cv2.findContours(bitmap.astype(np.uint8), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) for contour in contours: # Check whether smallest enclosing bounding box is not too small - if np.any(contour[:, 0].max(axis=0) - contour[:, 0].min(axis=0) < min_size_box): # type: ignore[index] + if np.any(contour[:, 0].max(axis=0) - contour[:, 0].min(axis=0) < min_size_box): continue # Compute objectness if self.assume_straight_pages: diff --git a/doctr/models/detection/fast/base.py b/doctr/models/detection/fast/base.py index f98981a82e..1b3a02bb29 100644 --- a/doctr/models/detection/fast/base.py +++ b/doctr/models/detection/fast/base.py @@ -111,7 +111,7 @@ def bitmap_to_boxes( contours, _ = cv2.findContours(bitmap.astype(np.uint8), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) for contour in contours: # Check whether smallest enclosing bounding box is not too small - if np.any(contour[:, 0].max(axis=0) - contour[:, 0].min(axis=0) < 2): # type: ignore[index] + if np.any(contour[:, 0].max(axis=0) - contour[:, 0].min(axis=0) < 2): continue # Compute objectness if self.assume_straight_pages: diff --git a/doctr/models/detection/linknet/base.py b/doctr/models/detection/linknet/base.py index d677048c0e..9aeb543fe3 100644 --- a/doctr/models/detection/linknet/base.py +++ b/doctr/models/detection/linknet/base.py @@ -111,7 +111,7 @@ def bitmap_to_boxes( contours, _ = cv2.findContours(bitmap.astype(np.uint8), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) for contour in contours: # Check whether smallest enclosing bounding box is not too small - if np.any(contour[:, 0].max(axis=0) - contour[:, 0].min(axis=0) < 2): # type: ignore[index] + if np.any(contour[:, 0].max(axis=0) - contour[:, 0].min(axis=0) < 2): continue # Compute objectness if self.assume_straight_pages: diff --git a/doctr/models/kie_predictor/tensorflow.py b/doctr/models/kie_predictor/tensorflow.py index b73f651fc5..873e0b09e4 100644 --- a/doctr/models/kie_predictor/tensorflow.py +++ b/doctr/models/kie_predictor/tensorflow.py @@ -172,7 +172,7 @@ def __call__( boxes_per_page, objectness_scores_per_page, text_preds_per_page, - origin_page_shapes, # type: ignore[arg-type] + origin_page_shapes, crop_orientations_per_page, orientations, languages_dict, diff --git a/doctr/models/predictor/tensorflow.py b/doctr/models/predictor/tensorflow.py index 1392943bc4..99ceaa9731 100644 --- a/doctr/models/predictor/tensorflow.py +++ b/doctr/models/predictor/tensorflow.py @@ -148,7 +148,7 @@ def __call__( boxes, objectness_scores, text_preds, - origin_page_shapes, # type: ignore[arg-type] + origin_page_shapes, crop_orientations, orientations, languages_dict, diff --git a/doctr/utils/geometry.py b/doctr/utils/geometry.py index 21ad0dd7f4..eac3d4966a 100644 --- a/doctr/utils/geometry.py +++ b/doctr/utils/geometry.py @@ -126,7 +126,7 @@ def resolve_enclosing_rbbox(rbboxes: List[np.ndarray], intermed_size: int = 1024 # Convert to absolute for minAreaRect cloud *= intermed_size rect = cv2.minAreaRect(cloud.astype(np.int32)) - return cv2.boxPoints(rect) / intermed_size # type: ignore[return-value] + return cv2.boxPoints(rect) / intermed_size def rotate_abs_points(points: np.ndarray, angle: float = 0.0) -> np.ndarray: @@ -323,7 +323,7 @@ def rotate_image( # Compute the expanded padding exp_img: np.ndarray if expand: - exp_shape = compute_expanded_shape(image.shape[:2], angle) # type: ignore[arg-type] + exp_shape = compute_expanded_shape(image.shape[:2], angle) h_pad, w_pad = ( int(max(0, ceil(exp_shape[0] - image.shape[0]))), int(max(0, ceil(exp_shape[1] - image.shape[1]))), @@ -344,7 +344,7 @@ def rotate_image( # Pad height else: h_pad, w_pad = int(rot_img.shape[1] * image.shape[0] / image.shape[1] - rot_img.shape[0]), 0 - rot_img = np.pad(rot_img, ((h_pad // 2, h_pad - h_pad // 2), (w_pad // 2, w_pad - w_pad // 2), (0, 0))) # type: ignore[assignment] + rot_img = np.pad(rot_img, ((h_pad // 2, h_pad - h_pad // 2), (w_pad // 2, w_pad - w_pad // 2), (0, 0))) if preserve_origin_shape: # rescale rot_img = cv2.resize(rot_img, image.shape[:-1][::-1], interpolation=cv2.INTER_LINEAR) @@ -563,4 +563,4 @@ def extract_rcrops( ) for idx in range(_boxes.shape[0]) ] - return crops # type: ignore[return-value] + return crops diff --git a/pyproject.toml b/pyproject.toml index 613eb512e2..763e966187 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ maintainers = [ {name = "Felix Dittrich"}, ] readme = "README.md" -requires-python = ">=3.9.0,<4" +requires-python = ">=3.10.0,<4" license = {file = "LICENSE"} keywords=["OCR", "deep learning", "computer vision", "tensorflow", "pytorch", "text detection", "text recognition"] classifiers=[ @@ -25,9 +25,9 @@ classifiers=[ "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Scientific/Engineering :: Artificial Intelligence", ] dynamic = ["version"] @@ -183,7 +183,7 @@ ignore_missing_imports = true [tool.ruff] exclude = [".git", "venv*", "build", "**/__init__.py"] line-length = 120 -target-version = "py39" +target-version = "py310" preview=true [tool.ruff.lint]