From db63e2056ce587253fdbc228a915121e9ebc05f7 Mon Sep 17 00:00:00 2001 From: Greg Starr Date: Wed, 24 May 2023 12:57:21 -0400 Subject: [PATCH 1/5] adding pyproject.toml and basic test --- pyproject.toml | 27 +++++++++++++++++++++++++++ test/test_basic.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 pyproject.toml create mode 100644 test/test_basic.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..665673f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,27 @@ +[tool.poetry] +name = "volumentations-3d" +version = "1.0.4" +description = "Library for 3D augmentations" +authors = [ + "Roman Sol (ZFTurbo)", + "ashawkey", + "qubvel", + "muellerdo" +] +license = "MIT" +readme = "README.md" +packages = [{include = "volumentations_3d"}] + +[tool.poetry.dependencies] +python = ">=3.9, <3.12" +scikit-image = "^0.20.0" +opencv-python = "^4.7.0.72" +numpy = "^1.24.3" + +[tool.poetry.group.dev.dependencies] +pytest = "^7.3.1" +flake8 = "^6.0.0" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/test/test_basic.py b/test/test_basic.py new file mode 100644 index 0000000..706b625 --- /dev/null +++ b/test/test_basic.py @@ -0,0 +1,37 @@ +import pytest + +from volumentations import * + +augmentations = [ + CenterCrop, + ColorJitter, + Contiguous, + CropNonEmptyMaskIfExists, + Downscale, + ElasticTransform, + ElasticTransformPseudo2D, + Flip, + Float, + GaussianNoise, + GlassBlur, + GridDistortion, + GridDropout, + ImageCompression, + Normalize, + PadIfNeeded, + RandomBrightnessContrast, + RandomCrop, + RandomCropFromBorders, + RandomDropPlane, + RandomGamma, + RandomResizedCrop, + RandomRotate90, + RandomScale, + RandomScale2, + RemoveEmptyBorder, + Resize, + ResizedCropNonEmptyMaskIfExists, + Rotate, + RotatePseudo2D, + Transpose, +] From 71d84bccad568e809b8b71a8a60ff8b112991bc7 Mon Sep 17 00:00:00 2001 From: Greg Starr Date: Wed, 24 May 2023 13:29:31 -0400 Subject: [PATCH 2/5] basic_test finished --- pyproject.toml | 2 +- test/test_basic.py | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 665673f..ec09a62 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ authors = [ ] license = "MIT" readme = "README.md" -packages = [{include = "volumentations_3d"}] +packages = [{include = "volumentations"}] [tool.poetry.dependencies] python = ">=3.9, <3.12" diff --git a/test/test_basic.py b/test/test_basic.py index 706b625..4bb959f 100644 --- a/test/test_basic.py +++ b/test/test_basic.py @@ -1,12 +1,14 @@ import pytest +import numpy as np from volumentations import * + augmentations = [ CenterCrop, ColorJitter, Contiguous, - CropNonEmptyMaskIfExists, + # CropNonEmptyMaskIfExists, Downscale, ElasticTransform, ElasticTransformPseudo2D, @@ -30,8 +32,35 @@ RandomScale2, RemoveEmptyBorder, Resize, - ResizedCropNonEmptyMaskIfExists, + # ResizedCropNonEmptyMaskIfExists, Rotate, RotatePseudo2D, Transpose, ] + +arg_required = [ + CenterCrop, + CropNonEmptyMaskIfExists, + PadIfNeeded, + RandomCrop, + RandomResizedCrop, + Resize, + ResizedCropNonEmptyMaskIfExists, +] + + +@pytest.fixture(scope="module") +def cube(): + X, Y, Z = np.mgrid[-8:8:40j, -8:8:40j, -8:8:40j] + values = np.sin(X*Y*Z) / (X*Y*Z) + return values + + +@pytest.mark.parametrize("aug_class", augmentations) +def test_augmentations(aug_class, cube): + if aug_class in arg_required: + aug = aug_class(shape=(30, 30, 30)) + else: + aug = aug_class() + new_cube = aug(True, "image", image=cube)["image"] + print(aug_class.__name__, new_cube.shape) From 930c81affcd6084ba2407ce14a87ed12a5d4905a Mon Sep 17 00:00:00 2001 From: Greg Starr Date: Wed, 24 May 2023 13:39:13 -0400 Subject: [PATCH 3/5] adding python packge github action --- .github/workflows/python-package.yml | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/python-package.yml diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..47ba5ea --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,37 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + push: + branches: [ "master", "develop" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install poetry + poetry install --with dev + - name: Lint with flake8 + run: | + poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + - name: Test with pytest + run: | + pytest From c485a771c7e73e6ce2136bd8283ea6ffccde9e40 Mon Sep 17 00:00:00 2001 From: Greg Starr Date: Wed, 24 May 2023 13:42:29 -0400 Subject: [PATCH 4/5] small linting fix --- .github/workflows/python-package.yml | 2 +- volumentations/augmentations/functional.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 47ba5ea..ccea277 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -31,7 +31,7 @@ jobs: poetry install --with dev - name: Lint with flake8 run: | - poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + poetry run flake8 ./volumentations --count --select=E9,F63,F7,F82 --show-source --statistics - name: Test with pytest run: | pytest diff --git a/volumentations/augmentations/functional.py b/volumentations/augmentations/functional.py index d04c8e3..9170ba3 100644 --- a/volumentations/augmentations/functional.py +++ b/volumentations/augmentations/functional.py @@ -43,6 +43,8 @@ from scipy.ndimage import gaussian_filter from scipy.ndimage import map_coordinates from warnings import warn +from itertools import product + MAX_VALUES_BY_DTYPE = { np.dtype("uint8"): 255, From 4ca2a6034b22a6bc62756bcbc19bf3a09a73ab78 Mon Sep 17 00:00:00 2001 From: Gregory Starr Date: Wed, 24 May 2023 13:44:43 -0400 Subject: [PATCH 5/5] pytest command fix in python-package.yml --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index ccea277..bdf6eab 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -34,4 +34,4 @@ jobs: poetry run flake8 ./volumentations --count --select=E9,F63,F7,F82 --show-source --statistics - name: Test with pytest run: | - pytest + poetry run pytest