Skip to content

Implement average poolings and try to generalize the functions #207

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

Open
ricor07 opened this issue Feb 24, 2025 · 4 comments
Open

Implement average poolings and try to generalize the functions #207

ricor07 opened this issue Feb 24, 2025 · 4 comments
Assignees

Comments

@ricor07
Copy link
Collaborator

ricor07 commented Feb 24, 2025

I'd like to implement functions such as averagepooling, globalmaxpooling and globalaveragepooling. Since all of this have a 1d, a 2d and a 3d implementation, i think it is possible to write this as an unique function, just as how input was done.

@ricor07 ricor07 self-assigned this Feb 24, 2025
@milancurcic
Copy link
Member

Back to the topic of how to make 1d/2d/3d constructors behind generic names.

For the reshape (what should now be called reshape3d) and reshape2d layers, it's straightforward because the output shape needs to be provided to the constructor, and so a type-kind-rank distinction can be made, like we did with input layers.

However, it's not clear to me how we can make conv1d/2d and maxpool1d/2d generic, as either 1d or 2d variants take pool size and stride integers as input, which can't be used to make a type-kind-rank distinction.

Any ideas?

@milancurcic
Copy link
Member

A potential approach to make conv1d/2d, maxpool1d/2d generic is not at the constructor function, but in the internal implementation of the layer itself, for example instead of the current approach of:

type conv1d_layer, extends(base_layer)
  ...
contains
  procedure :: forward, backward
  ...

and

type conv2d_layer, extends(base_layer)
  ...
contains
  procedure :: forward, backward
  ...

we could have one conv_layer type for all ranks

type conv_layer, extends(base_layer)
  ...
contains
  procedure :: forward1d, forward2d
  procedure :: backward1d, backward2d
  generic :: forward => forward1d, forward2d
  generic :: backward => backward1d, backward2d
  ...

(the specific syntax may be incorrect but should give you an idea)

Then, the generic conv % forward and conv % backward is resolved based on the input and gradient array ranks..

@ricor07
Copy link
Collaborator Author

ricor07 commented Mar 14, 2025

I would just write a basic function called conv or maxpool, which takes the shape of the input array and then calls the other functions (not accessible to user) maxpool1d, 2d or 3d. But I think there are better solutions. Let me know. If you want we can also have a call

@milancurcic
Copy link
Member

It's possible but it would make the API not as nice as it is now, as it would require the user to keep track of the shape of the data as it moves from layer to layer. I agree that it would be good to have a call to discuss this and a few other design choices between you, me, @OneAdder and @jvdp1, and possibly others. I'll be busy with travel until March 25, after which I'll be on central european time which is the same as @jvdp1 and is closer to @OneAdder's local time. I'll follow up soon to find a time.

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

No branches or pull requests

2 participants