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

Add groups parameter to nengo.Convolution #1675

Open
Michaeljurado42 opened this issue Aug 5, 2021 · 2 comments
Open

Add groups parameter to nengo.Convolution #1675

Michaeljurado42 opened this issue Aug 5, 2021 · 2 comments

Comments

@Michaeljurado42
Copy link

nengo.Convolution supports many of the same arguments and options as its keras counterpart. However there is no groups parameter in nengo as in the keras docs for Conv2D.

A groups paramter would be useful to allow for more robust conversions between keras networks and nengo networks via the dl converter. This would also allow people to implement depthwise convolutions with ease also in nengo.

@Michaeljurado42
Copy link
Author

Michaeljurado42 commented Aug 9, 2021

It seems to fix this method you have to add a groups parameter to the conv2d function found here

This is my fix:

def conv2d(x, w, pad='SAME', stride=(1, 1), groups = 1):
    ksize = w.shape[:2]
    x = extract_sliding_windows(x, ksize, pad, stride)
    ws = w.shape
    w = w.reshape([ws[0] * ws[1] * ws[2], ws[3]])
    xs = x.shape

    if groups == 1:
        x = x.reshape([xs[0] * xs[1] * xs[2], -1])
    else:
         x = x.reshape([xs[0] * xs[1] * xs[2], groups, -1])  # seperate input into groups

    y = x.dot(w)  # convolve all
    if groups > 1:
        y = np.sum(y, -2)  # sum up along groups
    y = y.reshape([xs[0], xs[1], xs[2], -1])
    return y

Then you have to manually edit or extend ConvInc found here to use the groups parameter

You have to modify the convolution transform found here and register it with the Builder.

I may edit and elaborate on this process in the coming weeks

@Michaeljurado42
Copy link
Author

Sorry I did not mean to close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant