Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 782 Bytes

custom-transforms.rst

File metadata and controls

30 lines (22 loc) · 782 Bytes

Writing Custom Transforms

Writing a custom transform is simple and straighforward. A transformer must only implement one function, transform. After initialization, transformers should be stateless so they may be used in multiple pipelines, and each pipeline can be executed many times. Keeping transformers stateless also helps with memory consumption, which can become a problem as the size of input grows.

Here is an example transform class implementation:

import hidi


class TimesTwoTransform(object):
    def transform(self, inp, **kwargs):
        # Transform input
        return inp*2, kwargs

pipeline = hidi.pipeline.Pipeline([
    ...,
    TimesTwoTransform(),
    ...
])

pipeline.run()