Git Product home page Git Product logo

autopool's Introduction

autopool

Adaptive pooling operators for Multiple Instance Learning (documentation).

PyPI License Documentation Status PyPI - Python Version

AutoPool is an adaptive (trainable) pooling operator which smoothly interpolates between common pooling operators, such as min-, max-, or average-pooling, automatically adapting to the characteristics of the data.

AutoPool can be readily applied to any differentiable model for time-series label prediction. AutoPool is presented in the following paper, where it is evaluated in conjunction with convolutional neural networks for Sound Event Detection:

Adaptive pooling operators for weakly labeled sound event detection
Brian Mcfee, Justin Salamon, and Juan Pablo Bello
IEEE Transactions on Audio, Speech and Language Processing, In press, 2018.

Installation

To install the keras-based implementation:

python -m pip install autopool[keras]

For the tensorflow implementation:

python -m pip install autopool[tf]

Definition

AutoPool extends softmax-weighted pooling by adding a trainable parameter α to be learned jointly with all other trainable model parameters:

Here, p(Y|x) denotes the prediction for an instance x, and X denotes a set (bag) of instances. The aggregated prediction P(Y|X) is a weighted average of the instance-level predictions. Note that when α = 0 this reduces to an unweighted mean; when α = 1 this simplifies to soft-max pooling; and when α → ∞ this approaches the max operator. Hence the name: AutoPool.

Usage

AutoPool is implemented as a keras layer, so using it is as straightforward as using any standard Keras pooling layer, for example:

from autopool.keras import AutoPool1D
bag_pred = AutoPool1D(axis=1)(instance_pred)

Further details and examples are provided in the documentation.

Constrained and Regularized AutoPool

In the paper we show there can be benefits to either constraining the range α can take, or, alternatively, applying l2 regularization on α; this results in constrained AutoPool (CAP) and regularized AutoPool (RAP) respectively. Since AutoPool is implemented as a keras layer, CAP and RAP can be can be achieved through the layer's optional arugments:

CAP with non-negative α:

bag_pred = AutoPool1D(axis=1, kernel_constraint=keras.constraints.non_neg())(instance_pred)

CAP with α norm-constrained to some value alpha_max:

bag_pred = AutoPool1D(axis=1, kernel_constraint=keras.constraints.max_norm(alpha_max, axis=0))(instance_pred)

Heuristics for determining sensible values of alpha_max are given in the paper (section III.E).

RAP with l2 regularized α:

bag_pred = AutoPool1D(axis=1, kernel_regularizer=keras.regularizers.l2(l=1e-4))(instance_pred)

CAP and RAP can be combined, of course, by applying both a kernel constraint and a kernel regularizer.

If using the tensorflow-based implementation, all of the above will also work, except that keras should be replaced by tensorflow.keras (or tf.keras), e.g.:

import tensorflow as tf
from autopool.tf import AutoPool1D
bag_pred = AutoPool1D(axis=1, kernel_regularizer=tf.keras.regularizers.l2(l=1e-4))(instance_pred)

Multi-label

AutoPool directly generalizes to multi-label settings, in which multiple class labels may be applied to each instance x (for example "car" and "siren" may both be present in an instance). In this setting, a separate auto-pooling operator is applied to each class. Rather than a single parameter α, there is a vector of parameters α_c where c indexes the output vocabulary. This allows a jointly trained model to adapt the pooling strategies independently for each category. Please see the paper for further details.

autopool's People

Contributors

andreped avatar bmcfee avatar justinsalamon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

autopool's Issues

Evaluation

Hi @justinsalamon
i have a doubt regarding the evaluation implementation . during evaluation(testing) do we remove the aggregator layer to get instance level tagging. in that case the Alpha of the adaptive pooling layer is used only for training, pls clarify.

thanks
yuvaram

How to use Autopool for SED

Hi @justinsalamon ,
i am currently trying to implement the MIL approach for SED based on your adaptive pooling paper. https://arxiv.org/pdf/1804.10070.pdf. currently my implementation is not giving the intended results . i like to get your opinion on my implementation and correct me if i have missed any.

1.split the single track into 4 instance of 5sec each
2, converted them into melspec and passed to feature extractor made of conv layer followed by fully connected layer .
3, at the end of the previous step, the model will give sigmoid output for 4instance X n_classes.
4, this is passed on to my implememtation of Autopooling layer and will get a single vector containing n_classes weighted sigmoid values.
5, i am using BCEWithLogitsLoss in pytorch which is equivalent to BinaryCrossentropy with sigmoid layer in keras

pls share your thoughts on this.
thanks
yuvaram

Explanation on the call function

Hi ,
i am trying to understand the implementation by comparing it with the paper. currently i am not able to understand a particular code

def call(self, x, mask=None):
        scaled = self.kernel * x
        max_val = K.max(scaled, axis=self.axis, keepdims=True)
        softmax = K.exp(scaled - max_val)
        weights = softmax / K.sum(softmax, axis=self.axis, keepdims=True)
        return K.sum(x * weights, axis=self.axis, keepdims=False)

in this call function, we are subtracting max value from scaled softmax = K.exp(scaled - max_val). but , i am not able to find this part on the paper . pls explain.

Autopool2D

I guess the image folks could benefit from a 2D autopool implementation. Does anyone feel like taking a crack at generalizing our implementation?

Restructuring for multiple backends

Tagging @justinsalamon for some input on this, should be easy.

The reference implementation of autopool is tied to old-style Keras, and that's cool. PR #12 updates this to work with v2.2 and up. However, it is recommended at this point that keras-dependent code target the tf.keras backend instead of the standalone package.

I think we should still provide the old-style interface (for historical reasons), but we should also have a tf.keras-facing implementation.

At the same time, we may as well provide a pytorch implementation as well.

I think the sensible way to approach this is by having different submodules for each backend, eg autopool.keras, autopool.tf, autopool.torch from which you would import the AutoPool/SoftMaxPool classes.

The only hiccup here is that the import structure changes. Instead of the previous

from autopool import AutoPool1D

you would have

from autopool.keras import AutoPool1D

or

from autopool.torch import AutoPool1D

(not unlike from tqdm.notebook import tqdm).

What do you think?

Images for readme

This issue contains all images needed for the README file.

Equations

autopool_formula

paremeter question

hi, I want to figure out if the instance_pred in the code bag_pred = AutoPool(axis=1, kernel_constraint=keras.constraints.max_norm(alpha_max, axis=0))(instance_pred) is embedded feature maps of multi-instances? thanks! By the way it would more convenient if a demo script can be offer.

Implementation for Pytorch

Hi Justin,
i like to try this for a SED work. i am looking to Implementation this on pytorch. i like to know if there exist any pytorch Implementation .
thanks
yuvaram

Why normalizing the scaled feature map?

I don't fully grasp the need of this normalization that you employ in your code:
softmax = tf.keras.backend.exp(scaled - max_val)

I'm tempted to remove this line from my implementation.
Any ideas on that? Does it help training?

Jordi.

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.