Skip to content

Commit

Permalink
isort, flake8 => ruff (#1529)
Browse files Browse the repository at this point in the history
  • Loading branch information
ternaus authored Feb 21, 2024
1 parent e56fc0d commit 93b0aaa
Show file tree
Hide file tree
Showing 33 changed files with 1,404 additions and 877 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,5 @@ conda.recipe/
.gitingore

*.ipynb

.ruff_cache/
22 changes: 8 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: requirements-txt-fixer
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.2.2
hooks:
- id: pyupgrade
args: ["--py38-plus"]
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: [ "--profile", "black" ]
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
Expand All @@ -60,11 +59,6 @@ repos:
- id: python-check-blanket-noqa
- id: python-use-type-annotations
- id: text-unicode-replacement-char
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
exclude: ^setup.py
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![PyPI version](https://badge.fury.io/py/albumentations.svg)](https://badge.fury.io/py/albumentations)
![CI](https://github.com/albumentations-team/albumentations/workflows/CI/badge.svg)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

Albumentations is a Python library for image augmentation. Image augmentation is used in deep learning and computer vision tasks to increase the quality of trained models. The purpose of image augmentation is to create new training samples from the existing data.

Expand All @@ -19,6 +20,7 @@ Here is an example of how you can apply some [pixel-level](#pixel-level-transfor
- The library is [**widely used**](#who-is-using-albumentations) in industry, deep learning research, machine learning competitions, and open source projects.

## Table of contents

- [Albumentations](#albumentations)
- [Why Albumentations](#why-albumentations)
- [Table of contents](#table-of-contents)
Expand Down
15 changes: 8 additions & 7 deletions albumentations/augmentations/blur/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

__all__ = ["blur", "median_blur", "gaussian_blur", "glass_blur"]

TWO = 2
EIGHT = 8


@preserve_shape
def blur(img: np.ndarray, ksize: int) -> np.ndarray:
Expand Down Expand Up @@ -63,9 +66,9 @@ def glass_blur(
range(img.shape[1] - max_delta, max_delta, -1),
)
):
ind = ind if ind < len(dxy) else ind % len(dxy)
dy = dxy[ind, i, 0]
dx = dxy[ind, i, 1]
idx = ind if ind < len(dxy) else ind % len(dxy)
dy = dxy[idx, i, 0]
dx = dxy[idx, i, 1]
x[h, w], x[h + dy, w + dx] = x[h + dy, w + dx], x[h, w]
else:
ValueError(f"Unsupported mode `{mode}`. Supports only `fast` and `exact`.")
Expand All @@ -75,7 +78,7 @@ def glass_blur(

def defocus(img: np.ndarray, radius: int, alias_blur: float) -> np.ndarray:
length = np.arange(-max(8, radius), max(8, radius) + 1)
ksize = 3 if radius <= 8 else 5
ksize = 3 if radius <= EIGHT else 5

x, y = np.meshgrid(length, length)
aliased_disk = np.array((x**2 + y**2) <= radius**2, dtype=np.float32)
Expand All @@ -101,6 +104,4 @@ def zoom_blur(img: np.ndarray, zoom_factors: Union[np.ndarray, Sequence[int]]) -
for zoom_factor in zoom_factors:
out += central_zoom(img, zoom_factor)

img = ((img + out) / (len(zoom_factors) + 1)).astype(img.dtype)

return img
return ((img + out) / (len(zoom_factors) + 1)).astype(img.dtype)
Loading

0 comments on commit 93b0aaa

Please sign in to comment.