Python steppy.base.BaseTransformer() Examples
The following are 5
code examples of steppy.base.BaseTransformer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
steppy.base
, or try the search function
.
Example #1
Source File: utils.py From open-solution-googleai-object-detection with MIT License | 6 votes |
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()
Example #2
Source File: utils.py From open-solution-value-prediction with MIT License | 5 votes |
def make_transformer(func, output_name): class StaticTransformer(BaseTransformer): def transform(self, *args, **kwargs): return {output_name: func(*args, **kwargs)} return StaticTransformer()
Example #3
Source File: utils.py From open-solution-salt-identification with MIT License | 4 votes |
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()
Example #4
Source File: misc.py From open-solution-ship-detection with MIT License | 4 votes |
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()
Example #5
Source File: utils.py From open-solution-googleai-object-detection with MIT License | 4 votes |
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()