o
    *j                     @   s   d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZ d dlmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ e ZejejejdejejejdG dd deZdS )    )AnyDictOptionalUnion)	Pipelines)
OutputKeys)DetectionOutput)InputPipeline)	PIPELINES)	LoadImagePreprocessor)Tasks'show_image_object_detection_auto_result)
get_logger)module_namec                       s   e Zd Z	ddedee f fddZdedeee	f f fdd	Z
deee	f deeee	f ef fd
dZdeeee	f ef deee	f fddZdddZ  ZS )TinynasDetectionPipelineNmodelpreprocessorc                    s   t  jd||d| dS )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__r   s/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/pipelines/cv/tinynas_detection_pipeline.pyr      s   z!TinynasDetectionPipeline.__init__inputreturnc                    s   t |}t |S N)r   Zconvert_to_ndarrayr   
preprocess)r   r   imgr   r   r   r!   (   s   
z#TinynasDetectionPipeline.preprocessc                 C   s   |  |d S )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   r   r   r   forward,   s   z TinynasDetectionPipeline.forwardinputsc                 C   sX   |d |d |d }}}|d u rt jg t jg t jg i}|S t j|t j|t j|i}|S )NZboxesscoresZ	class_ids)r   ZSCORESZLABELSZBOXES)r   r$   Zbboxesr%   labelsZoutputsr   r   r   postprocess>   s   z$TinynasDetectionPipeline.postprocessc                 C   s   t ||| d S r    r   )r   Zimg_pathresultZ	save_pathr   r   r   show_resultQ   s   z$TinynasDetectionPipeline.show_resultr    )__name__
__module____qualname__strr   r   r   r	   r   r   r!   r   r   r#   r'   r)   __classcell__r   r   r   r   r      s.    	


r   N)typingr   r   r   r   Zmodelscope.metainfor   Zmodelscope.outputsr   Zmodelscope.outputs.cv_outputsr   Zmodelscope.pipelines.baser	   r
   Zmodelscope.pipelines.builderr   Zmodelscope.preprocessorsr   r   Zmodelscope.utils.constantr   Zmodelscope.utils.cv.image_utilsr   Zmodelscope.utils.loggerr   loggerZregister_moduleZ domain_specific_object_detectionZtinynas_detectionZimage_object_detectionr   r   r   r   r   <module>   s&   