示例#1
0
def insert_do(graph: Graph, replacement_descriptions: dict):
    do_outputs = replacement_descriptions['do_outputs']
    prior_boxes_node = Node(graph, 'ROIFeatureExtractor_2')
    num_classes = 81
    box_regressions_input_node = Node(
        graph, replacement_descriptions['box_regressions_input_node'])
    box_regressions_node = create_op_node_with_second_input(
        graph, Reshape, int64_array([-1, 4 * num_classes]),
        dict(name='box_regressions'), box_regressions_input_node)

    class_predicitons_node = Node(
        graph, replacement_descriptions['class_predicitons_node'])
    im_info_node = Parameter(graph, {
        "name": 'im_info',
        'shape': int64_array([1, 3])
    }).create_node()

    do_node = ExperimentalDetectronDetectionOutput(
        graph, {
            'name':
            'DetectionOutput',
            'class_agnostic_box_regression':
            0,
            'deltas_weights':
            np.array([10.0, 10.0, 5.0, 5.0]),
            'max_delta_log_wh':
            replacement_descriptions['max_delta_log_wh'],
            'nms_threshold':
            replacement_descriptions['nms_threshold'],
            'score_threshold':
            replacement_descriptions['score_threshold'],
            'num_classes':
            num_classes,
            'max_detections_per_image':
            replacement_descriptions['max_detections_per_image'],
            'post_nms_count':
            replacement_descriptions['post_nms_count']
        }).create_node()
    prior_boxes_node.out_port(1).connect(do_node.in_port(0))
    box_regressions_node.out_port(0).connect(do_node.in_port(1))
    class_predicitons_node.out_port(0).connect(do_node.in_port(2))
    im_info_node.out_port(0).connect(do_node.in_port(3))

    do_output_ports = [
        do_node.out_port(0),
        do_node.out_port(1),
        do_node.out_port(2)
    ]
    old_do_output_nodes = [Node(graph, node_id) for node_id in do_outputs]
    for old_node, new_port in zip(old_do_output_nodes, do_output_ports):
        old_node.out_port(0).get_connection().set_source(new_port)
    # the consumer of the second output port of the ExperimentalDetectronDetectionOutput is the Mul node which second
    # input is of type int64 so it is necessary to insert Cast to have data types match
    do_node.out_port(1).get_connection().insert_node(
        Cast(graph, {
            'dst_type': np.int64
        }).create_node())
 def extract(cls, node):
     attrs = dict(class_agnostic_box_regression=onnx_attr(
         node, 'class_agnostic_box_regression', 'i', 0),
                  max_detections_per_image=onnx_attr(
                      node, 'max_detections_per_image', 'i', 100),
                  nms_threshold=onnx_attr(node, 'nms_threshold', 'f', 0.5),
                  num_classes=onnx_attr(node, 'num_classes', 'i', 81),
                  post_nms_count=onnx_attr(node, 'post_nms_count', 'i',
                                           2000),
                  score_threshold=onnx_attr(node, 'score_threshold', 'f',
                                            0.05),
                  max_delta_log_wh=onnx_attr(node, 'max_delta_log_wh', 'f',
                                             log(1000. / 16.)),
                  deltas_weights=np.array(onnx_attr(node, 'deltas_weights',
                                                    'floats',
                                                    [10., 10., 5., 5.]),
                                          dtype=np.float32))
     ExperimentalDetectronDetectionOutput.update_node_stat(node, attrs)
     return cls.enabled
示例#3
0
def insert_do(graph: Graph, replacement_descriptions):
    do_outputs = ['6530', '6532', '6534']
    prior_boxes_node = Node(graph, 'ROIFeatureExtractor_2')
    num_classes = 81
    box_regressions_node = create_op_node_with_second_input(
        graph, Reshape, int64_array([-1, 4 * num_classes]),
        dict(name='box_regressions'), Node(graph, '2773'))

    class_predicitons_node = Node(graph, '2774')
    im_info_node = Parameter(graph, {
        "name": 'im_info',
        'shape': int64_array([1, 3])
    }).create_node()

    do_node = ExperimentalDetectronDetectionOutput(
        graph, {
            'name':
            'DetectionOutput',
            'class_agnostic_box_regression':
            0,
            'deltas_weights':
            np.array([10.0, 10.0, 5.0, 5.0]),
            'max_delta_log_wh':
            replacement_descriptions['max_delta_log_wh'],
            'nms_threshold':
            replacement_descriptions['nms_threshold'],
            'score_threshold':
            replacement_descriptions['score_threshold'],
            'num_classes':
            num_classes,
            'max_detections_per_image':
            replacement_descriptions['max_detections_per_image'],
            'post_nms_count':
            replacement_descriptions['post_nms_count']
        }).create_node()
    prior_boxes_node.out_port(1).connect(do_node.in_port(0))
    box_regressions_node.out_port(0).connect(do_node.in_port(1))
    class_predicitons_node.out_port(0).connect(do_node.in_port(2))
    im_info_node.out_port(0).connect(do_node.in_port(3))

    do_output_ports = [
        do_node.out_port(0),
        do_node.out_port(1),
        do_node.out_port(2)
    ]
    old_do_output_nodes = [Node(graph, node_id) for node_id in do_outputs]
    for old_node, new_port in zip(old_do_output_nodes, do_output_ports):
        old_node.out_port(0).get_connection().set_source(new_port)