U 8d@s*ddlmZddlmZGdddZdS))SegmentAnything)SemanticSegmentc@s:eZdZddddZddZddZd d Zd d ZdS) RegionSemanticN)returncCs |dSN) init_modelsselfr :/mnt/home/wangjp/Code/Image2Text/models/region_semantic.py__init__szRegionSemantic.__init__cCst|_t|_dSr)r segment_modelrsemantic_segment_modelrr r r r szRegionSemantic.init_modelscCspt|dddd}|dd}d}tdtd |D]$}||d d t|d d 7}q6t|td|S)a fliter too small objects and objects with low stability score anns: [{'class_name': 'person', 'bbox': [0.0, 0.0, 0.0, 0.0], 'size': [0, 0], 'stability_score': 0.0}, ...] semantic_prompt: "person: [0.0, 0.0, 0.0, 0.0]; ..." cSs|dS)Narear )xr r r z4RegionSemantic.semantic_prompt_gen..T)keyreverseN zd****************************************************************************************************z Step3, Semantic Prompt: class_namez: bboxz; )sortedprintstr)r annsZsorted_annotationsZtop_10_largest_regionsZsemantic_promptregionr r r semantic_prompt_gen s "z"RegionSemantic.semantic_prompt_gencCs$|j|}|j||}||Sr)r Z generate_maskrZsemantic_class_w_maskr)r img_srcrZ anns_w_classr r r region_semantic s zRegionSemantic.region_semanticcCsdS)Nregion_semantic_debugr )r rr r r r!%sz$RegionSemantic.region_semantic_debug)__name__ __module__ __qualname__r rrr r!r r r r rs rN)Z,models.segment_models.semgent_anything_modelrZ5models.segment_models.semantic_segment_anything_modelrrr r r r s