Search code examples
pythonimage-processingdeep-learningpytorchobject-detection

Is there a way to make a model that creates a mask to drop certain inputs before feeding the masked data to another network?


This might be a question that is kind of dumb but I'm trying to construct a model that is able to filter out inputs before feeding the filtered output to another network.

For example, I have an image that I would to match with a database of about 100 pictures, then I would apply the first network to do some operations that would output the top 10 pictures that is most likely to correctly match. Afterwards, I would apply a second network to rematch those top 10 pictures using a secondary network.

INPUT --> | NETWORK 1 | --> FILTERED OUTPUT --> | NETWORK 2 | --> FINAL OUTPUT

Wondering if there is a way to accomplish this sort of filtration behaviour where that filtered output is fed to the second model like that.


Solution

  • You could maybe take a look at Boolean index arrays with numpy

        >>> import numpy as np
        >>> x = np.array(range(20))
        >>> x
        array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 
        10, 11, 12, 13, 14, 15, 16, 17, 18, 19])
        >>> x[x > 10]
        array([11, 12, 13, 14, 15, 16, 17, 18, 19])
    

    x > 10 returns an array with 20 booleans, so you can maybe try something like this:

        x = pic_arr[network1(pic_arr)]
        network2(x)
      
    

    Where pic_arr is an array with your pictures and network1 returns a list with booleans of which pictures to select.