示例#1
0
    def infer(node: Node):
        assert node.has_valid(
            'dst_type'
        ), 'Destination type of "Cast" operation should be extracted earlier'
        dst_type = node.dst_type
        copy_shape_infer(node)
        if node.has_and_set('stop_value_propagation'):
            return
        if node.in_node(0).has_valid('value'):
            new_blob, finite_match_count, zero_match_count = convert_blob(
                node.in_node(0).value, dst_type)
            node.out_port(0).data.set_value(new_blob)

            if finite_match_count:
                log.error((
                    "{} elements of {} were clipped to infinity while converting an input blob for node '{}' to {}. "
                    + refer_to_faq_msg(76)).format(finite_match_count,
                                                   new_blob.size, node.name,
                                                   dst_type))
            if zero_match_count:
                log.warning((
                    "{} elements of {} were clipped to zero while converting an input blob for node '{}' to {}. "
                    + refer_to_faq_msg(77)).format(zero_match_count,
                                                   new_blob.size, node.name,
                                                   dst_type))
示例#2
0
文件: Cast.py 项目: www096/openvino
    def helper_value_propagation(node_name, value, dst_type):
        new_blob, finite_match_count, zero_match_count = convert_blob(value, dst_type)

        if finite_match_count:
            log.error("{} elements of {} were clipped to infinity while converting an input blob for node '{}' to {}."
                      " ".format(finite_match_count, new_blob.size, node_name, dst_type) + refer_to_faq_msg(76))
        if zero_match_count:
            log.warning("{} elements of {} were clipped to zero while converting an input blob for node '{}' to {}."
                        " ".format(zero_match_count, new_blob.size, node_name, dst_type) + refer_to_faq_msg(77))
        return new_blob
示例#3
0
def add_removed_converts(graph: Graph):
    for data_node_name in graph.get_nodes_with_attributes(Insert_Convert_operation_after=True):
        data_node = Node(graph, data_node_name)
        # Get access to Const node connected to data node
        const_op = data_node.in_node(0)
        assert const_op.data_type == np.float32, "Error when try to insert Convert operation after Const: {}".\
            format(const_op.soft_get('name'))

        convert_op = Cast(graph, {'dst_type': np.float32,
                                  'name': const_op.name + '/restored_convert',
                                  'stop_value_propagation': True}).create_node()

        # Insert Convert operation after Const operation
        consumer_port = const_op.out_port(0).get_connection().get_destination()
        const_op.out_port(0).get_connection().set_destination(convert_op.in_port(0))
        convert_op.out_port(0).connect(consumer_port)

        # Convert Const value to FP32 to make types in graph consistent
        const_op.value, _, _ = convert_blob(const_op.value, np.float16)
        const_op.infer(const_op)