o
    *jD
                     @   s   d dl mZmZ d dl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 d dlmZ e Zejejejd	G d
d de
ZdS )    )AnyDictN)	Pipelines)
OutputKeys)InputPipeline)	PIPELINES)Tasks)
get_logger)module_namec                       s   e Zd Zdef fddZdedeeef fddZdeeef deeef fdd	Z	d
eeef deeef fddZ
  ZS )MovieSceneSegmentationPipelinemodelc                    sN   | dd}tj r|dkrd}nd}t jd||d| td dS )zuse `model` to create a movie scene segmentation pipeline for prediction

        Args:
            model: model id on modelscope hub
        deviceZgpucpu)r   r   zLoad model done!N )poptorchcudaZis_availablesuper__init__loggerinfo)selfr   kwargsZ_devicer   	__class__r   z/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/pipelines/cv/movie_scene_segmentation_pipeline.pyr      s   z'MovieSceneSegmentationPipeline.__init__inputreturnc                 C   s   || _ t|tr| j|\| _| _| _| _n	t	dt
| | j| jd}t  | j|}W d   |S 1 s=w   Y  |S )a   use pyscenedetect to detect shot from the input video, and generate key-frame jpg, anno.ndjson, and shot-frame.txt
            Then use shot-encoder to encoder feat of the detected key-frame

        Args:
            input: path of the input video

        z input should be a str,  but got )shot_timecode_lstshot_idx_lstN)input_video_pth
isinstancestrr   
preprocess	shot2keyfannor   r    	TypeErrortyper   Zno_gradZ	inference)r   r   resultoutputr   r   r   r$   $   s"   


z)MovieSceneSegmentationPipeline.preprocessc                 K   s   |S )Nr   )r   r   Zforward_paramsr   r   r   forward>   s   z&MovieSceneSegmentationPipeline.forwardinputsc                 C   sD   | j || jd}| j|\}}}}tj|tj|tj|tj|i}|S )N)r!   Zfeatr%   )	r!   r%   r   postprocessr   ZSHOT_NUMZSHOT_META_LISTZ	SCENE_NUMZSCENE_META_LIST)r   r,   dataZ	scene_numZscene_meta_lstZshot_numZshot_meta_lstr)   r   r   r   r-   B   s   z*MovieSceneSegmentationPipeline.postprocess)__name__
__module____qualname__r#   r   r   r   r   r$   r+   r-   __classcell__r   r   r   r   r      s    

*r   )typingr   r   r   Zmodelscope.metainfor   Zmodelscope.outputsr   Zmodelscope.pipelines.baser   r   Zmodelscope.pipelines.builderr   Zmodelscope.utils.constantr	   Zmodelscope.utils.loggerr
   r   Zregister_moduleZmovie_scene_segmentationr   r   r   r   r   <module>   s   