towhee.dag.operator_repr.OperatorRepr

class towhee.dag.operator_repr.OperatorRepr(name: str, function: str, init_args: Dict[str, Any], inputs: List[Dict[str, Any]], outputs: List[Dict[str, Any]], iter_info: Dict[str, Any], tag: str = 'main', threads: int = 1)[source]

Bases: BaseRepr

This class encapsulates operator representations at compile-time.

Parameters:
  • name (str) – Name of the operator represented by this object.

  • function (str) – The path leads to the operator.

  • init_args (Dict[str, any]) – The args to initilize the operator.

  • inputs (List[Dict[str, Any]]) – Input dataframes(s) to this object.

  • outputs (List[Dict[str, Any]]) – This operator’s output dataframe.

  • iter_info (Dict[str, Any]) – This operator’s iterator info.

Methods

from_dict

Generate a OperatorRepr from a description dict.

from_ir

inject_template

is_valid

Check if the src is a valid YAML file to describe a component in Towhee.

load_file

Load the representation(s) information from a local YAML file.

load_src

Load the information for the representation.

load_str

Load the representation(s) information from a YAML file (pre-loaded as string).

load_url

Load the representation information from a remote YAML file.

render_template

Attributes

function

init_args

Returns: (Dict[str, Any]) The args to initilize the operator.

inputs

Returns: (List[dict]) The inputs of the operator.

iter_info

Returns: (` Dict[str, Any]`) The operator's iterator info.

name

outputs

Returns: (List[dict]) The outputs of the operator.

tag

Returns: (str) The tag to load of the operator.

threads

__init__(name: str, function: str, init_args: Dict[str, Any], inputs: List[Dict[str, Any]], outputs: List[Dict[str, Any]], iter_info: Dict[str, Any], tag: str = 'main', threads: int = 1)[source]
static from_dict(info: Dict[str, Any]) OperatorRepr[source]

Generate a OperatorRepr from a description dict.

Parameters:

info (Dict[str, Any]) – A dict to describe the Operator.

Returns:

(towhee.dag.OperatorRepr)

The OperatorRepe object.

property init_args: Dict[str, Any]

Returns: (Dict[str, Any])

The args to initilize the operator.

property inputs: List[dict]

Returns: (List[dict])

The inputs of the operator.

static is_valid(info: Dict[str, Any], essentials: Set[str]) bool

Check if the src is a valid YAML file to describe a component in Towhee.

Parameters:
  • info (Dict[str, Any]) – The dict loaded from the source file.

  • essentials (Set[str]) – The essential keys that a valid YAML file should contain.

Returns:

(bool)

Return True if the src file is a valid YAML file to describe a component in Towhee, else False.

property iter_info: Dict[str, Any]

Returns: (` Dict[str, Any]`)

The operator’s iterator info.

static load_file(file: str) dict

Load the representation(s) information from a local YAML file.

Parameters:

file (str) – The file path.

Returns:

(dict)

The dict loaded from the YAML file that contains the representation information.

static load_src(file_or_src: str) dict

Load the information for the representation. We support file from local file/HTTP/HDFS.

Parameters:

file_or_src (str) – The source YAML file or the URL points to the source file or a str loaded from source file.

Returns:

(dict)

The YAML file loaded as dict.

static load_str(string: str) dict

Load the representation(s) information from a YAML file (pre-loaded as string).

Parameters:

string (str) – The string pre-loaded from a YAML.

Returns:

(dict)

The dict loaded from the YAML file that contains the representation information.

static load_url(url: str) dict

Load the representation information from a remote YAML file.

Parameters:

url (str) – The url points to the remote YAML file.

Returns:

(dict)

The dict loaded from the YAML file that contains the representation information.

property outputs: List

Returns: (List[dict])

The outputs of the operator.

property tag: str

Returns: (str)

The tag to load of the operator.