modAL-python/modAL

Support data with multiple inputs when querying from ActiveLearner

krille90 opened this issue · 0 comments

I am currently writing a Siamese CNN in tf.keras to compare two images and wanted to use modAL for active learning.
The Siamese CNN takes two images as input, so the data looks like this:

X_pool = [np.array([np.zeros((224,224, 3)), np.zeros((224,224, 3)), np.zeros((224,224, 3))]),
          np.array([np.zeros((224,224, 3)), np.zeros((224,224, 3)), np.zeros((224,224, 3))])]

This works fine for the initial training, however breaks when querying from a pool. I found out that this is due to the function retrieve_rows which expects single input data.

As a workaround I just extended the ActiveLearner:

from modAL.utils.data import modALinput
from typing import Union, Tuple

class MultiActiveLearner(ActiveLearner):
    def query(self, X_pool, *query_args, **query_kwargs) -> Union[Tuple, modALinput]:    
        
        query_result = self.query_strategy(self, X_pool, *query_args, **query_kwargs)
        return query_result

This will only return the query_result indices instead of trying to retrieve the rows.
I admit that this solution isn't very elegant, but just a quick workaround that I can work with.

A proper solution could be to add an axis: int = 0 parameter to the retrieve_rows and query function to give the user more control over what axis is chosen from the data.