Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Add reusable workflow to env setup and update CI's (#2009)

João Gustavo A. Amorim471ed2c027cd
diff --git a/.github/actions/env/action.yml b/.github/actions/env/action.yml
new file mode 100644
index 000000000..dcd0e2ca8
--- /dev/null
+++ b/.github/actions/env/action.yml
@@ -0,0 +1,48 @@
+name: Environment setup
+
+on:
+ workflow_dispatch:
+ inputs:
+ python-version:
+ description: "The python version desired."
+ required: true
+ default: '3.7'
+ type: string
+
+ pytorch-version:
+ description: "The pytorch version desired."
+ required: true
+ default: '1.10.2'
+ type: string
+
+runs:
+ using: "composite"
+ steps:
+ - name: Setup environment (conda)
+ uses: conda-incubator/setup-miniconda@v2
+ with:
+ auto-update-conda: true
+ python-version: ${{ inputs.python-version }}
+
+ - if: ${{ contains(fromJson('["lts", "nightly"]'), inputs.pytorch-version ) }}
+ name: Install dependencies
+ shell: bash -l {0}
+ run: |
+ conda install curl -c conda-forge
+ conda install pytorch cpuonly -c pytorch-${{ inputs.pytorch-version }}
+ pip install .[dev,x]
+
+
+ - if: ${{ contains(fromJson('["lts", "nightly"]'), inputs.pytorch-version ) == false}}
+ name: Install dependencies
+ shell: bash -l {0}
+ run: |
+ conda install curl -c conda-forge
+ conda install pytorch=${{ inputs.pytorch-version }} cpuonly -c pytorch
+ pip install .[dev,x]
+
+ - name: Environment
+ shell: bash -l {0}
+ run: |
+ curl -O https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
+ python collect_env.py
diff --git a/.github/emoji.yml b/.github/emoji.yml
deleted file mode 100644
index ab4ab7994..000000000
--- a/.github/emoji.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-# Configuration for action-emoji - https://github.com/tiena2cva/action-emoji
-
-# Include all emoji supported or not
-all: false
-
-# Choose what list of emoji you want to use. Support 4 list: people, nature, objects, places.
-# If "all" is true, all of list will be included
-lists:
- - people
- - nature
- - objects
- - places
-
-# User custom emoji list
-customs:
- - atom
- - suspect
- - electron
- - england
diff --git a/.github/workflows/add_emoji.yml b/.github/workflows/add_emoji.yml
deleted file mode 100644
index 56ab9e184..000000000
--- a/.github/workflows/add_emoji.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-name: Add Emoji
-on: pull_request
-
-jobs:
- add-emoji:
- runs-on: ubuntu-latest
- steps:
- - name: Checkout 🛎️
- uses: actions/checkout@v2
-
- - name: Add emoji 🥰
- uses: tiena2cva/action-emoji@v1
- with:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/.github/workflows/pr_test_cpu.yml b/.github/workflows/pr_test_cpu.yml
new file mode 100644
index 000000000..74b8cae9e
--- /dev/null
+++ b/.github/workflows/pr_test_cpu.yml
@@ -0,0 +1,46 @@
+name: Run tests on CPU
+
+on:
+ pull_request:
+ branches: [master]
+ types: [open, reopened, synchronize, review_requested, ready_for_review]
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ tests-cpu:
+ name: ${{ matrix.os }} - python-${{ matrix.python-version }}, torch-${{ matrix.pytorch-version }}, ${{ matrix.pytorch-dtype }}
+ runs-on: ${{ matrix.os }}
+
+ strategy:
+ fail-fast: true
+ matrix:
+ os: [ubuntu-latest, windows-latest, macos]
+ python-version: ['3.7', '3.8']
+ pytorch-version: ['1.9.1', '1.12.1']
+ pytorch-dtype: ['float16', 'float32', 'float64']
+
+ steps:
+ - name: Checkout kornia
+ uses: actions/checkout@v3
+
+ - name: Setting environment on ${{ matrix.os }} with python ${{ matrix.python-version }} and pytorch ${{ matrix.pytorch-version }}
+ uses: ./.github/actions/env
+ with:
+ python-version: ${{ matrix.python-version }}
+ pytorch-version: ${{ matrix.pytorch-version }}
+
+ - name: Run CPU tests ${{ matrix.pytorch-dtype }}
+ continue-on-error: ${{ contains('float16', matrix.pytorch-dtype) }} # Remove this when float16 stop raising errors
+ shell: bash -l {0}
+ run: pytest -v --device cpu --dtype ${{ matrix.pytorch-dtype }} --cov=kornia --cov-report xml ./test
+
+ - if: always()
+ name: Upload coverage
+ uses: codecov/codecov-action@v3
+ with:
+ file: coverage.xml
+ flags: cpu,${{ matrix.os }}_python-${{ matrix.python-version }}_torch-${{ matrix.pytorch-version }}_${{ matrix.pytorch-dtype }}
+ name: cpu-coverage
diff --git a/.github/workflows/pr_test_typing.yml b/.github/workflows/pr_test_typing.yml
new file mode 100644
index 000000000..0663e705f
--- /dev/null
+++ b/.github/workflows/pr_test_typing.yml
@@ -0,0 +1,44 @@
+name: Run typing tests
+
+on:
+ pull_request:
+ branches: [master]
+ types: [open, reopened, synchronize, review_requested, ready_for_review]
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ tests:
+ name: ${{ matrix.os }} - python-${{ matrix.python-version }}, torch-${{ matrix.pytorch-version }}
+ runs-on: ${{ matrix.os }}
+
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [ubuntu-latest]
+ python-version: ['3.7']
+ pytorch-version: ['1.9.1', '1.12.1']
+
+ steps:
+ - name: Checkout kornia
+ uses: actions/checkout@v3
+
+ - name: Setting environment on ${{ matrix.os }} with python ${{ matrix.python-version }} and pytorch ${{ matrix.pytorch-version }}
+ uses: ./.github/actions/env
+ with:
+ python-version: ${{ matrix.python-version }}
+ pytorch-version: ${{ matrix.pytorch-version }}
+
+ - name: Run typing tests
+ shell: bash -l {0}
+ run: mypy --cobertura-xml-report ./
+
+ - if: always()
+ name: Upload coverage
+ uses: codecov/codecov-action@v3
+ with:
+ file: cobertura.xml
+ flags: typing,${{ matrix.os }}_python-${{ matrix.python-version }}_torch-${{ matrix.pytorch-version }}
+ name: cpu-coverage-types
diff --git a/.github/workflows/scheduled_test_cpu.yml b/.github/workflows/scheduled_test_cpu.yml
new file mode 100644
index 000000000..b8bf2bbc7
--- /dev/null
+++ b/.github/workflows/scheduled_test_cpu.yml
@@ -0,0 +1,47 @@
+name: (scheduled) Run tests on CPU
+
+on:
+ push:
+ branches: [master]
+ schedule:
+ - cron: "0 4 * * *"
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ tests-cpu:
+ name: ${{ matrix.os }} - python-${{ matrix.python-version }}, torch-${{ matrix.pytorch-version }}, ${{ matrix.pytorch-dtype }}
+ runs-on: ${{ matrix.os }}
+
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [ubuntu-latest, windows-latest, macos]
+ python-version: ['3.7', '3.8']
+ pytorch-version: ['1.9.1', '1.10.2', '1.12.1', '1.13.0', 'nightly']
+ pytorch-dtype: ['float16', 'float32', 'float64']
+
+ steps:
+ - name: Checkout kornia
+ uses: actions/checkout@v3
+
+ - name: Setting environment on ${{ matrix.os }} with python ${{ matrix.python-version }} and pytorch ${{ matrix.pytorch-version }}
+ uses: ./.github/actions/env
+ with:
+ python-version: ${{ matrix.python-version }}
+ pytorch-version: ${{ matrix.pytorch-version }}
+
+ - name: Run CPU tests ${{ matrix.pytorch-dtype }}
+ shell: bash -l {0}
+ run: pytest -v --device cpu --dtype ${{ matrix.pytorch-dtype }} --cov=kornia --cov-report xml ./test
+
+
+ - if: always()
+ name: Upload coverage
+ uses: codecov/codecov-action@v3
+ with:
+ file: coverage.xml
+ flags: cpu,${{ matrix.os }}_python-${{ matrix.python-version }}_torch-${{ matrix.pytorch-version }}_${{ matrix.pytorch-dtype }}
+ name: cpu-coverage
diff --git a/.github/workflows/scheduled_test_typing.yml b/.github/workflows/scheduled_test_typing.yml
new file mode 100644
index 000000000..deef10539
--- /dev/null
+++ b/.github/workflows/scheduled_test_typing.yml
@@ -0,0 +1,45 @@
+name: (scheduled) Run typing tests
+
+on:
+ push:
+ branches: [master]
+ schedule:
+ - cron: "0 4 * * *"
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ tests:
+ name: ${{ matrix.os }} - python-${{ matrix.python-version }}, torch-${{ matrix.pytorch-version }}
+ runs-on: ${{ matrix.os }}
+
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [ubuntu-latest]
+ python-version: ['3.7']
+ pytorch-version: ['1.9.1', '1.10.2', '1.12.1', '1.13.0', 'nightly']
+
+ steps:
+ - name: Checkout kornia
+ uses: actions/checkout@v3
+
+ - name: Setting environment on ${{ matrix.os }} with python ${{ matrix.python-version }} and pytorch ${{ matrix.pytorch-version }}
+ uses: ./.github/actions/env
+ with:
+ python-version: ${{ matrix.python-version }}
+ pytorch-version: ${{ matrix.pytorch-version }}
+
+ - name: Run typing tests
+ shell: bash -l {0}
+ run: mypy --cobertura-xml-report ./
+
+ - if: always()
+ name: Upload coverage
+ uses: codecov/codecov-action@v3
+ with:
+ file: cobertura.xml
+ flags: typing,${{ matrix.os }}_python-${{ matrix.python-version }}_torch-${{ matrix.pytorch-version }}
+ name: cpu-coverage-types
diff --git a/.github/workflows/test_typing.yml b/.github/workflows/test_typing.yml
deleted file mode 100644
index 43277b698..000000000
--- a/.github/workflows/test_typing.yml
+++ /dev/null
@@ -1,46 +0,0 @@
-name: test-typing
-
-on:
- push:
- branches: [master]
- pull_request:
- branches: [master]
- types: [open, reopened, synchronize, review_requested, ready_for_review]
- schedule:
- - cron: "0 4 * * *"
-
-concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
- cancel-in-progress: true
-
-jobs:
- tests-cpu:
- runs-on: ${{ matrix.os }}
- strategy:
- fail-fast: false
- matrix:
- os: [ubuntu-latest]
- python-version: [3.8]
- steps:
- - uses: actions/checkout@v2
- - name: Setup conda dependencies
- uses: conda-incubator/setup-miniconda@v2
- with:
- auto-update-conda: true
- python-version: ${{ matrix.python-version }}
- - name: Install dependencies
- shell: bash -l {0}
- run: |
- conda install curl -c conda-forge
- conda install pytorch cpuonly -c pytorch-lts
- pip install .[dev,x]
- - name: Run Tests
- shell: bash -l {0}
- run: pytest -v --cov=kornia --cov-report xml --mypy kornia/
- - name: Upload coverage
- uses: codecov/codecov-action@v1
- with:
- token: ${{ secrets.CODECOV_TOKEN }}
- file: coverage.xml
- flags: cpu,pytest,typing
- name: cpu-coverage
diff --git a/.github/workflows/tests_cpu.yml b/.github/workflows/tests_cpu.yml
deleted file mode 100644
index 20ae6b4bb..000000000
--- a/.github/workflows/tests_cpu.yml
+++ /dev/null
@@ -1,47 +0,0 @@
-name: tests-cpu
-
-on:
- push:
- branches: [master]
- pull_request:
- branches: [master]
- types: [open, reopened, synchronize, review_requested, ready_for_review]
- schedule:
- - cron: "0 4 * * *"
-
-concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
- cancel-in-progress: true
-
-jobs:
- tests-cpu:
- runs-on: ${{ matrix.os }}
- strategy:
- fail-fast: false
- matrix:
- os: [ubuntu-latest, macos-latest, windows-latest]
- python-version: [3.7, 3.8, 3.9]
- pytorch-version: [1.10.2, 1.12.1]
- steps:
- - uses: actions/checkout@v2
- - name: Setup conda dependencies
- uses: conda-incubator/setup-miniconda@v2
- with:
- auto-update-conda: true
- python-version: ${{ matrix.python-version }}
- - name: Install dependencies
- shell: bash -l {0}
- run: |
- conda install curl -c conda-forge
- conda install pytorch=${{ matrix.pytorch-version }} cpuonly -c pytorch
- pip install .[dev,x]
- - name: Run Tests
- shell: bash -l {0}
- run: pytest -v --device cpu --dtype float32,float64 --cov=kornia --cov-report xml ./test
- - name: Upload coverage
- uses: codecov/codecov-action@v1
- with:
- token: ${{ secrets.CODECOV_TOKEN }}
- file: coverage.xml
- flags: cpu,pytest, torch${{ matrix.pytorch-version }}
- name: cpu-coverage
diff --git a/.github/workflows/tests_lts.yml b/.github/workflows/tests_lts.yml
deleted file mode 100644
index 62732af1c..000000000
--- a/.github/workflows/tests_lts.yml
+++ /dev/null
@@ -1,46 +0,0 @@
-name: tests-lts
-
-on:
- push:
- branches: [master]
- pull_request:
- branches: [master]
- types: [open, reopened, synchronize, review_requested, ready_for_review]
- schedule:
- - cron: "0 4 * * *"
-
-concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
- cancel-in-progress: true
-
-jobs:
- tests-cpu:
- runs-on: ${{ matrix.os }}
- strategy:
- fail-fast: false
- matrix:
- os: [ubuntu-latest, windows-latest]
- python-version: [3.7, 3.8]
- steps:
- - uses: actions/checkout@v2
- - name: Setup conda dependencies
- uses: conda-incubator/setup-miniconda@v2
- with:
- auto-update-conda: true
- python-version: ${{ matrix.python-version }}
- - name: Install dependencies
- shell: bash -l {0}
- run: |
- conda install curl -c conda-forge
- conda install pytorch cpuonly -c pytorch-lts
- pip install .[dev,x]
- - name: Run Tests
- shell: bash -l {0}
- run: pytest -v --device cpu --dtype float32,float64 --cov=kornia --cov-report xml ./test
- - name: Upload coverage
- uses: codecov/codecov-action@v1
- with:
- token: ${{ secrets.CODECOV_TOKEN }}
- file: coverage.xml
- flags: cpu,pytest,torch-lts-1.8.2
- name: cpu-coverage
diff --git a/.github/workflows/tests_nightly.yml b/.github/workflows/tests_nightly.yml
deleted file mode 100644
index 95c3651ac..000000000
--- a/.github/workflows/tests_nightly.yml
+++ /dev/null
@@ -1,34 +0,0 @@
-name: test-nightly
-
-on:
- #push:
- # branches:
- # - master
- #pull_request:
- schedule:
- - cron: "0 4 * * *"
-
-jobs:
- test-cpu-versions:
- runs-on: ${{ matrix.os }}
- strategy:
- fail-fast: false
- matrix:
- os: [ubuntu-latest, macos-latest, windows-latest]
- python-version: [3.7, 3.8]
- steps:
- - uses: actions/checkout@v2
- - name: Setup conda dependencies
- uses: conda-incubator/setup-miniconda@v2
- with:
- auto-update-conda: true
- python-version: ${{ matrix.python-version }}
- - name: Install dependencies
- shell: bash -l {0}
- run: |
- conda install curl -c conda-forge
- conda install pytorch cpuonly -c pytorch-nightly
- pip install .[dev,x]
- - name: Run Tests
- shell: bash -l {0}
- run: pytest -v --device cpu --dtype float32,float64 ./test
diff --git a/Makefile b/Makefile
index 9be38a65e..c3815e3aa 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,9 @@
.PHONY: test test-cpu test-cuda lint mypy build-docs install uninstall FORCE
test: mypy lint build-docs test-all
-# TODO: Add cuda-float16 when #649 is solved
+
test-all: FORCE
- pytest -v --device all --dtype float32,float64 --cov=kornia test/ --flake8 --mypy
+ pytest -v --device all --dtype all --cov=kornia test/
test-cpu: FORCE
pytest -v --device cpu --dtype all --cov=kornia test/
@@ -36,7 +36,7 @@ lint: FORCE
flake8 -v kornia/ test/ examples/
mypy: FORCE
- pytest -v --cache-clear --mypy kornia/ -m mypy
+ mypy
yapf: FORCE
yapf --in-place --parallel --recursive kornia/ test/ examples/
diff --git a/kornia/enhance/core.py b/kornia/enhance/core.py
index b72af4d8e..037673fdd 100644
--- a/kornia/enhance/core.py
+++ b/kornia/enhance/core.py
@@ -1,8 +1,12 @@
-from kornia.core import Module, Tensor
+from typing import Union
+
+from kornia.core import Module, Tensor, tensor
from kornia.testing import KORNIA_CHECK, KORNIA_CHECK_IS_TENSOR
-def add_weighted(src1: Tensor, alpha, src2: Tensor, beta, gamma) -> Tensor:
+def add_weighted(
+ src1: Tensor, alpha: Union[float, Tensor], src2: Tensor, beta: Union[float, Tensor], gamma: Union[float, Tensor]
+) -> Tensor:
r"""Calculate the weighted sum of two Tensors.
.. image:: _static/img/add_weighted.png
@@ -35,12 +39,21 @@ def add_weighted(src1: Tensor, alpha, src2: Tensor, beta, gamma) -> Tensor:
KORNIA_CHECK_IS_TENSOR(src1)
KORNIA_CHECK_IS_TENSOR(src2)
KORNIA_CHECK(src1.shape == src2.shape, f"src1 and src2 have different shapes. Got {src1.shape} and {src2.shape}")
+
if isinstance(alpha, Tensor):
KORNIA_CHECK(src1.shape == alpha.shape, "alpha has a different shape than src.")
+ else:
+ alpha = tensor(alpha, dtype=src1.dtype, device=src1.device)
+
if isinstance(beta, Tensor):
KORNIA_CHECK(src1.shape == beta.shape, "beta has a different shape than src.")
+ else:
+ beta = tensor(beta, dtype=src1.dtype, device=src1.device)
+
if isinstance(gamma, Tensor):
KORNIA_CHECK(src1.shape == gamma.shape, "gamma has a different shape than src.")
+ else:
+ gamma = tensor(gamma, dtype=src1.dtype, device=src1.device)
return src1 * alpha + src2 * beta + gamma
diff --git a/setup.cfg b/setup.cfg
index 8cccc3e9b..3ad7f2e93 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -57,13 +57,13 @@ dev =
flake8==5.0.4
isort
kornia-rs==0.0.5
+ mypy[reports]
numpy
opencv-python
pre-commit>=2.0
pydocstyle
pytest==7.2.0
pytest-cov==4.0.0
- pytest-mypy==0.10.1
scipy
docs =
PyYAML>=5.1,<6.1.0