MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _find_all_hints_in_nodes

Function _find_all_hints_in_nodes

tensorflow/lite/python/op_hint.py:723–783  ·  view source on GitHub ↗

Look at the all the input nodes and return a list of LiteFuncCall objs. Args: nodes: A TensorFlow graph_def to look for LiteFuncCalls. Returns: a list of `LifeFuncCall` objects in the form

(nodes)

Source from the content-addressed store, hash-verified

721
722
723def _find_all_hints_in_nodes(nodes):
724 """Look at the all the input nodes and return a list of LiteFuncCall objs.
725
726 Args:
727 nodes: A TensorFlow graph_def to look for LiteFuncCalls.
728
729 Returns:
730 a list of `LifeFuncCall` objects in the form
731
732 """
733 func_calls = _collections.defaultdict(_LiteFuncCall)
734
735 for node in nodes:
736 attr = node.attr
737 # This is an op hint if it has a FUNCTION_UUID_ATTR, otherwise skip
738 if (OpHint.FUNCTION_UUID_ATTR not in attr
739 or not attr[OpHint.FUNCTION_UUID_ATTR].s):
740 continue
741 uuid = attr[OpHint.FUNCTION_UUID_ATTR].s
742
743 # Start building function
744 call_def = func_calls[uuid]
745 call_def.uuid = uuid
746 call_def.function_name = attr[OpHint.FUNCTION_NAME_ATTR].s
747 call_def.level = attr[OpHint.FUNCTION_LEVEL_ATTR].i
748 # Get sorting and aggregation information
749
750 sort = (attr[OpHint.FUNCTION_SORT_INDEX_ATTR].i
751 if OpHint.FUNCTION_SORT_INDEX_ATTR in attr else None)
752 if sort == -1: sort = None
753 aggregation = None
754 if OpHint.FUNCTION_AGGREGATE_ATTR in attr:
755 aggregation = _compat.as_text(attr[OpHint.FUNCTION_AGGREGATE_ATTR].s)
756
757 if OpHint.CHILDREN_INPUTS_MAPPINGS in attr:
758 call_def.children_inputs_mappings = _json.loads(
759 _compat.as_text(attr[OpHint.CHILDREN_INPUTS_MAPPINGS].s))
760
761 # Add the input or output
762 def put_operand(stuff, index, sort, operand, aggregation):
763 """Add a given index into the function structure."""
764 if sort is None:
765 stuff[index] = _LiteSingleOperand(operand)
766 else:
767 if index not in stuff:
768 stuff[index] = _LiteAggregateOperand(aggregation)
769 stuff[index].add(sort, operand)
770
771 if OpHint.FUNCTION_INPUT_INDEX_ATTR in attr:
772 put_operand(call_def.inputs, attr[OpHint.FUNCTION_INPUT_INDEX_ATTR].i,
773 sort, node, aggregation)
774 if OpHint.FUNCTION_OUTPUT_INDEX_ATTR in attr:
775 put_operand(call_def.outputs, attr[OpHint.FUNCTION_OUTPUT_INDEX_ATTR].i,
776 sort, node, aggregation)
777
778 # Remember attributes
779 for a in attr:
780 if a.startswith("_tflite_attr_"):

Calls 2

put_operandFunction · 0.85
replaceMethod · 0.80

Tested by

no test coverage detected