Exemple #1
0
 def _resolve_score_threshold(cls, nms_ops_map, nms_scope, graph_helper):
     score_threshold_op_name = '{}/map/while/MultiClassNonMaxSuppression/FilterGreaterThan/Greater/y' \
         .format(nms_scope)
     score_threshold_op = nms_ops_map.get(score_threshold_op_name, None)
     if score_threshold_op is None:
         raise ConverterError(get_message('ERROR_TF_SSD_NMS_CAN_NOT_RESOLVE_SCORE_THRESHOLD'))
     score_threshold = float(graph_helper.evaluate_tensor_output(score_threshold_op.outputs[0]))
     return score_threshold
Exemple #2
0
 def _resolve_iou_threshold(cls, nms_ops_map, nms_scope, graph_helper):
     nms_op_name = '{}/map/while/MultiClassNonMaxSuppression/non_max_suppression/NonMaxSuppressionV2' \
         .format(nms_scope)
     nms_op = nms_ops_map.get(nms_op_name, None)
     if nms_op is None:
         raise ConverterError(get_message('ERROR_TF_SSD_NMS_CAN_NOT_RESOLVE_IOU'))
     _, _, _, iou_tensor = graph_helper.get_op_input_tensors(nms_op, ('?', '?', '?', 'Const'))
     iou_threshold = float(graph_helper.evaluate_tensor_output(iou_tensor))
     return iou_threshold
Exemple #3
0
    def build_layer(self, converter_context, descriptor, input_descriptors, output_descriptors):
        """
        :type input_descriptors: [converters.tensorflow.common.LayerDescriptor]
        :type output_descriptors: [converters.tensorflow.common.LayerDescriptor]
        :type converter_context: converters.tensorflow.converter.ConverterContext
        :type descriptor: ConcatLayerResolver.Descriptor
        :rtype: int
        """
        if len(input_descriptors) != 2:
            raise ConverterError(get_message('ERROR_TF_SSD_NMS_REQUIRES_2_INPUTS'))

        input_names = []
        input_shapes = []
        for i in input_descriptors:
            tensors = converter_context.get_output_tensors_between(i, descriptor)
            if len(tensors) != 1:
                raise ConverterError(get_message('ERROR_TF_SSD_NMS_REQUIRES_SINGLE_INPUT_TENSOR'))

            input_shapes.append(converter_context.graph_helper.get_op_output_shape(tensors[0].op))

        for index, shape in enumerate(input_shapes):
            output_names = input_descriptors[index].output_names
            if len(shape) == 3 and shape[-1] == 4:
                input_names = output_names + input_names
            else:
                input_names.extend(output_names)

        classes_shape = converter_context.graph_helper.get_op_output_shape(descriptor.classes_output_op)

        return converter_context.model.add_multi_class_nms_layer(name=descriptor.layer_name,
                                                                 input_names=input_names,
                                                                 output_names=descriptor.output_names,
                                                                 scoreThreshold=descriptor.score_threshold,
                                                                 iouThreshold=descriptor.iou_threshold,
                                                                 maxDetectionPerClass=classes_shape[-1],
                                                                 maxTotalDetections=classes_shape[-1])
Exemple #4
0
 def build_layer(self, converter_context, descriptor, input_descriptors, output_descriptors):
     """
     :type input_descriptors: [converters.tensorflow.common.LayerDescriptor]
     :type output_descriptors: [converters.tensorflow.common.LayerDescriptor]
     :type converter_context: converters.tensorflow.converter.ConverterContext
     :type descriptor: ConcatLayerResolver.Descriptor
     :rtype: int
     """
     output_name = descriptor.output_names[0]
     anchor_input = [d for d in input_descriptors if isinstance(d, ConstantLayerResolver.Descriptor)]
     boxes_input = [d for d in input_descriptors if not isinstance(d, ConstantLayerResolver.Descriptor)]
     if len(anchor_input) != 1:
         raise ConverterError(get_message('ERROR_TF_SSD_ANCHOR_INPUT_MISSING'))
     anchors_layer_name = anchor_input[0].output_names[0]
     boxes_layer_name = boxes_input[0].output_names[0]
     return converter_context.model.add_box_decoder_layer(output_name,
                                                          [boxes_layer_name, anchors_layer_name],
                                                          [output_name],
                                                          scale_y=descriptor.scale_y,
                                                          scale_x=descriptor.scale_y,
                                                          scale_h=descriptor.scale_h,
                                                          scale_w=descriptor.scale_w)