Skip to content

Commit

Permalink
Merge pull request #657 from zimmerrol/dependencies
Browse files Browse the repository at this point in the history
Bump up versions of test dependencies
  • Loading branch information
zimmerrol committed Jan 31, 2022
2 parents ca8bc83 + 9e5a7b8 commit 43f4d2f
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 53 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
retry-with-backoff pip install -r tests/requirements.txt
- name: mypy (package)
run: |
mypy --install-types --non-interactive foolbox/
mypy -p foolbox
- name: mypy (tests)
run: |
Expand Down
2 changes: 1 addition & 1 deletion examples/zoo/mnist/foolbox_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def create() -> PyTorchModel:
nn.ReLU(),
nn.MaxPool2d(2),
nn.Dropout2d(0.25),
nn.Flatten(), # type: ignore
nn.Flatten(),
nn.Linear(9216, 128),
nn.ReLU(),
nn.Dropout2d(0.5),
Expand Down
2 changes: 1 addition & 1 deletion foolbox/attacks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def __call__( # type: ignore
if any(eps is None for eps in epsilons):
early_stop = None
else:
early_stop = min(epsilons)
early_stop = min(epsilons) # type: ignore

# run the actual attack
xp = self.run(model, x, criterion, early_stop=early_stop, **kwargs)
Expand Down
16 changes: 8 additions & 8 deletions foolbox/attacks/gen_attack_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def rescale_jax(x: ep.JAXTensor, target_shape: List[int]) -> ep.JAXTensor:

resize_rates = (target_shape[1] / x.shape[1], target_shape[2] / x.shape[2])

def interpolate_bilinear( # type: ignore
def interpolate_bilinear(
im: np.ndarray, rows: np.ndarray, cols: np.ndarray
) -> np.ndarray:
# based on http://stackoverflow.com/a/12729229
Expand All @@ -21,11 +21,11 @@ def interpolate_bilinear( # type: ignore
row_lo = np.floor(rows).astype(int)
row_hi = row_lo + 1

def cclip(cols: np.ndarray) -> np.ndarray: # type: ignore
return np.clip(cols, 0, ncols - 1)
def cclip(cols: np.ndarray) -> np.ndarray:
return np.clip(cols, 0, ncols - 1) # type: ignore

def rclip(rows: np.ndarray) -> np.ndarray: # type: ignore
return np.clip(rows, 0, nrows - 1)
def rclip(rows: np.ndarray) -> np.ndarray:
return np.clip(rows, 0, nrows - 1) # type: ignore

nrows, ncols = im.shape[-3:-1]

Expand All @@ -39,7 +39,7 @@ def rclip(rows: np.ndarray) -> np.ndarray: # type: ignore
wc = np.expand_dims((cols - col_lo) * (row_hi - rows), -1)
wd = np.expand_dims((cols - col_lo) * (rows - row_lo), -1)

return wa * Ia + wb * Ib + wc * Ic + wd * Id
return wa * Ia + wb * Ib + wc * Ic + wd * Id # type: ignore

nrows, ncols = img.shape[-3:-1]
deltas = (0.5 / resize_rates[0], 0.5 / resize_rates[1])
Expand All @@ -49,8 +49,8 @@ def rclip(rows: np.ndarray) -> np.ndarray: # type: ignore
rows_grid, cols_grid = np.meshgrid(rows - 0.5, cols - 0.5, indexing="ij")

img_resize_vec = interpolate_bilinear(img, rows_grid.flatten(), cols_grid.flatten())
img_resize = img_resize_vec.reshape(
img.shape[:-3] + (len(rows), len(cols)) + img.shape[-1:]
img_resize = np.reshape(
img_resize_vec, img.shape[:-3] + (len(rows), len(cols)) + img.shape[-1:]
)

return ep.JAXTensor(img_resize)
Expand Down
4 changes: 2 additions & 2 deletions foolbox/attacks/spatial_attack_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def transform_pt(
def create_meshgrid(x: torch.Tensor) -> torch.Tensor:
space_x = torch.linspace(-1, 1, n_x, device=x.device)
space_y = torch.linspace(-1, 1, n_y, device=x.device)
meshgrid = torch.meshgrid([space_x, space_y]) # type: ignore
meshgrid = torch.meshgrid([space_x, space_y])
ones = torch.ones(meshgrid[0].shape, device=x.device)
gridder = torch.stack([meshgrid[1], meshgrid[0], ones], dim=2)
grid = gridder[None, ...].repeat(bs, 1, 1, 1)[..., None]
Expand All @@ -62,7 +62,7 @@ def create_meshgrid(x: torch.Tensor) -> torch.Tensor:
new_coords = new_coords.squeeze_(-1)

# align_corners=True to match tf implementation
transformed_images = torch.nn.functional.grid_sample( # type: ignore
transformed_images = torch.nn.functional.grid_sample(
x, new_coords, mode="bilinear", padding_mode="zeros", align_corners=True
)
return astensor(transformed_images)
Expand Down
2 changes: 1 addition & 1 deletion foolbox/zoo/model_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ def load(
self, path: str, module_name: str = "foolbox_model", **kwargs: Any
) -> Model:
module = super()._import_module(path, module_name=module_name)
model = module.create(**kwargs) # type: ignore
model = module.create(**kwargs)
return cast(Model, model)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ pytest-cov==2.8.1
coverage==5.1
codecov==2.0.15
coveralls==1.10.0
mypy==0.770
mypy==0.931
pre-commit==2.3.0
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from setuptools import setup # type: ignore
from setuptools import setup
from setuptools import find_packages
from os.path import join, dirname

Expand All @@ -20,7 +20,7 @@
"numpy",
"scipy",
"setuptools",
"eagerpy==0.29.0",
"eagerpy>=0.30.0",
"GitPython>=3.0.7",
"typing-extensions>=3.7.4.1",
"requests>=2.24.0",
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def pytorch_simple_model(
import torch

class Model(torch.nn.Module):
def forward(self, x: torch.Tensor) -> torch.Tensor: # type: ignore
def forward(self, x: torch.Tensor) -> torch.Tensor:
x = torch.mean(x, 3)
x = torch.mean(x, 2)
return x
Expand Down
9 changes: 4 additions & 5 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
torch==1.4.0
torchvision==0.5.0
jaxlib==0.1.46
jax==0.1.66
tensorflow==2.5.0
torch==1.10.1
torchvision==0.11.2
jax[cpu]==0.2.17
tensorflow==2.6.2
numba==0.50.1
matplotlib==3.2.1
pillow==8.1.1
Expand Down
28 changes: 0 additions & 28 deletions tests/test_evaluate.py

This file was deleted.

4 changes: 2 additions & 2 deletions tests/test_gen_attack_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_rescale_axis(request: Any, dummy: ep.Tensor) -> None:
x_up_ep = rescale_images(x_ep, (16, 3, 128, 128), 1)
x_up = x_up_ep.numpy()

assert np.allclose(x_up_np, x_up)
assert np.allclose(x_up_np, x_up, atol=1e-5)


def test_rescale_axis_nhwc(request: Any, dummy: ep.Tensor) -> None:
Expand All @@ -39,4 +39,4 @@ def test_rescale_axis_nhwc(request: Any, dummy: ep.Tensor) -> None:
x_up_ep = rescale_images(x_ep, (16, 128, 128, 3), -1)
x_up = x_up_ep.numpy()

assert np.allclose(x_up_np, x_up)
assert np.allclose(x_up_np, x_up, atol=1e-5)
2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_pytorch_training_warning(request: Any) -> None:
import torch

class Model(torch.nn.Module):
def forward(self, x: torch.Tensor) -> torch.Tensor: # type: ignore
def forward(self, x: torch.Tensor) -> torch.Tensor:
return x

model = Model().train()
Expand Down

0 comments on commit 43f4d2f

Please sign in to comment.