Skip to content

Commit

Permalink
Tests and deps fixed to support the newest packages
Browse files Browse the repository at this point in the history
  • Loading branch information
lext committed Jul 11, 2022
1 parent 1d28da0 commit fae62de
Show file tree
Hide file tree
Showing 11 changed files with 550 additions and 172 deletions.
17 changes: 10 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
repos:
- repo: https://github.com/ambv/black
rev: 19.10b0
rev: 22.6.0
hooks:
- id: black
args: [--config=black.toml]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
args: [--max-line-length=120]
exclude: ^tests/
- id: check-case-conflict
- id: check-symlinks
- id: end-of-file-fixer
- id: requirements-txt-fixer
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-case-conflict
- id: check-symlinks
- id: end-of-file-fixer
- id: requirements-txt-fixer
9 changes: 5 additions & 4 deletions ci/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
black==19.10b0
codecov==2.0.15
black-22.6.0
codecov-2.1.12
coverage==5.0.3
ipykernel==4.8.2
msmb-theme==1.2.0
nbsphinx-link==1.2
opencv-python-headless==4.1.2.30
#opencv-python-headless==4.1.2.30
opencv-python-headless==4.6.0.66
pytest==3.6.4
pytest-cov==2.6.0
pytest-flake8==1.0.2
pytest-flake8-1.1.1
pytest-pep8==1.0.6
sphinx==1.8.4
sphinx-rtd-theme==0.4.1
Expand Down
10 changes: 9 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, "solt", "solt Documentation", author, "solt", "One line description of project.", "Miscellaneous",),
(
master_doc,
"solt",
"solt Documentation",
author,
"solt",
"One line description of project.",
"Miscellaneous",
),
]


Expand Down
23 changes: 20 additions & 3 deletions solt/core/_base_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,14 @@ def wrap_data(data):
return data

def __call__(
self, data, return_torch=False, as_dict=True, scale_keypoints=True, normalize=True, mean=None, std=None,
self,
data,
return_torch=False,
as_dict=True,
scale_keypoints=True,
normalize=True,
mean=None,
std=None,
):
"""
Applies the transform to a DataContainer
Expand Down Expand Up @@ -184,7 +191,11 @@ def __call__(

if return_torch:
return res.to_torch(
as_dict=as_dict, scale_keypoints=scale_keypoints, normalize=normalize, mean=mean, std=std,
as_dict=as_dict,
scale_keypoints=scale_keypoints,
normalize=normalize,
mean=mean,
std=std,
)
return res

Expand Down Expand Up @@ -349,7 +360,13 @@ class MatrixTransform(BaseTransform, InterpolationPropertyHolder, PaddingPropert
"""

def __init__(
self, interpolation="bilinear", padding="z", p=0.5, ignore_state=True, affine=True, ignore_fast_mode=False,
self,
interpolation="bilinear",
padding="z",
p=0.5,
ignore_state=True,
affine=True,
ignore_fast_mode=False,
):
BaseTransform.__init__(self, p=p, data_indices=None)
InterpolationPropertyHolder.__init__(self, interpolation=interpolation)
Expand Down
50 changes: 42 additions & 8 deletions solt/core/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ class Stream(Serializable):
How the class should be stored in the registry"""

def __init__(
self, transforms=None, interpolation=None, padding=None, optimize_stack=False, ignore_fast_mode=False,
self,
transforms=None,
interpolation=None,
padding=None,
optimize_stack=False,
ignore_fast_mode=False,
):
super(Stream, self).__init__()

Expand Down Expand Up @@ -118,7 +123,14 @@ def reset_padding(self, value):
trf.reset_padding(self.padding)

def __call__(
self, data, return_torch=True, as_dict=True, scale_keypoints=True, normalize=True, mean=None, std=None,
self,
data,
return_torch=True,
as_dict=True,
scale_keypoints=True,
normalize=True,
mean=None,
std=None,
):
"""
Executes the list of the pre-defined transformations for a given data container.
Expand Down Expand Up @@ -153,7 +165,11 @@ def __call__(

if return_torch:
return res.to_torch(
as_dict=as_dict, scale_keypoints=scale_keypoints, normalize=normalize, mean=mean, std=std,
as_dict=as_dict,
scale_keypoints=scale_keypoints,
normalize=normalize,
mean=mean,
std=std,
)
return res

Expand Down Expand Up @@ -242,7 +258,12 @@ class SelectiveStream(Stream):
"""How the class should be stored in the registry"""

def __init__(
self, transforms=None, n=1, probs=None, optimize_stack=False, ignore_fast_mode=False,
self,
transforms=None,
n=1,
probs=None,
optimize_stack=False,
ignore_fast_mode=False,
):
"""
Constructor.
Expand All @@ -257,7 +278,9 @@ def __init__(
Whether to execute stack optimization for augmentations.
"""
super(SelectiveStream, self).__init__(
transforms=transforms, optimize_stack=optimize_stack, ignore_fast_mode=ignore_fast_mode,
transforms=transforms,
optimize_stack=optimize_stack,
ignore_fast_mode=ignore_fast_mode,
)
if transforms is None:
transforms = []
Expand All @@ -270,7 +293,14 @@ def __init__(
self.probs = probs

def __call__(
self, data, return_torch=True, as_dict=True, scale_keypoints=True, normalize=True, mean=None, std=None,
self,
data,
return_torch=True,
as_dict=True,
scale_keypoints=True,
normalize=True,
mean=None,
std=None,
):
"""
Applies randomly selected n transforms to the given data item
Expand Down Expand Up @@ -302,7 +332,7 @@ def __call__(
data = BaseTransform.wrap_data(data)

if len(self.transforms) > 0:
random_state = np.random.RandomState(random.randint(0, 2 ** 32 - 1))
random_state = np.random.RandomState(random.randint(0, 2**32 - 1))
trfs = random_state.choice(self.transforms, self.n, replace=False, p=self.probs)
if self.optimize_stack:
trfs = [copy.deepcopy(x) for x in trfs]
Expand All @@ -311,7 +341,11 @@ def __call__(

if return_torch:
return data.to_torch(
as_dict=as_dict, scale_keypoints=scale_keypoints, normalize=normalize, mean=mean, std=std,
as_dict=as_dict,
scale_keypoints=scale_keypoints,
normalize=normalize,
mean=mean,
std=std,
)

return data
6 changes: 5 additions & 1 deletion solt/core/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ def __init__(self, data, fmt, transform_settings=None):
transform_settings[idx]["padding"] = validate_parameter(None, ALLOWED_PADDINGS, "z", str, True)
else:
transform_settings[idx]["padding"] = validate_parameter(
(transform_settings[idx]["padding"], "strict"), ALLOWED_PADDINGS, "z", str, True,
(transform_settings[idx]["padding"], "strict"),
ALLOWED_PADDINGS,
"z",
str,
True,
)
else:
if "interpolation" in transform_settings[idx] or "padding" in transform_settings[idx]:
Expand Down
30 changes: 23 additions & 7 deletions solt/transforms/_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ class Rotate(MatrixTransform):
"""How the class should be stored in the registry"""

def __init__(
self, angle_range=None, interpolation="bilinear", padding="z", p=0.5, ignore_state=True, ignore_fast_mode=False,
self,
angle_range=None,
interpolation="bilinear",
padding="z",
p=0.5,
ignore_state=True,
ignore_fast_mode=False,
):
super(Rotate, self).__init__(
interpolation=interpolation,
Expand Down Expand Up @@ -614,7 +620,11 @@ def _apply_pts(self, pts: Keypoints, settings: dict):
pts_data[:, 0] += pad_w_left
pts_data[:, 1] += pad_h_top

return Keypoints(pts_data, pad_h_top + pts.height + pad_h_bottom, pad_w_left + pts.width + pad_w_right,)
return Keypoints(
pts_data,
pad_h_top + pts.height + pad_h_bottom,
pad_w_left + pts.width + pad_w_right,
)


class Resize(BaseTransform, InterpolationPropertyHolder):
Expand Down Expand Up @@ -820,7 +830,7 @@ def sample_transform(self, data: DataContainer):
if w is None or h is None or c is None:
raise ValueError

random_state = np.random.RandomState(random.randint(0, 2 ** 32 - 1))
random_state = np.random.RandomState(random.randint(0, 2**32 - 1))
noise_img = random_state.randn(h, w, c)

noise_img -= noise_img.min()
Expand All @@ -833,7 +843,11 @@ def sample_transform(self, data: DataContainer):
@img_shape_checker
def _apply_img(self, img: np.ndarray, settings: dict):
return cv2.addWeighted(
img, (1 - self.state_dict["gain"]), self.state_dict["noise"], self.state_dict["gain"], 0,
img,
(1 - self.state_dict["gain"]),
self.state_dict["noise"],
self.state_dict["gain"],
0,
)

def _apply_mask(self, mask: np.ndarray, settings: dict):
Expand Down Expand Up @@ -960,7 +974,7 @@ def sample_transform(self, data: DataContainer):
gain = random.uniform(self.gain_range[0], self.gain_range[1])
salt_p = random.uniform(self.salt_p[0], self.salt_p[1])

random_state = np.random.RandomState(random.randint(0, 2 ** 32 - 1))
random_state = np.random.RandomState(random.randint(0, 2**32 - 1))
sp = random_state.rand(h, w) <= gain
salt = sp.copy() * 1.0
pepper = sp.copy() * 1.0
Expand Down Expand Up @@ -1140,7 +1154,9 @@ def sample_transform(self, data):
def _apply_img(self, img: np.ndarray, settings: dict):
if self.blur == "g":
return cv2.GaussianBlur(
img, ksize=(self.state_dict["k_size"], self.state_dict["k_size"]), sigmaX=self.state_dict["sigma"],
img,
ksize=(self.state_dict["k_size"], self.state_dict["k_size"]),
sigmaX=self.state_dict["sigma"],
)
if self.blur == "m":
return cv2.medianBlur(img, ksize=self.state_dict["k_size"])
Expand Down Expand Up @@ -1531,7 +1547,7 @@ def __init__(self, d_range=None, ratio=0.6, rotate=0, mode=None, data_indices=No
def sample_transform(self, data: DataContainer):
h, w = super(GridMask, self).sample_transform(data)

hh = int(np.ceil(np.sqrt(h ** 2 + w ** 2)))
hh = int(np.ceil(np.sqrt(h**2 + w**2)))
d = random.randint(self.d_range[0], self.d_range[1])

mask = np.ones((hh, hh), np.float32)
Expand Down
Loading

0 comments on commit fae62de

Please sign in to comment.