Internal Helpers Submodule
This module contains helper functions and classes which are used internally in the package or can be useful when debugging or implementing custom functionality.
For debugging, print_tensor_op() and print_tensor_size_op() can be used to print tensors
from within the DALI pipeline.
The other functionality is used internally, and may be useful when implementing custom processing steps.
- accvlab.dali_pipeline_framework.internal_helpers.check_type(input, expected_type_np, identifier)[source]
Python operator for checking the type of the input.
If the type of the input does not match the expected type, a ValueError is raised.
Note
The check is performed at runtime, i.e. not the graph construction time.
Important
Use the output of this function to tie the dependency on the check op, preventing it from being pruned or remain unused. Note that even though
preserve=Trueis set in the operator performing the check, the operator may be not executed if the output is not used, meaning that no check will be performed.- Parameters:
- Returns:
The same input. Use this output to tie the dependency on the check op, preventing it from being not called due to the unused output.
- Raises:
ValueError – If the type of the input does not match the expected type.
- accvlab.dali_pipeline_framework.internal_helpers.print_tensor_op(tensor_list, name)[source]
Python operator for printing a tensor list.
This operator is used to print a tensor list while running the pipeline. Note that simply adding print statements to the pipeline will not work as those will be executed during the DALI graph construction phase, not the actual execution of the pipeline, and therefore, the printed objects will be
DataNode(i.e. “placeholder” objects) instead of the actual data.Note
The input is of type
DataNode, not a tensor list (TensorListCPUorTensorListGPU). This is because this function is called in the DALI pipeline definition, i.e. during the graph construction phase.
- accvlab.dali_pipeline_framework.internal_helpers.print_tensor_size_op(tensor_list, name)[source]
Python operator for printing the size of a tensor list.
This operator is used to print the size of a tensor list while running the pipeline. See
print_tensor_op()for more details on why this operator is needed.Note
The input is of type
DataNode, not a tensor list (TensorListCPUorTensorListGPU). This is because this function is called in the DALI pipeline definition, i.e. during the graph construction phase.
- accvlab.dali_pipeline_framework.internal_helpers.get_mapped(val, mapping, encapsulate=False)[source]
Mapping of original values to numerical values.
Handles nested lists/tuples recursively.
The mapping is a dictionary with the original values (i.e. inputs to be mapped) as keys and the mapped values (i.e. the corresponding output values) as values. The dictionary may have a key
None, which is used as a default value if the input value is not in the mapping. If noNonekey is present, all the values must have a corresponding key in the mapping.
- accvlab.dali_pipeline_framework.internal_helpers.get_as_data_node(value)[source]
Convert a value to a DALI DataNode constant.
Important
The result is always either an 32-bit integer or a 32-bit float (depending on the type of the input value).
- Parameters:
value – The value to convert to a DALI DataNode.
- Returns:
DataNode– The value as a DALI DataNode.
Mini-Parser
This module contains the mini-parser for the DALI pipeline. See Parser for more details on the parser
and AST and its subclasses for more details on the abstract syntax tree which is used as the
output of the parser.
The parser is used internally in the AnnotationConditionEval
processing step.
- class accvlab.dali_pipeline_framework.internal_helpers.mini_parser.Parser(input_str)[source]
Bases:
objectThe actual parser.
The input string must start with a variable name, followed by an assignment operator, followed by an expression.
The expression is parsed recursively. The expression can contain variables, literals, and operators.
- The operators are:
Logical operators:
or,and,notComparison operators:
==,!=,>,>=,<,<=Parentheses:
(and)Unary minus:
-Assignment operator:
=
- The syntax is similar to Python. However, note that
Only the operators defined above are supported.
Comparisons of more than two values are not supported (e.g.
a < b < cis not supported).Only numeric literals are supported.
TrueandFalseare not supported (not needed in the current use case).
Example
- Some valid statements:
res_var = -_b1 < 10.5res_1_var = -_b1 < 10.5 and -c > -20res_3_var = not -_b1 < 10.5res_4_var = (-_b1 < 10.5 or a_bool_var) and another_nool_varres_5_var = (-_b1 < 10.5 or (-c > -20 and d == 10)) and another_var > 30res_7_var = (-_b1 < 10.5 or (-c > -20 and d == 10)) and (another_var > 30 and _e < 40) and f > 50
- Parameters:
input_str (
str) – Input string to parse.
- class accvlab.dali_pipeline_framework.internal_helpers.mini_parser.AST[source]
Bases:
objectBase class for the AST nodes.
- class accvlab.dali_pipeline_framework.internal_helpers.mini_parser.Assignment(variable, expression)[source]
Bases:
ASTRepresents an assignment of a value to a variable.
Note
The constructor parameters are also the attributes of the class.
- class accvlab.dali_pipeline_framework.internal_helpers.mini_parser.Literal(value)[source]
Bases:
ASTRepresents a literal value.
Note
The constructor parameters are also the attributes of the class.
- Parameters:
value (
str) – Value to represent.
- class accvlab.dali_pipeline_framework.internal_helpers.mini_parser.Variable(name)[source]
Bases:
ASTRepresents a variable (by name).
Note
The constructor parameters are also the attributes of the class.
- Parameters:
name (
str) – Name of the variable.
- class accvlab.dali_pipeline_framework.internal_helpers.mini_parser.Comparison(val1, comparison_type, val2)[source]
Bases:
ASTRepresents a comparison.
Note
The constructor parameters are also the attributes of the class.
- class accvlab.dali_pipeline_framework.internal_helpers.mini_parser.Or(*conditions)[source]
Bases:
ASTRepresents a logical
oron a set of operands.Note
The constructor parameters are also the attributes of the class. The individual conditions are stored as a tuple.
- Parameters:
conditions (
AST) – Conditions to be combined withor. Note that the number of conditions is variable, i.e. more than two conditions can be combined.
- class accvlab.dali_pipeline_framework.internal_helpers.mini_parser.And(*conditions)[source]
Bases:
ASTRepresents a logical
andon a set of operands.Note
The constructor parameters are also the attributes of the class. The individual conditions are stored as a tuple.
- Parameters:
conditions (
AST) – Conditions to be combined withand. Note that the number of conditions is variable, i.e. more than two conditions can be combined.
- class accvlab.dali_pipeline_framework.internal_helpers.mini_parser.Not(condition)[source]
Bases:
ASTRepresents a logical
not(i.e. negation) for an operand.Note
The constructor parameters are also the attributes of the class.
- Parameters:
condition (
AST) – Condition to be negated.
- class accvlab.dali_pipeline_framework.internal_helpers.mini_parser.UnaryMinus(value)[source]
Bases:
ASTRepresents a unary minus.
Note
The constructor parameters are also the attributes of the class.
- class accvlab.dali_pipeline_framework.internal_helpers.mini_parser.Lexer(input)[source]
Bases:
objectLexer for the simple parser.
- Parameters:
input (
str) – Input string to generate tokens from.
- class accvlab.dali_pipeline_framework.internal_helpers.mini_parser.TokenType[source]
Bases:
objectRepresents the type of a token
- LITERAL = 'literal'
- VARIABLE = 'variable'
- ASSIGNMENT = 'assignment'
- COMPARISON = 'comparison'
- LOGICAL_OR = 'logical_or'
- LOGICAL_AND = 'logical_and'
- LOGICAL_NOT = 'logical_not'
- MINUS = 'minus'
- PARENTHESIS_OPEN = 'parenthesis_open'
- PARENTHESIS_CLOSE = 'parenthesis_close'
- EOL = 'end_of_line'