
    9i                     T   S SK JrJrJrJr  S SKJr  S SKJr  S SK	J
r
  S SKJrJr  S SKJr  S SKJrJr  S SKJr  S S	KJr  S S
KJr  \" 5       r\R4                  " \R6                  \R8                  S9\R4                  " \R:                  \R8                  S9 " S S\5      5       5       rg)    )AnyDictOptionalUnion)	Pipelines)
OutputKeys)DetectionOutput)InputPipeline)	PIPELINES)	LoadImagePreprocessor)Tasks'show_image_object_detection_auto_result)
get_logger)module_namec                      ^  \ rS rSr SS\S\\   4U 4S jjjrS\S\	\\
4   4U 4S jjrS\	\\
4   S\\	\\
4   \4   4S jrS	\\	\\
4   \4   S\	\\
4   4S
 jrSS jrSrU =r$ )TinynasDetectionPipeline   modelpreprocessorc                 *   > [         TU ]  " SXS.UD6  g)a  Object detection pipeline, currently only for the tinynas-detection model.

Args:
    model: A str format model id or model local dir to build the model instance from.
    preprocessor: A preprocessor instance to preprocess the data, if None,
    the pipeline will try to build the preprocessor according to the configuration.json file.
    kwargs: The args needed by the `Pipeline` class.
)r   r   N )super__init__)selfr   r   kwargs	__class__s       r/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/pipelines/cv/tinynas_detection_pipeline.pyr   !TinynasDetectionPipeline.__init__   s     	JuJ6J    inputreturnc                 N   > [         R                  " U5      n[        TU ]  U5      $ N)r   convert_to_ndarrayr   
preprocess)r   r#   imgr   s      r    r(   #TinynasDetectionPipeline.preprocess(   s#    **51w!#&&r"   c                 *    U R                  US   5      $ )a  The forward method of this pipeline.

Args:
    input: The input data output from the `preprocess` procedure.

Returns:
    A model output, either in a dict format, or in a standard `DetectionOutput` dataclass.
    If outputs a dict, these keys are needed:
        class_ids (`Tensor`, *optional*): class id for each object.
        boxes (`Tensor`, *optional*): Bounding box for each detected object
            in [left, top, right, bottom] format.
        scores (`Tensor`, *optional*): Detection score for each object.
r)   )r   )r   r#   s     r    forward TinynasDetectionPipeline.forward,   s      zz%,''r"   inputsc                     US   US   US   pCnUc4  [         R                  / [         R                  / [         R                  / 0nU$ [         R                  U[         R                  U[         R                  U0nU$ )Nboxesscores	class_ids)r   SCORESLABELSBOXES)r   r.   bboxesr1   labelsoutputss         r    postprocess$TinynasDetectionPipeline.postprocess>   s     "(&2BFE>!!2!!2  "G 	 !!6!!6  &G
 r"   c                     [        XU5        g r&   r   )r   img_pathresult	save_paths       r    show_result$TinynasDetectionPipeline.show_resultQ   s    /)Lr"   r   r&   )__name__
__module____qualname____firstlineno__strr   r   r   r
   r   r   r(   r   r	   r,   r9   r?   __static_attributes____classcell__)r   s   @r    r   r      s     9=KK'5K K' '$sCx. '(c!" #(',T#s(^_-L'M($S#X /!0 159#s(^&M Mr"   r   N)typingr   r   r   r   modelscope.metainfor   modelscope.outputsr   modelscope.outputs.cv_outputsr	   modelscope.pipelines.baser
   r   modelscope.pipelines.builderr   modelscope.preprocessorsr   r   modelscope.utils.constantr   modelscope.utils.cv.image_utilsr   modelscope.utils.loggerr   loggerregister_module domain_specific_object_detectiontinynas_detectionimage_object_detectionr   r   r"   r    <module>rW      s    . - ) ) 9 5 2 < +, .	 	**++- 	  i.I.IK:Mx :MK-
:Mr"   