Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use np-conv2d from PyPI #1686

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nengobones.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ setup_py:
- nengo = pytest_nengo
install_req:
- numpy>=1.19
- np-conv2d>=1.0.0
docs_req:
- sphinx>=1.8
- jupyter
Expand Down
54 changes: 1 addition & 53 deletions nengo/builder/tests/test_transforms_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from nengo.builder.signal import Signal
from nengo.builder.tests.test_operator import _test_operator_arg_attributes
from nengo.builder.transforms import ConvInc, ConvTransposeInc, conv2d_gradx
from nengo.builder.transforms import ConvInc, ConvTransposeInc
from nengo.transforms import ChannelShape, Convolution, ConvolutionTranspose


Expand Down Expand Up @@ -281,58 +281,6 @@ def debug_convtransposeinc_2d(w, wt, x, xt, y, yt, conv, conv_transpose, plt):
assert False, f"Output {i} channel {k} differs"


@pytest.mark.parametrize("x_size", (1, 2, 3, 4))
@pytest.mark.parametrize("k_size", (1, 2, 3, 4))
@pytest.mark.parametrize("stride", (1, 2, 3, 4))
@pytest.mark.parametrize("padding", ("same", "valid"))
def test_conv2d_gradx(padding, stride, k_size, x_size, rng, plt, allclose):
tf = pytest.importorskip("tensorflow")

in_channels = 1
out_channels = 1

if padding == "same":
y_min = (x_size - 1) * stride + 1
y_max = x_size * stride
else:
y_min = (x_size - 1) * stride + k_size
y_max = x_size * stride + k_size - 1

bad_sizes = []
for y_size in range(y_min, y_max + 1):
x_shape = (1, x_size, x_size, in_channels)
y_shape = (1, y_size, y_size, out_channels)
k_shape = (k_size, k_size, out_channels, in_channels)

x = rng.uniform(-1, 1, size=x_shape)
kernel = rng.uniform(-1, 1, size=k_shape)
y_tf = tf.nn.conv2d_transpose(
x, kernel, y_shape, stride, padding=padding.upper()
).numpy()[0]

kernel_t = np.transpose(kernel, (0, 1, 3, 2))
y_np = conv2d_gradx(
kernel_t,
x,
xsize=y_shape[1:3],
pad=padding.upper(),
stride=(stride, stride),
)[0]

assert y_np.shape == y_tf.shape

if not allclose(y_np, y_tf):
plt.subplot(1, 2, 1)
plt.imshow(y_tf[..., 0], vmin=y_tf.min(), vmax=y_tf.max())
plt.subplot(1, 2, 2)
plt.imshow(y_np[..., 0], vmin=y_tf.min(), vmax=y_tf.max())
bad_sizes.append(y_size)

if len(bad_sizes) == 0:
plt.saveas = None
assert len(bad_sizes) == 0, (y_min, y_max, bad_sizes)


def test_convinc_attrs_decstr():
argnames = ["W", "X", "Y", "conv"]
non_signals = ["conv"]
Expand Down
Loading