towhee.functional.mixins.state.StateMixin

class towhee.functional.mixins.state.StateMixin[source]

Bases: object

Mixin for state tracking.

Examples:

>>> from towhee import DataCollection, State
>>> from towhee import param_scope
>>> dc = DataCollection.range(10).set_state(State(a=1))
>>> dc.get_state()
{'a': 1}
>>> dc = dc.map(lambda x: x+1).map(lambda x: x*2)
>>> dc.get_state()
{'a': 1}

Methods

get_state

Get the state storage for DataCollection

set_evaluating

Set evaluating mode for stateful operators

set_state

Set the state storage for DataCollection

set_training

Set training mode for stateful operators

smap

__init__()[source]
get_state()[source]

Get the state storage for DataCollection

Returns:

the state storage

Return type:

State

set_evaluating(state=None)[source]

Set evaluating mode for stateful operators

Parameters:

state (State, optional) – Update the state storage. Defaults to None.

Returns:

data collection itself

Return type:

DataCollection

set_state(state)[source]

Set the state storage for DataCollection

Parameters:

state (State) – state storage

Returns:

data collection itself

Return type:

DataCollection

set_training(state=None)[source]

Set training mode for stateful operators

Parameters:

state (State, optional) – Update the state storage. Defaults to None.

Returns:

data collection itself

Return type:

DataCollection