Spaces:
Sleeping
Sleeping
fix quantile
Browse files
app.py
CHANGED
@@ -3269,9 +3269,13 @@ with demo:
|
|
3269 |
|
3270 |
def to_mask(heatmap, threshold):
|
3271 |
heatmap = 1 / (heatmap + 1e-6)
|
3272 |
-
|
3273 |
-
|
|
|
|
|
|
|
3274 |
heatmap = (heatmap - vmin) / (vmax - vmin)
|
|
|
3275 |
mask = heatmap > threshold
|
3276 |
return mask
|
3277 |
|
|
|
3269 |
|
3270 |
def to_mask(heatmap, threshold):
|
3271 |
heatmap = 1 / (heatmap + 1e-6)
|
3272 |
+
if heatmap.shape[0] > 10000:
|
3273 |
+
random_idx = np.random.choice(heatmap.shape[0], 10000, replace=False)
|
3274 |
+
vmin, vmax = heatmap[random_idx].quantile(0.01), heatmap[random_idx].quantile(0.99)
|
3275 |
+
else:
|
3276 |
+
vmin, vmax = heatmap.quantile(0.01), heatmap.quantile(0.99)
|
3277 |
heatmap = (heatmap - vmin) / (vmax - vmin)
|
3278 |
+
heatmap = heatmap.reshape(len(ncut_images), h, w)
|
3279 |
mask = heatmap > threshold
|
3280 |
return mask
|
3281 |
|