jina.executors.encoders¶
-
class
jina.executors.encoders.
BaseEncoder
(*args, **kwargs)[source]¶ Bases:
jina.executors.BaseExecutor
BaseEncoder
encodes chunk into vector representation.The key function is
encode()
.See also
jina.drivers.handlers.encode
-
class
jina.executors.encoders.
BaseNumericEncoder
(*args, **kwargs)[source]¶ Bases:
jina.executors.encoders.BaseEncoder
BaseNumericEncoder encodes data from a ndarray, potentially B x ([T] x D) into a ndarray of B x D
-
class
jina.executors.encoders.
BaseImageEncoder
(*args, **kwargs)[source]¶ Bases:
jina.executors.encoders.BaseNumericEncoder
BaseImageEncoder encodes data from a ndarray, potentially B x (Height x Width) into a ndarray of B x D
-
class
jina.executors.encoders.
BaseVideoEncoder
(*args, **kwargs)[source]¶ Bases:
jina.executors.encoders.BaseNumericEncoder
BaseVideoEncoder encodes data from a ndarray, potentially B x (Time x Height x Width) into a ndarray of B x D
-
class
jina.executors.encoders.
BaseAudioEncoder
(*args, **kwargs)[source]¶ Bases:
jina.executors.encoders.BaseNumericEncoder
BaseAudioEncoder encodes data from a ndarray, potentially B x (Time x D) into a ndarray of B x D
-
class
jina.executors.encoders.
BaseTextEncoder
(*args, **kwargs)[source]¶ Bases:
jina.executors.encoders.BaseEncoder
BaseTextEncoder encodes data from an array of string type (data.dtype.kind == ‘U’) of size B into a ndarray of B x D.
-
class
jina.executors.encoders.
PipelineEncoder
(routes=None, resolve_all=True, *args, **kwargs)[source]¶ Bases:
jina.executors.compound.CompoundExecutor
Create a new
CompoundExecutor
object- Parameters
routes (
Optional
[Dict
[str
,Dict
]]) –a map of function routes. The key is the function name, the value is a tuple of two pieces, where the first element is the name of the referred component (
metas.name
) and the second element is the name of the referred function.See also
add_route()
resolve_all (
bool
) – universally add*_all()
to all functions that have the identical name
Example:
We have two dummy executors as follows:
class dummyA(BaseExecutor): def say(self): return 'a' def sayA(self): print('A: im A') class dummyB(BaseExecutor): def say(self): return 'b' def sayB(self): print('B: im B')
and we create a
CompoundExecutor
consisting of these two viada, db = dummyA(), dummyB() ce = CompoundExecutor() ce.components = lambda: [da, db]
Now the new executor
ce
have two new methods, i.ece.sayA()
andce.sayB()
. They point to the originaldummyA.sayA()
anddummyB.sayB()
respectively. One can sayce
has inherited these two methods.The interesting part is
say()
, as this function name is shared betweendummyA
anddummyB
. It requires some resolution. When resolve_all=True, then a new functionsay_all()
is add toce
.ce.say_all
works as if you calldummyA.sayA()
anddummyB.sayB()
in a row. This makes sense in some cases such as training, saving. In other cases, it may require a more sophisticated resolution, where one can useadd_route()
to achieve that. For example,ce.add_route('say', db.name, 'say') assert b.say() == 'b'
Such resolution is what we call routes here, and it can be specified in advance with the arguments
routes
in__init__()
, or using YAML.!CompoundExecutor components: ... with: resolve_all: true routes: say: - dummyB-e3acc910 - say