
    uki5                         d Z ddlmZ ddlmZ ddlmZ ddlZddlmc m	Z
 ddlmZ  G d de
j                  j                        Zed	k(  re
j                  j%                          yy)
aR  Copyright 2019 The MediaPipe Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Tests for media_sequence.py.
    )absolute_import)division)print_functionN)media_sequencec                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)MediaSequenceTestc                    t         j                  j                         }t        j                  d|       t        j
                  d|       t        j                  ddg|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                   d|       t        j"                  d|       t        j$                  d|       t        j&                  d|       t        j(                  d|       t        j*                  d|       t        j,                  d|       t        j.                  d|       t        j0                  d|       t        j2                  d|       t        j4                  d|       t        j6                  d|       t        j8                  d|       t        j:                  d	|       t        j<                  d|       t        j>                  d|       t        j@                  d|       t        jB                  d|       t        jD                  d|       t        jF                  d|       t        jH                  d	|       t        jJ                  d|       t        jL                  d|       t        jN                  d|       t        jP                  d|       t        jR                  d|       t        jT                  d|       t        jV                  d|       t        jX                  d|       t        jZ                  d|       t        j\                  d
|       t        j^                  d|       t        j`                  d|       t        jb                  d|       t        jd                  d|       t        jf                  ddg|       t        jh                  d|       t        jj                  d|       t        jl                  ddg|       t        jn                  d|       t        jp                  d|       t        jr                  d|       t        jt                  d|       t        jv                  d|       t        jx                  d|       t        jz                  d|       t        j|                  d|       t        j~                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  ddg|       t        j                  d|       t        j                  ddg|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  d|       t        j                  ddg|       t        j                  d	dg|       t        j                  d|       t        j                  d|       t        j                  d	|       t        j                  d|       t        j                  d|       t        j                  d|       y )N   strings   overal   test/   )r
   r   )r   1   )Gz?\(\?)r   s   stringsr   )s   HEADs   TOE)g     G@g     A@)r   #   )   texts   stingsr   r   r   s   one)jtftrainSequenceExamplemsset_example_idset_example_dataset_nameset_example_dataset_flag_stringset_clip_media_idset_clip_alternative_media_idset_clip_encoded_media_bytes&set_clip_encoded_media_start_timestampset_clip_data_pathset_clip_start_timestampset_clip_end_timestampset_clip_label_stringset_clip_label_indexset_clip_label_confidenceset_segment_start_timestampset_segment_start_indexset_segment_end_timestampset_segment_end_indexset_segment_label_indexset_segment_label_stringset_segment_label_confidenceset_image_formatset_image_channelsset_image_colorspaceset_image_heightset_image_widthset_image_frame_rateset_image_data_pathset_forward_flow_formatset_forward_flow_channelsset_forward_flow_colorspaceset_forward_flow_heightset_forward_flow_widthset_forward_flow_frame_rateset_class_segmentation_formatset_class_segmentation_heightset_class_segmentation_width)set_class_segmentation_class_label_string(set_class_segmentation_class_label_index set_instance_segmentation_format set_instance_segmentation_heightset_instance_segmentation_width,set_instance_segmentation_object_class_indexset_bbox_partsset_context_feature_floatsset_context_feature_bytesset_context_feature_intsadd_image_encodedadd_image_multi_encodedadd_image_timestampadd_forward_flow_encodedadd_forward_flow_multi_encodedadd_forward_flow_timestampadd_bbox_yminadd_bbox_xminadd_bbox_ymaxadd_bbox_xmaxadd_bbox_point_xadd_bbox_point_yadd_bbox_3d_point_xadd_bbox_3d_point_yadd_bbox_3d_point_zadd_predicted_bbox_yminadd_predicted_bbox_xminadd_predicted_bbox_ymaxadd_predicted_bbox_xmaxadd_bbox_num_regionsadd_bbox_is_annotatedadd_bbox_is_generatedadd_bbox_is_occludedadd_bbox_label_indexadd_bbox_label_stringadd_bbox_label_confidenceadd_bbox_class_indexadd_bbox_class_stringadd_bbox_class_confidenceadd_bbox_track_indexadd_bbox_track_stringadd_bbox_track_confidenceadd_bbox_timestampadd_predicted_bbox_class_indexadd_predicted_bbox_class_stringadd_predicted_bbox_timestampadd_class_segmentation_encoded$add_class_segmentation_multi_encoded!add_instance_segmentation_encoded'add_instance_segmentation_multi_encoded add_class_segmentation_timestamp(set_bbox_embedding_dimensions_per_regionset_bbox_embedding_formatadd_bbox_embedding_floatsadd_bbox_embedding_encodedadd_bbox_embedding_confidenceset_text_languageset_text_context_contentset_text_context_token_idset_text_context_embeddingadd_text_contentadd_text_timestampadd_text_confidenceadd_text_durationadd_text_token_idadd_text_embeddingselfexamples     f/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/mediapipe/util/sequence/media_sequence_test.py#test_expected_functions_are_definedz5MediaSequenceTest.test_expected_functions_are_defined   s    hh&&(Gi)	73&&	7';WEG,$$Y8##Iw7--b':)W-G,b'*17;Hg.  w7""8W5x1  73Xw/x1 5w?##L':)"g&GW-G$r7#D'*7G,w0  W-""7G4r7+b'*""41$$Wg6$$R1##B0001FP//'B''9''G4&&r7333HgF'1!!*g6  !6@'2'*17;2w'1%%w&8'B!!"g.\7+\7+\7+\7+g.g.<1<1<1|W5|W5|W5|W5B(R)Xw/Hg.Hg.2G<  w7Hg.2G<  w7Hg.2G<  w7"g&%%h8&&'<gF##B0%%gw7++Wg,>H((':../A7K''G4//'B  '2  w7!!"6@$$\7;'*1  "b73!!4,8("g&4)W%W%,0    c                 J   t         j                  j                         }t        j                  g dg dg      }t        j                  g       }t        j                  ||       t        j                  ||       | j                  dt        j                  |             | j                  |t        j                  d|             | j                  t        j                  |             t        j                  |       | j                  dt        j                  |             y N皙?皙?333333?皙?)      ?333333?ffffff?g?   r   )r   r   r   nparrayr   add_bboxassertEqualget_bbox_sizeassertAllCloseget_bbox_at
assertTruehas_bbox
clear_bbox)r}   r~   boxesempty_boxess       r   test_bbox_round_tripz&MediaSequenceTest.test_bbox_round_trip   s    hh&&(GHH**, -E((2,KKKwKKW%Q((12r~~a9:OOBKK()MM'Q((12r   c                     t         j                  j                         }t        j                  ddgddgg      }t        j                  ||       t        j                  ||       | j                  dt        j                  |             | j                  |t        j                  d|             | j                  t        j                  |             t        j                  |       | j                  dt        j                  |             y )Nr   r   r   r   r   r   r   r   r   r   r   r   add_bbox_pointr   get_bbox_point_sizer   get_bbox_point_atr   has_bbox_pointclear_bbox_pointr}   r~   pointss      r   test_point_round_tripz'MediaSequenceTest.test_point_round_trip   s    hh&&(GXXSzSz# $Ffg&fg&Q..w78 4 4Q @AOOB%%g./ Q..w78r   c                 .   t         j                  j                         }t        j                  ddgddgg      }t        j                  ||d       t        j                  ||d       | j                  dt        j                  |d             | j                  |t        j                  d|d             | j                  t        j                  |d             t        j                  |d       | j                  dt        j                  |d             y )Nr   r   r   r   testr   r   r   r   s      r   test_prefixed_point_round_tripz0MediaSequenceTest.test_prefixed_point_round_trip   s    hh&&(GXXSzSz# $Ffgv.fgv.Q..w?@ 4 4Q HIOOB%%gv67(Q..w?@r   c                     t         j                  j                         }t        j                  g dg dg      }t        j                  ||       t        j                  ||       | j                  dt        j                  |             | j                  |t        j                  d|             | j                  t        j                  |             t        j                  |       | j                  dt        j                  |             y )Nr   r   r   )r   r   r   r   r   )r   r   r   r   r   r   add_bbox_3d_pointr   get_bbox_3d_point_sizer   get_bbox_3d_point_atr   has_bbox_3d_pointclear_bbox_3d_pointr   s      r   test_3d_point_round_tripz*MediaSequenceTest.test_3d_point_round_trip   s    hh&&(GXX&( )F))Q11':; 7 77 CDOOB((127#Q11':;r   c                     t         j                  j                         }t        j                  g dg dg      }t        j                  ||       t        j                  ||       | j                  dt        j                  |             | j                  |t        j                  d|             | j                  t        j                  |             t        j                  |       | j                  dt        j                  |             y r   )r   r   r   r   r   r   add_predicted_bboxr   get_predicted_bbox_sizer   get_predicted_bbox_atr   has_predicted_bboxclear_predicted_bbox)r}   r~   r   s      r   test_predicted_bbox_round_tripz0MediaSequenceTest.test_predicted_bbox_round_trip   s    hh&&(GHH**, -E%)%)Q227;<r777CDOOB))'23G$Q227;<r   c                    t         j                  j                         }g d}g d}t        j                  ||d       t        j                  ||d       t        j                  ||d       | j                  dt        j                  |d             | j                  dt        j                  |d             | j                  t        j                  |d             | j                  t        j                  |d             | j                  |t        j                  d|d             | j                  |t        j                  d|d             t        j                  |d       | j                  dt        j                  |d             | j                  t        j                  |d             | j                  dt        j                  |d             | j                  t        j                  |d             t        j                  |d       | j                  dt        j                  |d             | j                  t        j                  |d             y )Nr   )r   r   r   12r      r   )r   r   r   r   add_feature_floatsr   get_feature_floats_sizer   has_feature_floatsr   get_feature_floats_atclear_feature_floatsassertFalser}   r~   values_1values_2s       r   test_float_list_round_tripz,MediaSequenceTest.test_float_list_round_trip   s   hh&&(GHH(GS1(GS1(GS1Q227C@AQ227C@AOOB))'378OOB))'378"":":1gs"KL"":":1gs"KLGS)Q227C@AR**7C89Q227C@AOOB))'378GS)Q227C@AR**7C89r   c                    t         j                  j                         }d}d}t        j                  ||d       t        j                  ||d       t        j                  ||d       | j                  dt        j                  |d             | j                  dt        j                  |d             | j                  t        j                  |d             | j                  t        j                  |d             | j                  |t        j                  d|d             | j                  |t        j                  d|d             t        j                  |d       | j                  dt        j                  |d             | j                  t        j                  |d             | j                  dt        j                  |d             | j                  t        j                  |d             t        j                  |d       | j                  dt        j                  |d             | j                  t        j                  |d             y )Nr   r   r   r   r   r   r   )r   r   r   r   add_feature_timestampr   get_feature_timestamp_sizer   has_feature_timestampr   get_feature_timestamp_atclear_feature_timestampr   r   s       r   !test_feature_timestamp_round_tripz3MediaSequenceTest.test_feature_timestamp_round_trip   s   hh&&(GHHXw4Xw4Xw4Q55gsCDQ55gsCDOOB,,Wc:;OOB,,Wc:;33AwDF33AwDFw,Q55gsCDR--gs;<Q55gsCDOOB,,Wc:;w,Q55gsCDR--gs;<r   c                 X   t         j                  j                         }t        j                  ddg|d       t        j                  ddg|d       | j                  ddgt        j                  |d             | j                  ddgt        j                  |d             | j                  t        j                  |d             | j                  t        j                  |d             t        j                  |d       | j                  t        j                  |d             | j                  t        j                  |d             t        j                  |d       | j                  t        j                  |d             | j                  t        j                  |d             y )Nr   r   r   2   r   )r   r   r   r   set_feature_dimensionsassertSequenceEqualget_feature_dimensionsr   has_feature_dimensionsclear_feature_dimensionsr   r|   s     r   "test_feature_dimensions_round_tripz4MediaSequenceTest.test_feature_dimensions_round_trip   sF   hh&&(Gr2h5r2h5b"X66wDFb"X66wDFOOB--gs;<OOB--gs;<-R..w<=OOB--gs;<-R..w<=R..w<=r   c                    t         j                  j                         }d}t        j                  g d      }t        j                  g d      }| j                  t        j                  |             | j                  t        j                  |             | j                  t        j                  |             t        j                  ||       t        j                  ||       t        j                  ||       | j                  |t        j                  |             | j                  |t        j                   |             | j                  |t        j"                  |             | j%                  t        j                  |             | j%                  t        j                  |             | j%                  t        j                  |             t        j&                  |       t        j(                  |       t        j*                  |       | j                  t        j                  |             | j                  t        j                  |             | j                  t        j                  |             y )Ns   text content)r   r         r   )r   r   r   r   r   r   r   has_text_context_embeddinghas_text_context_token_idhas_text_context_contentrs   rt   ru   r   get_text_context_contentr   get_text_context_token_idget_text_context_embeddingr   clear_text_context_contentclear_text_context_token_idclear_text_context_embedding)r}   r~   text_contenttext_token_idstext_embeddingss        r   test_text_context_round_tripz.MediaSequenceTest.test_text_context_round_trip	  s   hh&&(G"LXXl+Nhh34OR227;<R11':;R009:g6  9!!/7;\2#>#>w#GH(D(DW(MN)F)Fw)OPOOB11':;OOB009:OOB//89!!'*""7+##G,R227;<R11':;R009:r   N)__name__
__module____qualname__r   r   r   r   r   r   r   r   r   r    r   r   r   r      s7    n1`3
9
A
<
=:,=0>";r   r   __main__)__doc__
__future__r   r   r   numpyr   tensorflow.compat.v1compatv1r   mediapipe.util.sequencer   r   r   TestCaser   r   mainr   r   r   <module>r      sV   " '  %  ! ! 8D;(( D;L z'',,. r   