
    9i                     4   S SK Jr  S SKrS SKJrJr  S SKrS SK	r	S SK
Jr  S SKJr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Jr  S S
KJr  S SKJr  S SK J!r!  \!" 5       r"\RF                  " \RH                  \RJ                  S9 " S S\5      5       r&g)    N)AnyDict)	Pipelines)ClassifierFreeSampleModelcreate_modelload_model_wo_clip)
OutputKeys)InputPipeline)	PIPELINES)Config)	ModelFileTasks)recover_from_ric)plot_3d_motion)
get_logger)module_namec                      ^  \ rS rSrS\4U 4S jjrS\S\\\4   4S jr	S\\\4   S\\\4   4S jr
S\\\4   S\\\4   4S	 jrS
rU =r$ )MDMMotionGeneration   modelc                   > [         TU ]  " SSU0UD6  [        R                  " U R                  [
        R                  5      n[        R                  SU 35        [        R                  " U R                  [
        R                  5      n[        R                  SU 35        [        R                  " [        R                  " U R                  S5      5      U l        [        R                  " [        R                  " U R                  S5      5      U l        [        R                  " U5      U l        U R                   R#                  S[        R                  " U R                  S5      05        U R                   R#                  U5        SU l        S	U l        S
U l        [+        U R                   5      u  U l        U l        [0        R                  " USSS9n[3        U R,                  U5        [5        U R,                  5      U l        U R,                  R7                  U R8                  5        U R,                  R;                  5         [        R                  S5        g)zn
use `model` to create motion generation pipeline for prediction
Args:
    model: model id on modelscope hub.
r   zloading model from zloading config from zMean.npyzStd.npysmpl_data_pathsmpl      x   cpuT)map_locationweights_onlyzload model doneN )super__init__ospjoinr   r   TORCH_MODEL_FILEloggerinfoCONFIGURATIONnploadmeanstdr   	from_filecfgupdaten_jointsfpsn_framesr   mdm	diffusiontorchr   r   todeviceeval)selfr   kwargs
model_pathconfig_path
state_dict	__class__s         r/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/pipelines/cv/motion_generation_pipeline.pyr#   MDMMotionGeneration.__init__   s    	/u//XXdjj)*D*DE
)*67hhtzz9+B+BC*;-89GGCHHTZZ<=	77388DJJ	:;##K0)388DJJ+GHI#/#9 $.ZZU?
488Z0,TXX6DKK %&    inputreturnc                 l    [        U[        5      (       a  UnO[        S[        U5       35      eSU0nU$ )Nz input should be a str,  but got 
input_text)
isinstancestr	TypeErrortype)r:   rC   rF   results       r@   
preprocessMDMMotionGeneration.preprocess:   sC    eS!!J ))-e7 8 8
+rB   c                    US   /nS[         R                  " SSSU R                  5      S:  [         R                  " U R                  /5      S U[         R                  " SU R                  S9S-  S.0nU R
                  R                  nU" U R                  SU R                  R                  U R                  R                  U R                  4SUSS S	S S SS
9
nUR                  5       R                  SSSS5      U R                  -  U R                  -   R                  5       n[        XPR                   5      nUR"                  " S/UR$                  SS  Q76 R                  SSSS5      nU R                  R'                  US SS	S	SS	S SS SS9nUR                  5       R)                  5       nUS   R+                  SSS5      n[,        R.                  USUS   0nU$ )NrF   y   r   )r8   g      @)masklengthstokenstextscaleFT)clip_denoisedmodel_kwargsskip_timesteps
init_imageprogress
dump_stepsnoiseconst_noise      xyzr   )xrQ   pose_repglobtranslation
jointstype
vertstransbetasbetaglob_rotget_rotations_backrT   )r6   onesr3   tensorr8   r5   p_sample_loopr4   njointsnfeatsr   permuter-   r,   floatr   r1   viewshaperot2xyznumpy	transposer	   	KEYPOINTS)r:   rC   textsrW   	sample_fnsamplemotionouts           r@   forwardMDMMotionGeneration.forwardC   s   |$%

1aDMM:Q> <<8Adkk:S@
 NN00	HH  $((//4==A%
 **,&&q!Q2TXX=II$uw 	!&--8R3&,,qr"23;;Aq!QG!!$ " & ##%$$Q1-##VVU<5HI
rB   inputsc           	      (   UR                  S[        R                  " SS9R                  5      n/ SQ/ SQ/ SQ/ SQ/ SQ/nUb.  [	        UUU[
        R                     UR                  S	5      S
SS9  UR                  [
        R                  U05        U$ )Noutput_videoz.mp4)suffix)r   r^            )r   rP         
   )r   r_      	         )r               )r            r   rT   humanmlr   )datasetr2   )
gettempfileNamedTemporaryFilenamer   r	   rx   popr0   OUTPUT_VIDEO)r:   r   r;   output_video_pathkinematic_chains        r@   postprocessMDMMotionGeneration.postprocessq   s    "JJ''v6;;= ,-=/1D.0 (!z++,

6"! 	z..0ABCrB   )r/   r5   r2   r4   r,   r3   r1   r-   )__name__
__module____qualname____firstlineno__rH   r#   r
   r   r   rL   r~   r   __static_attributes____classcell__)r?   s   @r@   r   r      sv    'c '8 $sCx. ,T#s(^ ,S#X ,\$sCx. tCH~  rB   r   )'os.pathpathr$   r   typingr   r   rv   r*   r6   modelscope.metainfor   &modelscope.models.cv.motion_generationr   r   r   modelscope.outputsr	   modelscope.pipelines.baser
   r   modelscope.pipelines.builderr   modelscope.utils.configr   modelscope.utils.constantr   r   /modelscope.utils.cv.motion_utils.motion_processr   ,modelscope.utils.cv.motion_utils.plot_scriptr   modelscope.utils.loggerr   r'   register_modulemotion_generationmotion_generattionr   r!   rB   r@   <module>r      s         )H H * 5 2 * 6 L G .	 	)E)EGe( eGerB   