當前位置: 首頁>>代碼示例>>Python>>正文


Python base.BaseTransformer方法代碼示例

本文整理匯總了Python中steppy.base.BaseTransformer方法的典型用法代碼示例。如果您正苦於以下問題:Python base.BaseTransformer方法的具體用法?Python base.BaseTransformer怎麽用?Python base.BaseTransformer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在steppy.base的用法示例。


在下文中一共展示了base.BaseTransformer方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: make_apply_transformer_stream

# 需要導入模塊: from steppy import base [as 別名]
# 或者: from steppy.base import BaseTransformer [as 別名]
def make_apply_transformer_stream(func, output_name='output', apply_on=None):
    class StaticApplyTransformerStream(BaseTransformer):
        def transform(self, *args, **kwargs):
            self.check_input(*args, **kwargs)
            return {output_name: self._transform(*args, **kwargs)}

        def _transform(self, *args, **kwargs):
            if not apply_on:
                iterator = zip(*args, *kwargs.values())
            else:
                iterator = zip(*args, *[kwargs[key] for key in apply_on])

            for func_args in tqdm(iterator):
                yield func(*func_args)

        @staticmethod
        def check_input(*args, **kwargs):
            for arg in chain(args, kwargs.values()):
                if not isinstance(arg, Iterable):
                    raise Exception('All inputs must be iterable')

    return StaticApplyTransformerStream() 
開發者ID:minerva-ml,項目名稱:open-solution-googleai-object-detection,代碼行數:24,代碼來源:utils.py

示例2: make_transformer

# 需要導入模塊: from steppy import base [as 別名]
# 或者: from steppy.base import BaseTransformer [as 別名]
def make_transformer(func, output_name):
    class StaticTransformer(BaseTransformer):
        def transform(self, *args, **kwargs):
            return {output_name: func(*args, **kwargs)}

    return StaticTransformer() 
開發者ID:minerva-ml,項目名稱:open-solution-value-prediction,代碼行數:8,代碼來源:utils.py

示例3: make_apply_transformer

# 需要導入模塊: from steppy import base [as 別名]
# 或者: from steppy.base import BaseTransformer [as 別名]
def make_apply_transformer(func, output_name='output', apply_on=None):
    class StaticApplyTransformer(BaseTransformer):
        def transform(self, *args, **kwargs):
            self.check_input(*args, **kwargs)

            if not apply_on:
                iterator = zip(*args, *kwargs.values())
            else:
                iterator = zip(*args, *[kwargs[key] for key in apply_on])

            output = []
            for func_args in tqdm(iterator, total=self.get_arg_length(*args, **kwargs)):
                output.append(func(*func_args))
            return {output_name: output}

        @staticmethod
        def check_input(*args, **kwargs):
            if len(args) and len(kwargs) == 0:
                raise Exception('Input must not be empty')

            arg_length = None
            for arg in chain(args, kwargs.values()):
                if not isinstance(arg, Iterable):
                    raise Exception('All inputs must be iterable')
                arg_length_loc = None
                try:
                    arg_length_loc = len(arg)
                except:
                    pass
                if arg_length_loc is not None:
                    if arg_length is None:
                        arg_length = arg_length_loc
                    elif arg_length_loc != arg_length:
                        raise Exception('All inputs must be the same length')

        @staticmethod
        def get_arg_length(*args, **kwargs):
            arg_length = None
            for arg in chain(args, kwargs.values()):
                if arg_length is None:
                    try:
                        arg_length = len(arg)
                    except:
                        pass
                if arg_length is not None:
                    return arg_length

    return StaticApplyTransformer() 
開發者ID:neptune-ai,項目名稱:open-solution-salt-identification,代碼行數:50,代碼來源:utils.py

示例4: make_apply_transformer

# 需要導入模塊: from steppy import base [as 別名]
# 或者: from steppy.base import BaseTransformer [as 別名]
def make_apply_transformer(func, output_name='output', apply_on=None, n_threads=1):
    class StaticApplyTransformer(BaseTransformer):
        def transform(self, *args, **kwargs):
            self.check_input(*args, **kwargs)
            if not apply_on:
                iterator = list(zip(*args, *kwargs.values()))
            else:
                iterator = list(zip(*args, *[kwargs[key] for key in apply_on]))

            n_jobs = np.minimum(n_threads, len(iterator))
            with mp.pool.ThreadPool(n_jobs) as executor:
                output = list(tqdm(executor.imap(lambda p: func(*p), iterator), total=len(iterator)))
            return {output_name: output}

        @staticmethod
        def check_input(*args, **kwargs):
            if len(args) and len(kwargs) == 0:
                raise Exception('Input must not be empty')

            arg_length = None
            for arg in chain(args, kwargs.values()):
                if not isinstance(arg, Iterable):
                    raise Exception('All inputs must be iterable')
                arg_length_loc = None
                try:
                    arg_length_loc = len(arg)
                except:
                    pass
                if arg_length_loc is not None:
                    if arg_length is None:
                        arg_length = arg_length_loc
                    elif arg_length_loc != arg_length:
                        raise Exception('All inputs must be the same length')

        @staticmethod
        def get_arg_length(*args, **kwargs):
            arg_length = None
            for arg in chain(args, kwargs.values()):
                if arg_length is None:
                    try:
                        arg_length = len(arg)
                    except:
                        pass
                if arg_length is not None:
                    return arg_length

    return StaticApplyTransformer() 
開發者ID:minerva-ml,項目名稱:open-solution-ship-detection,代碼行數:49,代碼來源:misc.py


注:本文中的steppy.base.BaseTransformer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。