juliaflux.jlflux-machine-learning

How to do Adaptive average pooling in Flux.jl


I have seen that adaptive average pooling is available both in Tensor Flow and PyTorch.

I am wondering how this can be achieved in Flux.jl?


Solution

  • Flux actually does have a built in function which creates an Adaptive pooling layer:

    julia> xs = rand(Float32, 100, 100, 3, 50);  # batch of 50 RGB images
    
    julia> AdaptiveMeanPool((25, 25))(xs) |> size
    (25, 25, 3, 50)
    

    As you can see in the above example, it expects two additional array elements as input in addition to N feature dimensions. In this case, there are two feature dimensions (100, 100). Three represents the number of channels of the images (Red, Green, and Blue) and the 50 represents the number of images.