Giter Site home page Giter Site logo

Comments (2)

chaoyu3 avatar chaoyu3 commented on June 16, 2024 2

Pytorch has AdaptivePooling implementation here:

https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/AdaptivePooling.h
https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/cpu/AdaptiveAvgPoolKernel.cpp

If the input size is an integer multiple of the output for your case, the adaptive max pooling can be replaced by max pooling from oneDNN.
the stride and kernel size can be pre-calculated from input and output size, like:
stride = kernel = input size/ output size.

but, if the input size is not an integer multiple of the output, the current oneDNN max pooling can not product the exactly the same output with AdaptivePooling:

See the bellow code which is similar with Pytorch on steps/kernel computation for adaptive pooling,

inline int start_index(int a, int b, int c) {
        return (a / b) * c + ((a % b) * c) / b;
}
inline int end_index(int a, int b, int c) {
        return 1 + ((a + 1) * c - 1) / b;
}

int main() {
    int osize = 6;
    int isize = 10;
    for (int oh = 0; oh < osize; ++oh) {
        int istart = start_index(oh, osize, isize);
        int iend   = end_index(oh, osize, isize);
        int k = iend - istart;
        std::cout << "oh: " << oh << ", istart: " << istart << ", iend: " << iend << ", kernel: " << k << std::endl;
    }
    return 0;
}

the stride and kernel change when input size is not an integer multiple of ouput in some cases.
For example, when input size is 10, output is 6:
oh: 0, istart: 0, iend: 2, kernel: 2
oh: 1, istart: 1, iend: 4, kernel: 3
oh: 2, istart: 3, iend: 5, kernel: 2
oh: 3, istart: 5, iend: 7, kernel: 2
oh: 4, istart: 6, iend: 9, kernel: 3
oh: 5, istart: 8, iend: 10, kernel: 2

from onednn.

feixuedudiao avatar feixuedudiao commented on June 16, 2024

ths

from onednn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.