MCPcopy Index your code
hub / github.com/CASIA-LMC-Lab/FastSAM / segment_everything

Function segment_everything

app_gradio.py:72–115  ·  view source on GitHub ↗
(
    input,
    input_size=1024, 
    iou_threshold=0.7,
    conf_threshold=0.25,
    better_quality=False,
    withContours=True,
    use_retina=True,
    text="",
    wider=False,
    mask_random_color=True,
)

Source from the content-addressed store, hash-verified

70
71
72def segment_everything(
73 input,
74 input_size=1024,
75 iou_threshold=0.7,
76 conf_threshold=0.25,
77 better_quality=False,
78 withContours=True,
79 use_retina=True,
80 text="",
81 wider=False,
82 mask_random_color=True,
83):
84 input_size = int(input_size) # 确保 imgsz 是整数
85 # Thanks for the suggestion by hysts in HuggingFace.
86 w, h = input.size
87 scale = input_size / max(w, h)
88 new_w = int(w * scale)
89 new_h = int(h * scale)
90 input = input.resize((new_w, new_h))
91
92 results = model(input,
93 device=device,
94 retina_masks=True,
95 iou=iou_threshold,
96 conf=conf_threshold,
97 imgsz=input_size,)
98
99 if len(text) > 0:
100 results = format_results(results[0], 0)
101 annotations, _ = text_prompt(results, text, input, device=device, wider=wider)
102 annotations = np.array([annotations])
103 else:
104 annotations = results[0].masks.data
105
106 fig = fast_process(annotations=annotations,
107 image=input,
108 device=device,
109 scale=(1024 // input_size),
110 better_quality=better_quality,
111 mask_random_color=mask_random_color,
112 bbox=None,
113 use_retina=use_retina,
114 withContours=withContours,)
115 return fig
116
117
118def segment_with_points(

Callers

nothing calls this directly

Calls 3

format_resultsFunction · 0.90
text_promptFunction · 0.90
fast_processFunction · 0.90

Tested by

no test coverage detected