o
    oi                     @   sh   d dl Z d dlmZ d dlZd dlmZ d dlmZmZ d dl	m
Z
 d dlmZ dgZG dd dZdS )	    N)Optional)DETRPostProcessor)RTDETRRTDETRConfig)ObjectDetector)ResizePreProcessorRTDETRDetectorBuilderc                   @   s\   e Zd ZdZe						ddee dee dedee	 dee
 d	ee d
efddZdS )r   a  A builder class for constructing RT-DETR object detection models.

    This class provides static methods to:
        - Build an object detection model from a model name or configuration.
        - Export the model to ONNX format for inference.

    .. code-block:: python

        images = kornia.utils.sample.get_sample_images()
        model = RTDETRDetectorBuilder.build()
        model.save(images)
    NT
model_nameconfig
pretrained
image_sizeconfidence_thresholdconfidence_filteringreturnc              	   C   s   | dur|durt d|durt|}|p|j}n0| dur9|r-t| }t| j}nt| }t| j}ntjddd td}tdj}|du rX|durV|j	nd}t
|t||t||pgtj  |jj|jjdS )	a  Build and returns an RT-DETR object detector model.

        Either `model_name` or `config` must be provided. If neither is provided,
        a default pretrained model (`rtdetr_r18vd`) will be built.

        Args:
            model_name:
                Name of the RT-DETR model to load. Can be one of the available pretrained models.
                Including 'rtdetr_r18vd', 'rtdetr_r34vd', 'rtdetr_r50vd_m', 'rtdetr_r50vd', 'rtdetr_r101vd'.
            config:
                A custom configuration object for building the RT-DETR model.
            pretrained:
                Whether to load a pretrained version of the model (applies when `model_name` is provided).
            image_size:
                The size to which input images will be resized during preprocessing.
                If None, no resizing will be inferred from config file. Recommended scales include
                [480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800].
            confidence_threshold: Threshold to filter results based on confidence scores.
            confidence_filtering: Whether to filter results based on confidence scores.


        Returns:
            ObjectDetector
                An object detector instance initialized with the specified model, preprocessor, and post-processor.

        Nz1Either `model_name` or `config` should be `None`.zHNo `model_name` or `config` found. Will build pretrained `rtdetr_r18vd`.   )
stacklevelrtdetr_r18vdg333333?)r   r   num_classesnum_top_queries)
ValueErrorr   from_config
input_sizefrom_pretrainedr   	from_namewarningswarnr   r   r   r   torchonnxis_in_onnx_exportdecoderr   num_queries)r	   r
   r   r   r   r   model r"   R/home/ubuntu/.local/lib/python3.10/site-packages/kornia/models/detection/rtdetr.pybuild-   s4   #



zRTDETRDetectorBuilder.build)NNTNNN)__name__
__module____qualname____doc__staticmethodr   strr   boolintfloatr   r$   r"   r"   r"   r#   r      s0    )r   typingr   r   kornia.contrib.models.rt_detrr   #kornia.contrib.models.rt_detr.modelr   r   kornia.models.detection.baser   kornia.models.utilsr   __all__r   r"   r"   r"   r#   <module>   s   