Matthias Bisping 26ef5fce8a Pull request #8: Pipeline refactoring
Merge in RR/image-prediction from pipeline_refactoring to tdd_refactoring

Squashed commit of the following:

commit 6989fcb3313007b7eecf4bba39077fcde6924a9a
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Mon Apr 25 09:49:49 2022 +0200

    removed obsolete module

commit 7428aeee37b11c31cffa597c85b018ba71e79a1d
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Mon Apr 25 09:45:45 2022 +0200

    refactoring

commit 0dcd3894154fdf34bd3ba4ef816362434474f472
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Mon Apr 25 08:57:21 2022 +0200

    refactoring; removed obsolete extractor-classifier

commit 1078aa81144f4219149b3fcacdae8b09c4b905c0
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Fri Apr 22 17:18:10 2022 +0200

    removed obsolete imports

commit 71f61fc5fc915da3941cf5ed5d9cc90fccc49031
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Fri Apr 22 17:16:25 2022 +0200

    comment changed

commit b582726cd1de233edb55c5a76c91e99f9dd3bd13
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Fri Apr 22 17:12:11 2022 +0200

    refactoring

commit 8abc9010048078868b235d6793ac6c8b20abb985
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Apr 21 21:25:47 2022 +0200

    formatting

commit 2c87c419fe3185a25c27139e7fcf79f60971ad24
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Apr 21 21:24:05 2022 +0200

    formatting

commit 50b161192db43a84464125c6d79650225e1010d6
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Apr 21 21:20:18 2022 +0200

    refactoring

commit 9a1446cccfa070852a5d9c0bdbc36037b82541fc
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Apr 21 21:04:57 2022 +0200

    refactoring

commit 6c10b55ff8e61412cb2fe5a5625e660ecaf1d7d1
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Apr 21 19:48:05 2022 +0200

    refactoring

commit 72e785e3e31c132ab352119e9921725f91fac9e2
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Apr 21 19:43:39 2022 +0200

    refactoring

commit f036ee55e6747daf31e3929bdc2d93dc5f2a56ca
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Apr 20 18:30:41 2022 +0200

    refactoring pipeline WIP
2022-04-25 10:08:49 +02:00

36 lines
1.2 KiB
Python

from typing import List, Union, Tuple
import numpy as np
from PIL.Image import Image
from funcy import rcompose
from image_prediction.estimator.adapter.adapter import EstimatorAdapter
from image_prediction.label_mapper.mapper import LabelMapper
from image_prediction.utils import get_logger
logger = get_logger()
class Classifier:
def __init__(self, estimator_adapter: EstimatorAdapter, label_mapper: LabelMapper):
"""Abstraction layer over different estimator backends (e.g. keras or scikit-learn). For each backend to be used
an EstimatorAdapter must be implemented.
Args:
estimator_adapter: adapter for a given estimator backend
"""
self.__estimator_adapter = estimator_adapter
self.__label_mapper = label_mapper
self.__pipe = rcompose(self.__estimator_adapter, self.__label_mapper)
def predict(self, batch: Union[np.array, Tuple[Image]]) -> List[str]:
if isinstance(batch, np.ndarray) and batch.shape[0] == 0:
return []
return self.__pipe(batch)
def __call__(self, batch: np.array) -> List[str]:
logger.debug("Classifier.predict")
return self.predict(batch)